-
Notifications
You must be signed in to change notification settings - Fork 5
/
classicapi_macos_configuration_profiles.go
351 lines (282 loc) · 13.8 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
// 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"
type ResponseMacOSConfigurationProfile struct {
General GeneralConfig `json:"general,omitempty" xml:"general,omitempty"`
Scope ScopeConfig `json:"scope,omitempty" xml:"scope,omitempty"`
SelfService SelfServiceConfig `json:"self_service,omitempty" xml:"self_service,omitempty"`
}
type GeneralConfig struct {
ID int `json:"id,omitempty" xml:"id,omitempty"`
Name string `json:"name,omitempty" xml:"name,omitempty"`
Description string `json:"description,omitempty" xml:"description,omitempty"`
Site SiteInfo `json:"site,omitempty" xml:"site,omitempty"`
Category CategoryInfo `json:"category,omitempty" xml:"category,omitempty"`
DistributionMethod string `json:"distribution_method,omitempty" xml:"distribution_method,omitempty"`
UserRemovable bool `json:"user_removable,omitempty" xml:"user_removable,omitempty"`
Level string `json:"level,omitempty" xml:"level,omitempty"`
UUID string `json:"uuid,omitempty" xml:"uuid,omitempty"`
RedeployOnUpdate string `json:"redeploy_on_update,omitempty" xml:"redeploy_on_update,omitempty"`
Payloads string `json:"payloads,omitempty" xml:"payloads,omitempty"`
}
type SiteInfo struct {
ID int `json:"id,omitempty" xml:"id,omitempty"`
Name string `json:"name,omitempty" xml:"name,omitempty"`
}
type CategoryInfo struct {
ID int `json:"id,omitempty" xml:"id,omitempty"`
Name string `json:"name,omitempty" xml:"name,omitempty"`
}
type ScopeConfig struct {
AllComputers bool `json:"all_computers,omitempty" xml:"all_computers,omitempty"`
AllJSSUsers bool `json:"all_jss_users,omitempty" xml:"all_jss_users,omitempty"`
Computers []ComputerAssignment `json:"computers,omitempty" xml:"computers,omitempty"`
Buildings []BuildingAssignment `json:"buildings,omitempty" xml:"buildings,omitempty"`
Departments []DepartmentAssignment `json:"departments,omitempty" xml:"departments,omitempty"`
ComputerGroups []ComputerGroupInfo `json:"computer_groups,omitempty" xml:"computer_groups,omitempty"`
JSSUsers []JSSUserConfig `json:"jss_users,omitempty" xml:"jss_users,omitempty"`
JSSUserGroups []JSSUserGroupInfo `json:"jss_user_groups,omitempty" xml:"jss_user_groups,omitempty"`
Limitations NetworkLimitation `json:"limitations,omitempty" xml:"limitations,omitempty"`
Exclusions ExclusionConfig `json:"exclusions,omitempty" xml:"exclusions,omitempty"`
}
type ComputerAssignment struct {
Computer ComputerInfo `json:"computer,omitempty" xml:"computer,omitempty"`
}
type ComputerInfo struct {
ID int `json:"id,omitempty" xml:"id,omitempty"`
Name string `json:"name,omitempty" xml:"name,omitempty"`
UDID string `json:"udid,omitempty" xml:"udid,omitempty"`
}
type BuildingAssignment struct {
Building BuildingInfo `json:"building,omitempty" xml:"building,omitempty"`
}
type BuildingInfo struct {
ID int `json:"id,omitempty" xml:"id,omitempty"`
Name string `json:"name,omitempty" xml:"name,omitempty"`
}
type DepartmentAssignment struct {
Department DepartmentInfo `json:"department,omitempty" xml:"department,omitempty"`
}
type DepartmentInfo struct {
ID int `json:"id,omitempty" xml:"id,omitempty"`
Name string `json:"name,omitempty" xml:"name,omitempty"`
}
type ComputerGroupInfo struct {
ComputerGroup GroupAssignmentDataSubsetGroupDetail `json:"computer_group,omitempty" xml:"computer_group,omitempty"`
}
type JSSUserConfig struct {
JSSUser UserInfo `json:"jss_user,omitempty" xml:"jss_user,omitempty"`
}
type UserInfo struct {
ID int `json:"id,omitempty" xml:"id,omitempty"`
Name string `json:"name,omitempty" xml:"name,omitempty"`
}
type JSSUserGroupInfo struct {
JSSUserGroup GroupAssignmentDataSubsetGroupDetail `json:"jss_user_group,omitempty" xml:"jss_user_group,omitempty"`
}
type NetworkLimitation struct {
Users []UserAssignment `json:"users,omitempty" xml:"users,omitempty"`
UserGroups []UserGroupAssignment `json:"user_groups,omitempty" xml:"user_groups,omitempty"`
NetworkSegments []NetworkSegmentInfo `json:"network_segments,omitempty" xml:"network_segments,omitempty"`
IBeacons []IBeaconInfo `json:"ibeacons,omitempty" xml:"ibeacons,omitempty"`
}
type UserAssignment struct {
User UserInfo `json:"user,omitempty" xml:"user,omitempty"`
}
type UserGroupAssignment struct {
UserGroup GroupAssignmentDataSubsetGroupDetail `json:"user_group,omitempty" xml:"user_group,omitempty"`
}
type GroupAssignmentDataSubsetGroupDetail struct {
ID int `json:"id,omitempty" xml:"id"`
Name string `json:"name" xml:"name"`
AccessLevel string `json:"access_level" xml:"access_level"`
PrivilegeSet string `json:"privilege_set" xml:"privilege_set"`
Site AccountDataSubsetSite `json:"site" xml:"site"`
Privileges AccountDataSubsetPrivileges `json:"privileges" xml:"privileges"`
Members []AccountDataSubsetMembers `json:"members" xml:"members>user"`
}
type AccountDataSubsetMembers struct {
ID int `json:"id,omitempty" xml:"id,omitempty"`
Name string `json:"name,omitempty" xml:"name,omitempty"`
}
type NetworkSegmentInfo struct {
NetworkSegment NetworkDetail `json:"network_segment,omitempty" xml:"network_segment,omitempty"`
}
type NetworkDetail struct {
ID int `json:"id,omitempty" xml:"id,omitempty"`
UID string `json:"uid,omitempty" xml:"uid,omitempty"`
Name string `json:"name,omitempty" xml:"name,omitempty"`
}
type IBeaconInfo struct {
IBeacon BeaconDetail `json:"ibeacon,omitempty" xml:"ibeacon,omitempty"`
}
type BeaconDetail struct {
ID int `json:"id,omitempty" xml:"id,omitempty"`
Name string `json:"name,omitempty" xml:"name,omitempty"`
}
type ExclusionConfig struct {
Computers []ComputerAssignment `json:"computers,omitempty" xml:"computers,omitempty"`
Buildings []BuildingAssignment `json:"buildings,omitempty" xml:"buildings,omitempty"`
Departments []DepartmentAssignment `json:"departments,omitempty" xml:"departments,omitempty"`
ComputerGroups []ComputerGroupInfo `json:"computer_groups,omitempty" xml:"computer_groups,omitempty"`
Users []UserAssignment `json:"users,omitempty" xml:"users,omitempty"`
UserGroups []UserGroupAssignment `json:"user_groups,omitempty" xml:"user_groups,omitempty"`
NetworkSegments []NetworkSegmentInfo `json:"network_segments,omitempty" xml:"network_segments,omitempty"`
IBeacons []IBeaconInfo `json:"ibeacons,omitempty" xml:"ibeacons,omitempty"`
JSSUsers []JSSUserConfig `json:"jss_users,omitempty" xml:"jss_users,omitempty"`
JSSUserGroups []JSSUserGroupInfo `json:"jss_user_groups,omitempty" xml:"jss_user_groups,omitempty"`
}
type SelfServiceConfig struct {
InstallButtonText string `json:"install_button_text,omitempty" xml:"install_button_text,omitempty"`
SelfServiceDescription string `json:"self_service_description,omitempty" xml:"self_service_description,omitempty"`
ForceUsersToViewDescription bool `json:"force_users_to_view_description,omitempty" xml:"force_users_to_view_description,omitempty"`
SelfServiceIcon SelfServiceIconDetail `json:"self_service_icon,omitempty" xml:"self_service_icon,omitempty"`
FeatureOnMainPage bool `json:"feature_on_main_page,omitempty" xml:"feature_on_main_page,omitempty"`
SelfServiceCategories SelfServiceCategory `json:"self_service_categories,omitempty" xml:"self_service_categories,omitempty"`
Notification string `json:"notification,omitempty" xml:"notification,omitempty"`
NotificationSubject string `json:"notification_subject,omitempty" xml:"notification_subject,omitempty"`
NotificationMessage string `json:"notification_message,omitempty" xml:"notification_message,omitempty"`
}
type SelfServiceIconDetail struct {
ID int `json:"id,omitempty" xml:"id,omitempty"`
URI string `json:"uri,omitempty" xml:"uri,omitempty"`
Data string `json:"data,omitempty" xml:"data,omitempty"`
}
//--------structs for lists----------//
type ResponseMacOSConfigurationProfileList struct {
Size int `json:"size" xml:"size"`
Results []MacOSConfigurationProfileListItem `json:"os_x_configuration_profile" xml:"os_x_configuration_profile"`
}
type MacOSConfigurationProfileListItem struct {
ID int `json:"id" xml:"id"`
Name string `json:"name" xml:"name"`
}
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
}
func (c *Client) GetMacOSConfigurationProfileByID(id int) (*ResponseMacOSConfigurationProfile, error) {
endpoint := fmt.Sprintf("%s/id/%d", uriMacOSConfigurationProfiles, id)
var profile ResponseMacOSConfigurationProfile
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
}
func (c *Client) GetMacOSConfigurationProfileByName(name string) (*ResponseMacOSConfigurationProfile, error) {
endpoint := fmt.Sprintf("%s/name/%s", uriMacOSConfigurationProfiles, name)
var profile ResponseMacOSConfigurationProfile
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
}
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
}
func (c *Client) CreateMacOSConfigurationProfile(profile *ResponseMacOSConfigurationProfile) (*ResponseMacOSConfigurationProfile, error) {
endpoint := uriMacOSConfigurationProfiles
// Wrap the profile with the desired XML name using an anonymous struct
requestBody := struct {
XMLName xml.Name `xml:"os_x_configuration_profile"`
*ResponseMacOSConfigurationProfile
}{
ResponseMacOSConfigurationProfile: profile,
}
var responseProfile ResponseMacOSConfigurationProfile
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
}
func (c *Client) UpdateMacOSConfigurationProfileByID(id int, profile *ResponseMacOSConfigurationProfile) (*ResponseMacOSConfigurationProfile, 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"`
*ResponseMacOSConfigurationProfile
}{
ResponseMacOSConfigurationProfile: profile,
}
var updatedProfile ResponseMacOSConfigurationProfile
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
}
func (c *Client) UpdateMacOSConfigurationProfileByName(name string, profile *ResponseMacOSConfigurationProfile) (*ResponseMacOSConfigurationProfile, 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"`
*ResponseMacOSConfigurationProfile
}{
ResponseMacOSConfigurationProfile: profile,
}
var updatedProfile ResponseMacOSConfigurationProfile
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
}
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
}
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
}