-
Notifications
You must be signed in to change notification settings - Fork 5
/
classicapi_macos_configuration_profiles.go
392 lines (318 loc) · 16.1 KB
/
classicapi_macos_configuration_profiles.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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
// classicapi_macos_configuration_profiles.go
// Jamf Pro Classic Api - osx configuration profiles
// api reference: https://developer.jamf.com/jamf-pro/reference/osxconfigurationprofiles
// Classic API requires the structs to support an XML data structure.
package jamfpro
import (
"encoding/xml"
"fmt"
)
const uriMacOSConfigurationProfiles = "/JSSResource/osxconfigurationprofiles"
// ResponseMacOSConfigurationProfileList represents the response structure for a list of macOS configuration profiles.
type ResponseMacOSConfigurationProfileList struct {
Size int `xml:"size,omitempty"`
Results []MacOSConfigurationProfileListItem `xml:"os_x_configuration_profile,omitempty"`
}
type MacOSConfigurationProfileListItem struct {
ID int `xml:"id,omitempty"`
Name string `xml:"name" `
}
// ResponseMacOSConfigurationProfiles represents the response structure for a macOS configuration profile.
type ResponseMacOSConfigurationProfiles struct {
General MacOSConfigurationProfilesDataSubsetGeneral `xml:"general,omitempty"`
Scope MacOSConfigurationProfilesDataSubsetScope `xml:"scope,omitempty"`
SelfService MacOSConfigurationProfilesDataSubsetSelfService `xml:"self_service,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetGeneral struct {
ID int `xml:"id,omitempty"`
Name string `xml:"name"`
Description string `xml:"description,omitempty"`
Site MacOSConfigurationProfilesDataSubsetSite `xml:"site,omitempty"`
Category MacOSConfigurationProfilesDataSubsetCategory `xml:"category,omitempty"`
DistributionMethod string `xml:"distribution_method,omitempty"`
UserRemovable bool `xml:"user_removable,omitempty"`
Level string `xml:"level,omitempty"`
UUID string `xml:"uuid,omitempty"`
RedeployOnUpdate string `xml:"redeploy_on_update,omitempty"`
Payloads string `xml:"payloads,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetSite struct {
ID int `xml:"id,omitempty"`
Name string `xml:"name,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetCategory struct {
ID int `xml:"id,omitempty"`
Name string `xml:"name,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetScope struct {
AllComputers bool `xml:"all_computers,omitempty"`
AllJSSUsers bool `xml:"all_jss_users,omitempty"`
Computers []MacOSConfigurationProfilesDataSubsetComputer `xml:"computers,omitempty"`
Buildings []MacOSConfigurationProfilesDataSubsetBuilding `xml:"buildings,omitempty"`
Departments []MacOSConfigurationProfilesDataSubsetDepartment `xml:"departments,omitempty"`
ComputerGroups []MacOSConfigurationProfilesDataSubsetComputerGroup `xml:"computer_groups,omitempty"`
JSSUsers []MacOSConfigurationProfilesDataSubsetJSSUser `xml:"jss_users,omitempty"`
JSSUserGroups []MacOSConfigurationProfilesDataSubsetJSSUserGroup `xml:"jss_user_groups,omitempty"`
Limitations MacOSConfigurationProfilesDataSubsetLimitations `xml:"limitations,omitempty"`
Exclusions MacOSConfigurationProfilesDataSubsetExclusions `xml:"exclusions,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetComputer struct {
Computer MacOSConfigurationProfilesDataSubsetComputerItem `xml:"computer,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetComputerItem struct {
ID int `xml:"id,omitempty"`
Name string `xml:"name,omitempty"`
UDID string `xml:"udid,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetBuilding struct {
Building MacOSConfigurationProfilesDataSubsetBuildingItem `xml:"building,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetBuildingItem struct {
ID int `xml:"id,omitempty"`
Name string `xml:"name,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetDepartment struct {
Department MacOSConfigurationProfilesDataSubsetDepartmentItem `xml:"department,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetDepartmentItem struct {
ID int `xml:"id,omitempty"`
Name string `xml:"name,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetComputerGroup struct {
ComputerGroup MacOSConfigurationProfilesDataSubsetComputerGroupItem `xml:"computer_group,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetComputerGroupItem struct {
ID int `xml:"id,omitempty"`
Name string `xml:"name,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetLimitations struct {
Users []MacOSConfigurationProfilesDataSubsetUser `xml:"users,omitempty"`
UserGroups []MacOSConfigurationProfilesDataSubsetUserGroup `xml:"user_groups,omitempty"`
NetworkSegments []MacOSConfigurationProfilesDataSubsetNetworkSegment `xml:"network_segments,omitempty"`
IBeacons []MacOSConfigurationProfilesDataSubsetIBeacon `xml:"ibeacons,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetUser struct {
User MacOSConfigurationProfilesDataSubsetUserItem `xml:"user,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetUserItem struct {
ID int `xml:"id,omitempty"`
Name string `xml:"name,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetUserGroup struct {
UserGroup MacOSConfigurationProfilesDataSubsetUserGroupItem `xml:"user_group,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetUserGroupItem struct {
ID int `xml:"id,omitempty"`
Name string `xml:"name,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetNetworkSegment struct {
NetworkSegment MacOSConfigurationProfilesDataSubsetNetworkSegmentItem `xml:"network_segment,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetNetworkSegmentItem struct {
ID int `xml:"id,omitempty"`
UID string `xml:"uid,omitempty,omitempty"`
Name string `xml:"name,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetIBeacon struct {
IBeacon MacOSConfigurationProfilesDataSubsetIBeaconItem `xml:"ibeacon,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetIBeaconItem struct {
ID int `xml:"id,omitempty"`
Name string `xml:"name,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetJSSUser struct {
JSSUser MacOSConfigurationProfilesDataSubsetJSSUserItem `xml:"jss_user,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetJSSUserItem struct {
ID int `xml:"id,omitempty"`
Name string `xml:"name,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetJSSUserGroup struct {
JSSUserGroup MacOSConfigurationProfilesDataSubsetJSSUserGroupItem `xml:"jss_user_group,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetJSSUserGroupItem struct {
ID int `xml:"id,omitempty"`
Name string `xml:"name,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetExclusions struct {
Computers []MacOSConfigurationProfilesDataSubsetComputer `xml:"computers,omitempty"`
Buildings []MacOSConfigurationProfilesDataSubsetBuilding `xml:"buildings,omitempty"`
Departments []MacOSConfigurationProfilesDataSubsetDepartment `xml:"departments,omitempty"`
ComputerGroups []MacOSConfigurationProfilesDataSubsetComputerGroup `xml:"computer_groups,omitempty"`
Users []MacOSConfigurationProfilesDataSubsetUser `xml:"users,omitempty"`
UserGroups []MacOSConfigurationProfilesDataSubsetUserGroup `xml:"user_groups,omitempty"`
NetworkSegments []MacOSConfigurationProfilesDataSubsetNetworkSegment `xml:"network_segments,omitempty"`
IBeacons []MacOSConfigurationProfilesDataSubsetIBeacon `xml:"ibeacons,omitempty"`
JSSUsers []MacOSConfigurationProfilesDataSubsetJSSUser `xml:"jss_users,omitempty"`
JSSUserGroups []MacOSConfigurationProfilesDataSubsetJSSUserGroup `xml:"jss_user_groups,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetSelfService struct {
InstallButtonText string `xml:"install_button_text,omitempty"`
SelfServiceDescription string `xml:"self_service_description,omitempty"`
ForceUsersToViewDescription bool `xml:"force_users_to_view_description,omitempty"`
SelfServiceIcon MacOSConfigurationProfilesDataSubsetSelfServiceIcon `xml:"self_service_icon,omitempty"`
FeatureOnMainPage bool `xml:"feature_on_main_page,omitempty"`
SelfServiceCategories MacOSConfigurationProfilesDataSubsetSelfServiceCategories `xml:"self_service_categories,omitempty"`
Notification string `xml:"notification,omitempty"`
NotificationSubject string `xml:"notification_subject,omitempty"`
NotificationMessage string `xml:"notification_message,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetSelfServiceIcon struct {
ID int `xml:"id,omitempty"`
URI string `xml:"uri,omitempty"`
Data string `xml:"data,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetSelfServiceCategories struct {
Category MacOSConfigurationProfilesDataSubsetSelfServiceCategory `xml:"category,omitempty"`
}
type MacOSConfigurationProfilesDataSubsetSelfServiceCategory struct {
ID int `xml:"id,omitempty,omitempty"`
Name string `xml:"name,omitempty,omitempty"`
DisplayIn bool `xml:"display_in,omitempty,omitempty"`
FeatureIn bool `xml:"feature_in,omitempty,omitempty"`
}
// GetMacOSConfigurationProfiles fetches a list of all macOS Configuration Profiles from the Jamf Pro server.
func (c *Client) GetMacOSConfigurationProfiles() (*ResponseMacOSConfigurationProfileList, error) {
endpoint := uriMacOSConfigurationProfiles
var profilesList ResponseMacOSConfigurationProfileList
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &profilesList)
if err != nil {
return nil, fmt.Errorf("failed to fetch all OS X Configuration Profiles: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &profilesList, nil
}
// GetMacOSConfigurationProfileByID fetches a specific macOS Configuration Profile by its ID from the Jamf Pro server.
func (c *Client) GetMacOSConfigurationProfileByID(id int) (*ResponseMacOSConfigurationProfiles, error) {
endpoint := fmt.Sprintf("%s/id/%d", uriMacOSConfigurationProfiles, id)
var profile ResponseMacOSConfigurationProfiles
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &profile)
if err != nil {
return nil, fmt.Errorf("failed to fetch macOS Configuration Profile by ID: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &profile, nil
}
// GetMacOSConfigurationProfileByName fetches a specific macOS Configuration Profile by its name from the Jamf Pro server.
func (c *Client) GetMacOSConfigurationProfileByName(name string) (*ResponseMacOSConfigurationProfiles, error) {
endpoint := fmt.Sprintf("%s/name/%s", uriMacOSConfigurationProfiles, name)
var profile ResponseMacOSConfigurationProfiles
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &profile)
if err != nil {
return nil, fmt.Errorf("failed to fetch macOS Configuration Profile by name: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &profile, nil
}
// GetMacOSConfigurationProfileNameByID retrieves the name of a macOS Configuration Profile by its ID.
func (c *Client) GetMacOSConfigurationProfileNameByID(id int) (string, error) {
profile, err := c.GetMacOSConfigurationProfileByID(id)
if err != nil {
return "", fmt.Errorf("failed to fetch macOS Configuration Profile by ID: %v", err)
}
return profile.General.Name, nil
}
// CreateMacOSConfigurationProfile creates a new macOS Configuration Profile on the Jamf Pro server.
func (c *Client) CreateMacOSConfigurationProfile(profile *ResponseMacOSConfigurationProfiles) (*ResponseMacOSConfigurationProfiles, error) {
endpoint := fmt.Sprintf("%s/id/0", uriMacOSConfigurationProfiles)
// Set default values for site if not included within request
if profile.General.Site.ID == 0 && profile.General.Site.Name == "" {
profile.General.Site = MacOSConfigurationProfilesDataSubsetSite{
ID: -1,
Name: "None",
}
}
// Set default values for category if not included within request
if profile.General.Category.ID == 0 && profile.General.Category.Name == "" {
profile.General.Category = MacOSConfigurationProfilesDataSubsetCategory{
ID: -1,
Name: "No category assigned",
}
}
// Wrap the profile with the desired XML name using an anonymous struct
requestBody := struct {
XMLName xml.Name `xml:"os_x_configuration_profile,omitempty"`
*ResponseMacOSConfigurationProfiles
}{
ResponseMacOSConfigurationProfiles: profile,
}
var responseProfile ResponseMacOSConfigurationProfiles
resp, err := c.HTTP.DoRequest("POST", endpoint, &requestBody, &responseProfile)
if err != nil {
return nil, fmt.Errorf("failed to create macOS Configuration Profile: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &responseProfile, nil
}
// UpdateMacOSConfigurationProfileByID updates an existing macOS Configuration Profile by its ID on the Jamf Pro server.
func (c *Client) UpdateMacOSConfigurationProfileByID(id int, profile *ResponseMacOSConfigurationProfiles) (*ResponseMacOSConfigurationProfiles, error) {
endpoint := fmt.Sprintf("%s/id/%d", uriMacOSConfigurationProfiles, id)
// Wrap the profile with the desired XML name using an anonymous struct
requestBody := struct {
XMLName xml.Name `xml:"os_x_configuration_profile,omitempty"`
*ResponseMacOSConfigurationProfiles
}{
ResponseMacOSConfigurationProfiles: profile,
}
var updatedProfile ResponseMacOSConfigurationProfiles
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &updatedProfile)
if err != nil {
return nil, fmt.Errorf("failed to update macOS Configuration Profile: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &updatedProfile, nil
}
// UpdateMacOSConfigurationProfileByName updates an existing macOS Configuration Profile by its name on the Jamf Pro server.
func (c *Client) UpdateMacOSConfigurationProfileByName(name string, profile *ResponseMacOSConfigurationProfiles) (*ResponseMacOSConfigurationProfiles, error) {
endpoint := fmt.Sprintf("%s/name/%s", uriMacOSConfigurationProfiles, name)
// Wrap the profile with the desired XML name using an anonymous struct
requestBody := struct {
XMLName xml.Name `xml:"os_x_configuration_profile,omitempty"`
*ResponseMacOSConfigurationProfiles
}{
ResponseMacOSConfigurationProfiles: profile,
}
var updatedProfile ResponseMacOSConfigurationProfiles
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &updatedProfile)
if err != nil {
return nil, fmt.Errorf("failed to update macOS Configuration Profile by name: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &updatedProfile, nil
}
// DeleteMacOSConfigurationProfileByID deletes a macOS Configuration Profile by its ID from the Jamf Pro server.
func (c *Client) DeleteMacOSConfigurationProfileByID(id int) error {
endpoint := fmt.Sprintf("%s/id/%d", uriMacOSConfigurationProfiles, id)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf("failed to delete macOS Configuration Profile by ID: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}
// DeleteMacOSConfigurationProfileByName deletes a macOS Configuration Profile by its name from the Jamf Pro server.
func (c *Client) DeleteMacOSConfigurationProfileByName(name string) error {
endpoint := fmt.Sprintf("%s/name/%s", uriMacOSConfigurationProfiles, name)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf("failed to delete macOS Configuration Profile by name: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}