-
Notifications
You must be signed in to change notification settings - Fork 5
/
classicapi_mac_applications.go
376 lines (302 loc) · 11.6 KB
/
classicapi_mac_applications.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
// classicapi_mac_applications.go
// Jamf Pro Classic Api - VPP Mac Applications
// api reference: https://developer.jamf.com/jamf-pro/reference/macapplications
// Classic API requires the structs to support an XML data structure.
package jamfpro
import (
"encoding/xml"
"fmt"
)
const uriVPPMacApplications = "/JSSResource/macapplications"
type ResponseMacApplicationsList struct {
MacApplications []MacApplication `xml:"mac_application"`
}
type MacApplication struct {
ID int `xml:"id"`
Name string `xml:"name"`
}
// ResponseMacApplications represents the detailed structure of a Mac Application response.
type ResponseMacApplications struct {
General MacAppDataSubsetGeneral `xml:"general"`
Scope MacAppDataSubsetScope `xml:"scope"`
SelfService MacAppDataSubsetSelfService `xml:"self_service"`
}
type MacAppDataSubsetGeneral struct {
ID int `xml:"id"`
Name string `xml:"name"`
Version string `xml:"version"`
IsFree bool `xml:"is_free"`
BundleID string `xml:"bundle_id"`
URL string `xml:"url"`
Category MacAppCategory `xml:"category"`
Site MacAppSite `xml:"site"`
}
type MacAppCategory struct {
ID int `xml:"id"`
Name string `xml:"name"`
}
type MacAppSite struct {
ID int `xml:"id"`
Name string `xml:"name"`
}
type MacAppDataSubsetScope struct {
AllComputers bool `xml:"all_computers"`
AllJSSUsers bool `xml:"all_jss_users"`
Buildings []MacAppScopeBuilding `xml:"buildings>building"`
Departments []MacAppScopeDepartment `xml:"departments>department"`
Computers []MacAppScopeComputer `xml:"computers>computer"`
ComputerGroups []MacAppScopeComputerGroup `xml:"computer_groups>computer_group"`
JSSUsers []MacAppScopeUser `xml:"jss_users>user"`
JSSUserGroups []MacAppScopeUserGroup `xml:"jss_user_groups>user_group"`
Limitations MacAppScopeLimitations `xml:"limitations"`
Exclusions MacAppScopeExclusions `xml:"exclusions"`
}
// Define structs for each scope component (Building, Department, Computer, etc.)
type MacAppScopeBuilding struct {
Building MacAppBuilding `xml:"building"`
}
type MacAppBuilding struct {
ID int `xml:"id"`
Name string `xml:"name"`
}
// Struct definitions for Department, Computer, ComputerGroup, User, UserGroup
type MacAppScopeDepartment struct {
Department MacAppDepartment `xml:"department"`
}
type MacAppDepartment struct {
ID int `xml:"id"`
Name string `xml:"name"`
}
type MacAppScopeComputer struct {
Computer MacAppComputer `xml:"computer"`
}
type MacAppComputer struct {
ID int `xml:"id"`
Name string `xml:"name"`
UDID string `xml:"udid"`
}
type MacAppScopeComputerGroup struct {
ComputerGroup MacAppComputerGroup `xml:"computer_group"`
}
type MacAppComputerGroup struct {
ID int `xml:"id"`
Name string `xml:"name"`
}
type MacAppScopeUser struct {
User MacAppUser `xml:"user"`
}
type MacAppUser struct {
ID int `xml:"id"`
Name string `xml:"name"`
}
type MacAppScopeUserGroup struct {
UserGroup MacAppUserGroup `xml:"user_group"`
}
type MacAppUserGroup struct {
ID int `xml:"id"`
Name string `xml:"name"`
}
type MacAppScopeLimitations struct {
Users []MacAppScopeUser `xml:"users>user"`
UserGroups []MacAppScopeUserGroup `xml:"user_groups>user_group"`
NetworkSegments []MacAppScopeNetworkSegment `xml:"network_segments>network_segment"`
}
type MacAppScopeExclusions struct {
Buildings []MacAppScopeBuilding `xml:"buildings>building"`
Departments []MacAppScopeDepartment `xml:"departments>department"`
Users []MacAppScopeUser `xml:"users>user"`
UserGroups []MacAppScopeUserGroup `xml:"user_groups>user_group"`
NetworkSegments []MacAppScopeNetworkSegment `xml:"network_segments>network_segment"`
Computers []MacAppScopeComputer `xml:"computers>computer"`
ComputerGroups []MacAppScopeComputerGroup `xml:"computer_groups>computer_group"`
JSSUsers []MacAppScopeUser `xml:"jss_users>user"`
JSSUserGroups []MacAppScopeUserGroup `xml:"jss_user_groups>user_group"`
}
type MacAppScopeNetworkSegment struct {
ID int `xml:"id"`
UID string `xml:"uid,omitempty"`
Name string `xml:"name"`
}
type MacAppDataSubsetSelfService struct {
InstallButtonText string `xml:"install_button_text"`
SelfServiceDescription string `xml:"self_service_description"`
ForceUsersToViewDescription bool `xml:"force_users_to_view_description"`
SelfServiceIcon MacAppSelfServiceIcon `xml:"self_service_icon"`
FeatureOnMainPage bool `xml:"feature_on_main_page"`
SelfServiceCategories []MacAppSelfServiceCategory `xml:"self_service_categories>category"`
Notification string `xml:"notification"`
NotificationSubject string `xml:"notification_subject"`
NotificationMessage string `xml:"notification_message"`
VPP MacAppVPP `xml:"vpp"`
}
type MacAppSelfServiceIcon struct {
ID int `xml:"id"`
URI string `xml:"uri"`
Data string `xml:"data"`
}
type MacAppSelfServiceCategory struct {
ID int `xml:"id"`
Name string `xml:"name"`
DisplayIn bool `xml:"display_in"`
FeatureIn bool `xml:"feature_in"`
}
type MacAppVPP struct {
AssignVPPDeviceBasedLicenses bool `xml:"assign_vpp_device_based_licenses"`
VPPAdminAccountID int `xml:"vpp_admin_account_id"`
}
// GetDockItems retrieves a serialized list of vpp mac applications.
func (c *Client) GetMacApplications() (*ResponseMacApplicationsList, error) {
endpoint := uriVPPMacApplications
var macApps ResponseMacApplicationsList
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &macApps)
if err != nil {
return nil, fmt.Errorf("failed to fetch Mac Applications: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &macApps, nil
}
// GetMacApplicationByID retrieves a single Mac application by its ID.
func (c *Client) GetMacApplicationByID(id int) (*ResponseMacApplications, error) {
endpoint := fmt.Sprintf("%s/id/%d", uriVPPMacApplications, id)
var macApp ResponseMacApplications
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &macApp)
if err != nil {
return nil, fmt.Errorf("failed to fetch Mac Application by ID: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &macApp, nil
}
// GetMacApplicationByName retrieves a single Mac application by its name.
func (c *Client) GetMacApplicationByName(name string) (*ResponseMacApplications, error) {
endpoint := fmt.Sprintf("%s/name/%s", uriVPPMacApplications, name)
var macApp ResponseMacApplications
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &macApp)
if err != nil {
return nil, fmt.Errorf("failed to fetch Mac Application by Name: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &macApp, nil
}
// GetMacApplicationByNameAndDataSubset retrieves a specific Mac Application by its ID and filters by a specific data subset.
// Subset values can be General, Scope, SelfService, VPPCodes and VPP.
func (c *Client) GetMacApplicationByIDAndDataSubset(id int, subset string) (*ResponseMacApplications, error) {
endpoint := fmt.Sprintf("%s/id/%d/subset/%s", uriVPPMacApplications, id, subset)
var macApp ResponseMacApplications
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &macApp)
if err != nil {
return nil, fmt.Errorf("failed to fetch Mac Application by Name and Subset: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &macApp, nil
}
// GetMacApplicationByNameAndDataSubset retrieves a specific Mac Application by its name and filters by a specific data subset.
// Subset values can be General, Scope, SelfService, VPPCodes and VPP.
func (c *Client) GetMacApplicationByNameAndDataSubset(name, subset string) (*ResponseMacApplications, error) {
endpoint := fmt.Sprintf("%s/name/%s/subset/%s", uriVPPMacApplications, name, subset)
var macApp ResponseMacApplications
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &macApp)
if err != nil {
return nil, fmt.Errorf("failed to fetch Mac Application by Name and Subset: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &macApp, nil
}
// CreateMacApplication creates a new Mac Application.
func (c *Client) CreateMacApplication(macApp ResponseMacApplications) (*ResponseMacApplications, error) {
endpoint := fmt.Sprintf("%s/id/0", uriVPPMacApplications) // '0' typically used for creation in APIs
// Set default values for site if not included within request
if macApp.General.Site.ID == 0 && macApp.General.Site.Name == "" {
macApp.General.Site = MacAppSite{
ID: -1,
Name: "None",
}
}
// The requestBody struct should mirror the ResponseMacApplications struct, including all nested structs
requestBody := struct {
XMLName xml.Name `xml:"mac_application"`
ResponseMacApplications
}{
ResponseMacApplications: macApp,
}
var response ResponseMacApplications
resp, err := c.HTTP.DoRequest("POST", endpoint, &requestBody, &response)
if err != nil {
return nil, fmt.Errorf("failed to create Mac Application: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &response, nil
}
// UpdateMacApplicationByID updates an existing Mac Application by its ID.
func (c *Client) UpdateMacApplicationByID(id int, macApp ResponseMacApplications) (*ResponseMacApplications, error) {
endpoint := fmt.Sprintf("%s/id/%d", uriVPPMacApplications, id)
requestBody := struct {
XMLName xml.Name `xml:"mac_application"`
ResponseMacApplications
}{
ResponseMacApplications: macApp,
}
var response ResponseMacApplications
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &response)
if err != nil {
return nil, fmt.Errorf("failed to update Mac Application by ID: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &response, nil
}
// UpdateMacApplicationByName updates an existing Mac Application by its name.
func (c *Client) UpdateMacApplicationByName(name string, macApp ResponseMacApplications) (*ResponseMacApplications, error) {
endpoint := fmt.Sprintf("%s/name/%s", uriVPPMacApplications, name)
requestBody := struct {
XMLName xml.Name `xml:"mac_application"`
ResponseMacApplications
}{
ResponseMacApplications: macApp,
}
var response ResponseMacApplications
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &response)
if err != nil {
return nil, fmt.Errorf("failed to update Mac Application by Name: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &response, nil
}
// DeleteMacApplicationByID deletes a MacApplication by its ID.
func (c *Client) DeleteMacApplicationByID(id int) error {
endpoint := fmt.Sprintf("%s/id/%d", uriVPPMacApplications, id)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf("failed to delete VPP Mac Application Item by ID: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}
// DeleteMacApplicationByName deletes a MacApplication by its name.
func (c *Client) DeleteMacApplicationByName(name string) error {
endpoint := fmt.Sprintf("%s/name/%s", uriVPPMacApplications, name)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf("failed to delete VPP Mac Application Item by Name: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}