Skip to content

Commit 5791e63

Browse files
authored
fix: mobile device applications - various (#789)
* fix: refactor Jamf Protect functions * fix: mobile device applications - various * Update examples to use bool ptrs * refactor: unify mobile device application structs under a common entity type
1 parent 3840423 commit 5791e63

File tree

6 files changed

+85
-99
lines changed

6 files changed

+85
-99
lines changed

examples/mobile_device_applications/CreateMobileDeviceApplication/CreateMobileDeviceApplication.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func main() {
2525
Description: "Jamf Self Service empowers you to be more productive...",
2626
BundleID: "com.jamfsoftware.selfservice",
2727
Version: "10.10.6",
28-
InternalApp: true,
28+
InternalApp: jamfpro.BoolPtr(true),
2929
OsType: "iOS", // iOS or tvOS
3030
Category: &jamfpro.SharedResourceCategory{
3131
ID: -1,

examples/mobile_device_applications/UpdateMobileDeviceApplicationByApplicationBundleID/UpdateMobileDeviceApplicationByApplicationBundleID.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func main() {
2828
Description: "Jamf Self Service empowers you to be more productive...",
2929
BundleID: "com.jamfsoftware.selfservice",
3030
Version: "10.10.6",
31-
InternalApp: true,
31+
InternalApp: jamfpro.BoolPtr(true),
3232
OsType: "iOS", // iOS or tvOS
3333
Category: &jamfpro.SharedResourceCategory{
3434
ID: -1,

examples/mobile_device_applications/UpdateMobileDeviceApplicationByID/UpdateMobileDeviceApplicationByID.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func main() {
2525
Description: "Jamf Self Service empowers you to be more productive...",
2626
BundleID: "com.jamfsoftware.selfservice",
2727
Version: "10.10.6",
28-
InternalApp: true,
28+
InternalApp: jamfpro.BoolPtr(true),
2929
OsType: "iOS", // iOS or tvOS
3030
Category: &jamfpro.SharedResourceCategory{
3131
ID: -1,

examples/mobile_device_applications/UpdateMobileDeviceApplicationByIDAndAppVersion/UpdateMobileDeviceApplicationByIDAndAppVersion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func main() {
2929
Description: "Jamf Self Service empowers you to be more productive...",
3030
BundleID: "com.jamfsoftware.selfservice",
3131
Version: "10.10.6",
32-
InternalApp: true,
32+
InternalApp: jamfpro.BoolPtr(true),
3333
OsType: "iOS", // iOS or tvOS
3434
Category: &jamfpro.SharedResourceCategory{
3535
ID: -1,

examples/mobile_device_applications/UpdateMobileDeviceApplicationByName/UpdateMobileDeviceApplicationByName.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func main() {
2525
Description: "Jamf Self Service empowers you to be more productive...",
2626
BundleID: "com.jamfsoftware.selfservice",
2727
Version: "10.10.6",
28-
InternalApp: true,
28+
InternalApp: jamfpro.BoolPtr(true),
2929
OsType: "iOS", // iOS or tvOS
3030
Category: &jamfpro.SharedResourceCategory{
3131
ID: -1,

sdk/jamfpro/classicapi_mobile_device_applications.go

Lines changed: 80 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -31,50 +31,51 @@ type MobileDeviceApplicationsListItem struct {
3131
DisplayName string `xml:"display_name"`
3232
BundleID string `xml:"bundle_id"`
3333
Version string `xml:"version"`
34-
InternalApp bool `xml:"internal_app"`
34+
InternalApp *bool `xml:"internal_app"`
3535
}
3636

3737
// Resource
3838

3939
// ResourceMobileDeviceApplication represents the detailed structure of a single mobile device application.
4040
type ResourceMobileDeviceApplication struct {
41-
General MobileDeviceApplicationSubsetGeneral `xml:"general"`
41+
General MobileDeviceApplicationSubsetGeneral `xml:"general"`
42+
Scope MobileDeviceApplicationSubsetScope `xml:"scope"`
43+
SelfService MobileDeviceApplicationSubsetGeneralSelfService `xml:"self_service"`
44+
VPP MobileDeviceApplicationSubsetGeneralVPP `xml:"vpp,omitempty"`
45+
AppConfiguration MobileDeviceApplicationSubsetGeneralAppConfiguration `xml:"app_configuration,omitempty"`
4246
}
4347

4448
// Subsets and Containers
4549

4650
type MobileDeviceApplicationSubsetGeneral struct {
47-
ID int `xml:"id,omitempty"`
48-
Name string `xml:"name"`
49-
DisplayName string `xml:"display_name"`
50-
Description string `xml:"description,omitempty"`
51-
BundleID string `xml:"bundle_id"`
52-
Version string `xml:"version"`
53-
InternalApp bool `xml:"internal_app,omitempty"`
54-
OsType string `xml:"os_type,omitempty"`
55-
Category *SharedResourceCategory `xml:"category"`
56-
IPA MobileDeviceApplicationSubsetGeneralIPA `xml:"ipa,omitempty"`
57-
Icon MobileDeviceApplicationSubsetIcon `xml:"icon"`
58-
ProvisioningProfile int `xml:"mobile_device_provisioning_profile,omitempty"`
59-
ITunesStoreURL string `xml:"itunes_store_url,omitempty"`
60-
MakeAvailableAfterInstall bool `xml:"make_available_after_install,omitempty"`
61-
ITunesCountryRegion string `xml:"itunes_country_region,omitempty"`
62-
ITunesSyncTime int `xml:"itunes_sync_time,omitempty"`
63-
DeploymentType string `xml:"deployment_type,omitempty"`
64-
DeployAutomatically bool `xml:"deploy_automatically,omitempty"`
65-
DeployAsManagedApp bool `xml:"deploy_as_managed_app,omitempty"`
66-
RemoveAppWhenMDMProfileIsRemoved bool `xml:"remove_app_when_mdm_profile_is_removed,omitempty"`
67-
PreventBackupOfAppData bool `xml:"prevent_backup_of_app_data,omitempty"`
68-
KeepDescriptionAndIconUpToDate bool `xml:"keep_description_and_icon_up_to_date,omitempty"`
69-
Free bool `xml:"free,omitempty"`
70-
TakeOverManagement bool `xml:"take_over_management,omitempty"`
71-
HostExternally bool `xml:"host_externally,omitempty"`
72-
ExternalURL string `xml:"external_url,omitempty"`
73-
Site *SharedResourceSite `xml:"site"`
74-
Scope MobileDeviceApplicationSubsetScope `xml:"scope"`
75-
SelfService MobileDeviceApplicationSubsetGeneralSelfService `xml:"self_service"`
76-
VPP MobileDeviceApplicationSubsetGeneralVPP `xml:"vpp,omitempty"`
77-
AppConfiguration MobileDeviceApplicationSubsetGeneralAppConfiguration `xml:"app_configuration,omitempty"`
51+
ID int `xml:"id,omitempty"`
52+
Name string `xml:"name"`
53+
DisplayName string `xml:"display_name"`
54+
Description string `xml:"description,omitempty"`
55+
BundleID string `xml:"bundle_id"`
56+
Version string `xml:"version"`
57+
InternalApp *bool `xml:"internal_app,omitempty"`
58+
OsType string `xml:"os_type,omitempty"`
59+
Category *SharedResourceCategory `xml:"category"`
60+
IPA MobileDeviceApplicationSubsetGeneralIPA `xml:"ipa,omitempty"`
61+
Icon MobileDeviceApplicationSubsetIcon `xml:"icon"`
62+
ProvisioningProfile int `xml:"mobile_device_provisioning_profile,omitempty"`
63+
ITunesStoreURL string `xml:"itunes_store_url,omitempty"`
64+
MakeAvailableAfterInstall bool `xml:"make_available_after_install,omitempty"`
65+
ITunesCountryRegion string `xml:"itunes_country_region,omitempty"`
66+
ITunesSyncTime int `xml:"itunes_sync_time,omitempty"`
67+
DeploymentType string `xml:"deployment_type,omitempty"`
68+
DeployAutomatically *bool `xml:"deploy_automatically,omitempty"`
69+
DeployAsManagedApp *bool `xml:"deploy_as_managed_app,omitempty"`
70+
RemoveAppWhenMDMProfileIsRemoved *bool `xml:"remove_app_when_mdm_profile_is_removed,omitempty"`
71+
PreventBackupOfAppData *bool `xml:"prevent_backup_of_app_data,omitempty"`
72+
KeepDescriptionAndIconUpToDate *bool `xml:"keep_description_and_icon_up_to_date,omitempty"`
73+
KeepAppUpdatedOnDevices *bool `xml:"keep_app_updated_on_devices,omitempty"`
74+
Free *bool `xml:"free,omitempty"`
75+
TakeOverManagement *bool `xml:"take_over_management,omitempty"`
76+
HostExternally *bool `xml:"host_externally,omitempty"`
77+
ExternalURL string `xml:"external_url,omitempty"`
78+
Site *SharedResourceSite `xml:"site"`
7879
}
7980

8081
type MobileDeviceApplicationSubsetGeneralIPA struct {
@@ -86,50 +87,53 @@ type MobileDeviceApplicationSubsetGeneralIPA struct {
8687
type MobileDeviceApplicationSubsetGeneralSelfService struct {
8788
SelfServiceDescription string `xml:"self_service_description,omitempty"`
8889
SelfServiceIcon MobileDeviceApplicationSubsetIcon `xml:"self_service_icon,omitempty"`
89-
FeatureOnMainPage bool `xml:"feature_on_main_page,omitempty"`
90+
FeatureOnMainPage *bool `xml:"feature_on_main_page,omitempty"`
9091
SelfServiceCategories []SharedResourceSelfServiceCategory `xml:"self_service_categories>category,omitempty"`
91-
Notification bool `xml:"notification,omitempty"`
92+
Notification *bool `xml:"notification,omitempty"`
9293
NotificationSubject string `xml:"notification_subject,omitempty"`
9394
NotificationMessage string `xml:"notification_message,omitempty"`
9495
}
9596

9697
type MobileDeviceApplicationSubsetGeneralVPP struct {
97-
AssignVPPDeviceBasedLicenses bool `xml:"assign_vpp_device_based_licenses,omitempty"`
98-
VPPAdminAccountID int `xml:"vpp_admin_account_id,omitempty"`
98+
AssignVPPDeviceBasedLicenses *bool `xml:"assign_vpp_device_based_licenses,omitempty"`
99+
VPPAdminAccountID int `xml:"vpp_admin_account_id,omitempty"`
99100
}
100101

101102
type MobileDeviceApplicationSubsetGeneralAppConfiguration struct {
102-
Preferences string `xml:"preferences,omitempty"`
103+
Preferences string `xml:"preferences"`
103104
}
104105

105106
// Shared Structs
106107

107108
type MobileDeviceApplicationSubsetScope struct {
108-
AllMobileDevices bool `xml:"all_mobile_devices,omitempty"`
109-
AllJSSUsers bool `xml:"all_jss_users,omitempty"`
110-
MobileDevices []MobileDeviceApplicationSubsetMobileDevice `xml:"mobile_devices>mobile_device,omitempty"`
111-
Buildings []MobileDeviceApplicationSubsetBuilding `xml:"buildings>building,omitempty"`
112-
Departments []MobileDeviceApplicationSubsetDepartment `xml:"departments>department,omitempty"`
113-
MobileDeviceGroups []MobileDeviceApplicationSubsetMobileDeviceGroup `xml:"mobile_device_groups>mobile_device_group,omitempty"`
114-
JSSUsers []MobileDeviceApplicationSubsetJSSUser `xml:"jss_users>user,omitempty"`
115-
JSSUserGroups []MobileDeviceApplicationSubsetJSSUserGroup `xml:"jss_user_groups>user_group,omitempty"`
116-
Limitations MobileDeviceApplicationSubsetLimitation `xml:"limitations,omitempty"`
117-
Exclusions MobileDeviceApplicationSubsetExclusion `xml:"exclusions,omitempty"`
109+
AllMobileDevices *bool `xml:"all_mobile_devices,omitempty"`
110+
AllJSSUsers *bool `xml:"all_jss_users,omitempty"`
111+
MobileDevices []MobileDeviceApplicationSubsetMobileDevice `xml:"mobile_devices>mobile_device,omitempty"`
112+
Buildings []MobileDeviceApplicationSubsetScopeEntity `xml:"buildings>building,omitempty"`
113+
Departments []MobileDeviceApplicationSubsetScopeEntity `xml:"departments>department,omitempty"`
114+
MobileDeviceGroups []MobileDeviceApplicationSubsetScopeEntity `xml:"mobile_device_groups>mobile_device_group,omitempty"`
115+
JSSUsers []MobileDeviceApplicationSubsetScopeEntity `xml:"jss_users>user,omitempty"`
116+
JSSUserGroups []MobileDeviceApplicationSubsetScopeEntity `xml:"jss_user_groups>user_group,omitempty"`
117+
Limitations MobileDeviceApplicationSubsetLimitation `xml:"limitations,omitempty"`
118+
Exclusions MobileDeviceApplicationSubsetExclusion `xml:"exclusions,omitempty"`
118119
}
119120

120121
type MobileDeviceApplicationSubsetLimitation struct {
121-
Users []MobileDeviceApplicationSubsetUser `xml:"users>user,omitempty"`
122-
UserGroups []MobileDeviceApplicationSubsetUserGroup `xml:"user_groups>user_group,omitempty"`
122+
Users []MobileDeviceApplicationSubsetScopeEntity `xml:"users>user,omitempty"`
123+
UserGroups []MobileDeviceApplicationSubsetScopeEntity `xml:"user_groups>user_group,omitempty"`
123124
NetworkSegments []MobileDeviceApplicationSubsetNetworkSegment `xml:"network_segments>network_segment,omitempty"`
124125
}
125126

126127
type MobileDeviceApplicationSubsetExclusion struct {
127-
MobileDevices []MobileDeviceApplicationSubsetMobileDevice `xml:"mobile_devices>mobile_device,omitempty"`
128-
Buildings []MobileDeviceApplicationSubsetBuilding `xml:"buildings>building,omitempty"`
129-
Departments []MobileDeviceApplicationSubsetDepartment `xml:"departments>department,omitempty"`
130-
MobileDeviceGroups []MobileDeviceApplicationSubsetMobileDeviceGroup `xml:"mobile_device_groups>mobile_device_group,omitempty"`
131-
JSSUsers []MobileDeviceApplicationSubsetJSSUser `xml:"jss_users>user,omitempty"`
132-
JSSUserGroups []MobileDeviceApplicationSubsetJSSUserGroup `xml:"jss_user_groups>user_group,omitempty"`
128+
MobileDevices []MobileDeviceApplicationSubsetMobileDevice `xml:"mobile_devices>mobile_device,omitempty"`
129+
Buildings []MobileDeviceApplicationSubsetScopeEntity `xml:"buildings>building,omitempty"`
130+
Users []MobileDeviceApplicationSubsetScopeEntity `xml:"users>user,omitempty"`
131+
UserGroups []MobileDeviceApplicationSubsetScopeEntity `xml:"user_groups>user_group,omitempty"`
132+
Departments []MobileDeviceApplicationSubsetScopeEntity `xml:"departments>department,omitempty"`
133+
MobileDeviceGroups []MobileDeviceApplicationSubsetScopeEntity `xml:"mobile_device_groups>mobile_device_group,omitempty"`
134+
NetworkSegments []MobileDeviceApplicationSubsetNetworkSegment `xml:"network_segments>network_segment,omitempty"`
135+
JSSUsers []MobileDeviceApplicationSubsetScopeEntity `xml:"jss_users>user,omitempty"`
136+
JSSUserGroups []MobileDeviceApplicationSubsetScopeEntity `xml:"jss_user_groups>user_group,omitempty"`
133137
}
134138

135139
type MobileDeviceApplicationSubsetIcon struct {
@@ -140,50 +144,22 @@ type MobileDeviceApplicationSubsetIcon struct {
140144
}
141145

142146
type MobileDeviceApplicationSubsetMobileDevice struct {
143-
ID int `xml:"id,omitempty"`
147+
ID int `xml:"id"`
144148
Name string `xml:"name,omitempty"`
145149
UDID string `xml:"udid,omitempty"`
146150
WifiMacAddress string `xml:"wifi_mac_address,omitempty"`
147151
}
148152

149-
type MobileDeviceApplicationSubsetBuilding struct {
150-
ID int `xml:"id,omitempty"`
151-
Name string `xml:"name,omitempty"`
152-
}
153-
154-
type MobileDeviceApplicationSubsetDepartment struct {
155-
ID int `xml:"id,omitempty"`
156-
Name string `xml:"name,omitempty"`
157-
}
158-
159-
type MobileDeviceApplicationSubsetMobileDeviceGroup struct {
160-
ID int `xml:"id,omitempty"`
161-
Name string `xml:"name,omitempty"`
162-
}
163-
164-
type MobileDeviceApplicationSubsetJSSUser struct {
165-
ID int `xml:"id,omitempty"`
166-
Name string `xml:"name,omitempty"`
167-
}
153+
// Entity
168154

169-
type MobileDeviceApplicationSubsetJSSUserGroup struct {
170-
ID int `xml:"id,omitempty"`
171-
Name string `xml:"name,omitempty"`
172-
}
173-
174-
type MobileDeviceApplicationSubsetUser struct {
175-
ID int `xml:"id,omitempty"`
176-
Name string `xml:"name,omitempty"`
177-
}
178-
179-
type MobileDeviceApplicationSubsetUserGroup struct {
180-
ID int `xml:"id,omitempty"`
155+
// Generic Entity struct for common use
156+
type MobileDeviceApplicationSubsetScopeEntity struct {
157+
ID int `xml:"id"`
181158
Name string `xml:"name,omitempty"`
182159
}
183160

184161
type MobileDeviceApplicationSubsetNetworkSegment struct {
185-
ID int `xml:"id,omitempty"`
186-
UID string `xml:"uid,omitempty"`
162+
MobileDeviceApplicationSubsetScopeEntity
187163
Name string `xml:"name,omitempty"`
188164
}
189165

@@ -309,7 +285,7 @@ func (c *Client) GetMobileDeviceApplicationByNameAndDataSubset(name string, subs
309285
}
310286

311287
// CreateMobileDeviceApplication creates a new mobile device application on the Jamf Pro server.
312-
func (c *Client) CreateMobileDeviceApplication(app *ResourceMobileDeviceApplication) (*ResourceMobileDeviceApplication, error) {
288+
func (c *Client) CreateMobileDeviceApplication(app *ResourceMobileDeviceApplication) (*MobileDeviceApplicationsListItem, error) {
313289
endpoint := fmt.Sprintf("%s/id/0", uriMobileDeviceApplications)
314290

315291
requestBody := struct {
@@ -319,8 +295,11 @@ func (c *Client) CreateMobileDeviceApplication(app *ResourceMobileDeviceApplicat
319295
ResourceMobileDeviceApplication: app,
320296
}
321297

322-
var responseApp ResourceMobileDeviceApplication
323-
resp, err := c.HTTP.DoRequest("POST", endpoint, &requestBody, &responseApp)
298+
var createResp struct {
299+
ID int `xml:"id"`
300+
}
301+
302+
resp, err := c.HTTP.DoRequest("POST", endpoint, &requestBody, &createResp)
324303
if err != nil {
325304
return nil, fmt.Errorf(errMsgFailedCreate, "mobile device application", err)
326305
}
@@ -329,7 +308,14 @@ func (c *Client) CreateMobileDeviceApplication(app *ResourceMobileDeviceApplicat
329308
defer resp.Body.Close()
330309
}
331310

332-
return &responseApp, nil
311+
if createResp.ID == 0 {
312+
return nil, fmt.Errorf("no ID found in mobile device application creation response")
313+
}
314+
315+
return &MobileDeviceApplicationsListItem{
316+
ID: createResp.ID,
317+
Name: app.General.Name,
318+
}, nil
333319
}
334320

335321
// UpdateMobileDeviceApplicationByID updates a mobile device application by its ID on the Jamf Pro server.

0 commit comments

Comments
 (0)