-
Notifications
You must be signed in to change notification settings - Fork 5
/
classicapi_mobile_device_enrollment_profiles.go
338 lines (271 loc) · 13 KB
/
classicapi_mobile_device_enrollment_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
// classicapi_mobile_device_enrollment_profiles.go
// Jamf Pro Classic Api - Mobile Device Enrollment Profiles
// API reference: https://developer.jamf.com/jamf-pro/reference/mobiledeviceenrollmentprofiles
// Jamf Pro Classic API requires the structs to support an XML data structure.
package jamfpro
import (
"encoding/xml"
"fmt"
)
const uriMobileDeviceEnrollmentProfiles = "/JSSResource/mobiledeviceenrollmentprofiles"
// ResponseMobileDeviceEnrollmentProfilesList represents the response for a list of mobile device enrollment profiles.
type ResponseMobileDeviceEnrollmentProfilesList struct {
Size int `xml:"size"`
MobileDeviceEnrollmentProfile []MobileDeviceEnrollmentProfileItem `xml:"mobile_device_enrollment_profile"`
}
// MobileDeviceEnrollmentProfileItem represents a single mobile device enrollment profile item.
type MobileDeviceEnrollmentProfileItem struct {
ID int `xml:"id"`
Name string `xml:"name"`
Invitation float64 `xml:"invitation"`
}
// ResponseMobileDeviceEnrollmentProfile represents the response structure for a mobile device enrollment profile.
type ResponseMobileDeviceEnrollmentProfile struct {
General MobileDeviceEnrollmentProfileGeneral `xml:"general"`
Location MobileDeviceEnrollmentProfileLocation `xml:"location,omitempty"`
Purchasing MobileDeviceEnrollmentProfilePurchasing `xml:"purchasing,omitempty"`
Attachments []MobileDeviceEnrollmentProfileAttachment `xml:"attachments,omitempty"`
}
// MobileDeviceEnrollmentProfileGeneral contains general information about the enrollment profile.
type MobileDeviceEnrollmentProfileGeneral struct {
ID int `xml:"id"`
Name string `xml:"name"`
Invitation string `xml:"invitation,omitempty"`
UDID string `xml:"udid,omitempty"`
Description string `xml:"description,omitempty"`
}
// MobileDeviceEnrollmentProfileLocation contains location information of the enrollment profile.
type MobileDeviceEnrollmentProfileLocation struct {
Username string `xml:"username,omitempty"`
Realname string `xml:"realname,omitempty"`
RealName string `xml:"real_name,omitempty"`
EmailAddress string `xml:"email_address,omitempty"`
Position string `xml:"position,omitempty"`
Phone string `xml:"phone,omitempty"`
PhoneNumber string `xml:"phone_number,omitempty"`
Department string `xml:"department,omitempty"`
Building string `xml:"building,omitempty"`
Room int `xml:"room,omitempty"`
}
// MobileDeviceEnrollmentProfilePurchasing contains purchasing information of the enrollment profile.
type MobileDeviceEnrollmentProfilePurchasing struct {
IsPurchased bool `xml:"is_purchased"`
IsLeased bool `xml:"is_leased"`
PONumber string `xml:"po_number,omitempty"`
Vendor string `xml:"vendor,omitempty"`
ApplecareID string `xml:"applecare_id,omitempty"`
PurchasePrice string `xml:"purchase_price,omitempty"`
PurchasingAccount string `xml:"purchasing_account,omitempty"`
PODate string `xml:"po_date,omitempty"`
PODateEpoch int64 `xml:"po_date_epoch,omitempty"`
PODateUTC string `xml:"po_date_utc,omitempty"`
WarrantyExpires string `xml:"warranty_expires,omitempty"`
WarrantyExpiresEpoch int64 `xml:"warranty_expires_epoch,omitempty"`
WarrantyExpiresUTC string `xml:"warranty_expires_utc,omitempty"`
LeaseExpires string `xml:"lease_expires,omitempty"`
LeaseExpiresEpoch int64 `xml:"lease_expires_epoch,omitempty"`
LeaseExpiresUTC string `xml:"lease_expires_utc,omitempty"`
LifeExpectancy int `xml:"life_expectancy,omitempty"`
PurchasingContact string `xml:"purchasing_contact,omitempty"`
}
// MobileDeviceEnrollmentProfileAttachment represents an attachment in the enrollment profile.
type MobileDeviceEnrollmentProfileAttachment struct {
Attachment MobileDeviceEnrollmentProfileAttachmentItem `xml:"attachment"`
}
// MobileDeviceEnrollmentProfileAttachmentItem contains details of an attachment.
type MobileDeviceEnrollmentProfileAttachmentItem struct {
ID int `xml:"id"`
Filename string `xml:"filename"`
URI string `xml:"uri"`
}
// GetMobileDeviceEnrollmentProfiles retrieves a serialized list of mobile device enrollment profiles.
func (c *Client) GetMobileDeviceEnrollmentProfiles() (*ResponseMobileDeviceEnrollmentProfilesList, error) {
endpoint := uriMobileDeviceEnrollmentProfiles
var enrollmentProfiles ResponseMobileDeviceEnrollmentProfilesList
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &enrollmentProfiles)
if err != nil {
return nil, fmt.Errorf("failed to fetch mobile device enrollment profiles: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &enrollmentProfiles, nil
}
// GetMobileDeviceEnrollmentProfileByID fetches a specific mobile device enrollment profile by its ID.
func (c *Client) GetMobileDeviceEnrollmentProfileByID(id int) (*ResponseMobileDeviceEnrollmentProfile, error) {
endpoint := fmt.Sprintf("%s/id/%d", uriMobileDeviceEnrollmentProfiles, id)
var profile ResponseMobileDeviceEnrollmentProfile
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &profile)
if err != nil {
return nil, fmt.Errorf("failed to fetch mobile device enrollment profile by ID: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &profile, nil
}
// GetMobileDeviceEnrollmentProfileByName fetches a specific mobile device enrollment profile by its name.
func (c *Client) GetMobileDeviceEnrollmentProfileByName(name string) (*ResponseMobileDeviceEnrollmentProfile, error) {
endpoint := fmt.Sprintf("%s/name/%s", uriMobileDeviceEnrollmentProfiles, name)
var profile ResponseMobileDeviceEnrollmentProfile
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &profile)
if err != nil {
return nil, fmt.Errorf("failed to fetch mobile device enrollment profile by name: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &profile, nil
}
// GetProfileByInvitation fetches a specific mobile device enrollment profile by its invitation.
func (c *Client) GetProfileByInvitation(invitation string) (*ResponseMobileDeviceEnrollmentProfile, error) {
endpoint := fmt.Sprintf("%s/invitation/%s", uriMobileDeviceEnrollmentProfiles, invitation)
var profile ResponseMobileDeviceEnrollmentProfile
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &profile)
if err != nil {
return nil, fmt.Errorf("failed to fetch mobile device enrollment profile by invitation: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &profile, nil
}
// GetMobileDeviceEnrollmentProfileByIDBySubset fetches a specific mobile device configuration profile by its ID and a specified subset.
func (c *Client) GetMobileDeviceEnrollmentProfileByIDBySubset(id int, subset string) (*ResponseMobileDeviceEnrollmentProfile, error) {
endpoint := fmt.Sprintf("%s/id/%d/subset/%s", uriMobileDeviceEnrollmentProfiles, id, subset)
var profile ResponseMobileDeviceEnrollmentProfile
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &profile)
if err != nil {
return nil, fmt.Errorf("failed to fetch mobile device configuration profile by ID and subset: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &profile, nil
}
// GetMobileDeviceEnrollmentProfileByNameBySubset fetches a specific mobile device configuration profile by its name and a specified subset.
func (c *Client) GetMobileDeviceEnrollmentProfileByNameBySubset(name string, subset string) (*ResponseMobileDeviceEnrollmentProfile, error) {
endpoint := fmt.Sprintf("%s/name/%s/subset/%s", uriMobileDeviceEnrollmentProfiles, name, subset)
var profile ResponseMobileDeviceEnrollmentProfile
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &profile)
if err != nil {
return nil, fmt.Errorf("failed to fetch mobile device configuration profile by name and subset: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &profile, nil
}
// CreateMobileDeviceEnrollmentProfile creates a new mobile device enrollment profile on the Jamf Pro server.
func (c *Client) CreateMobileDeviceEnrollmentProfile(profile *ResponseMobileDeviceEnrollmentProfile) (*ResponseMobileDeviceEnrollmentProfile, error) {
endpoint := fmt.Sprintf("%s/id/0", uriMobileDeviceEnrollmentProfiles)
// Wrap the profile with the desired XML name using an anonymous struct
requestBody := struct {
XMLName xml.Name `xml:"mobile_device_enrollment_profile"`
*ResponseMobileDeviceEnrollmentProfile
}{
ResponseMobileDeviceEnrollmentProfile: profile,
}
var responseProfile ResponseMobileDeviceEnrollmentProfile
resp, err := c.HTTP.DoRequest("POST", endpoint, &requestBody, &responseProfile)
if err != nil {
return nil, fmt.Errorf("failed to create mobile device enrollment profile: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &responseProfile, nil
}
// UpdateMobileDeviceEnrollmentProfileByID updates a mobile device enrollment profile by its ID.
func (c *Client) UpdateMobileDeviceEnrollmentProfileByID(id int, profile *ResponseMobileDeviceEnrollmentProfile) (*ResponseMobileDeviceEnrollmentProfile, error) {
endpoint := fmt.Sprintf("%s/id/%d", uriMobileDeviceEnrollmentProfiles, id)
requestBody := struct {
XMLName xml.Name `xml:"mobile_device_enrollment_profile"`
*ResponseMobileDeviceEnrollmentProfile
}{
ResponseMobileDeviceEnrollmentProfile: profile,
}
var responseProfile ResponseMobileDeviceEnrollmentProfile
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &responseProfile)
if err != nil {
return nil, fmt.Errorf("failed to update mobile device enrollment profile by ID: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &responseProfile, nil
}
// UpdateMobileDeviceEnrollmentProfileByName updates a mobile device enrollment profile by its name.
func (c *Client) UpdateMobileDeviceEnrollmentProfileByName(name string, profile *ResponseMobileDeviceEnrollmentProfile) (*ResponseMobileDeviceEnrollmentProfile, error) {
endpoint := fmt.Sprintf("%s/name/%s", uriMobileDeviceEnrollmentProfiles, name)
requestBody := struct {
XMLName xml.Name `xml:"mobile_device_enrollment_profile"`
*ResponseMobileDeviceEnrollmentProfile
}{
ResponseMobileDeviceEnrollmentProfile: profile,
}
var responseProfile ResponseMobileDeviceEnrollmentProfile
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &responseProfile)
if err != nil {
return nil, fmt.Errorf("failed to update mobile device enrollment profile by name: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &responseProfile, nil
}
// UpdateMobileDeviceEnrollmentProfileByInvitation updates a mobile device enrollment profile by its invitation.
func (c *Client) UpdateMobileDeviceEnrollmentProfileByInvitation(invitation string, profile *ResponseMobileDeviceEnrollmentProfile) (*ResponseMobileDeviceEnrollmentProfile, error) {
endpoint := fmt.Sprintf("%s/invitation/%s", uriMobileDeviceEnrollmentProfiles, invitation)
requestBody := struct {
XMLName xml.Name `xml:"mobile_device_enrollment_profile"`
*ResponseMobileDeviceEnrollmentProfile
}{
ResponseMobileDeviceEnrollmentProfile: profile,
}
var responseProfile ResponseMobileDeviceEnrollmentProfile
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &responseProfile)
if err != nil {
return nil, fmt.Errorf("failed to update mobile device enrollment profile by invitation: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &responseProfile, nil
}
// DeleteMobileDeviceEnrollmentProfileByID deletes a mobile device enrollment profile by its ID.
func (c *Client) DeleteMobileDeviceEnrollmentProfileByID(id int) error {
endpoint := fmt.Sprintf("%s/id/%d", uriMobileDeviceEnrollmentProfiles, id)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf("failed to delete mobile device enrollment profile by ID: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}
// DeleteMobileDeviceEnrollmentProfileByName deletes a mobile device enrollment profile by its name.
func (c *Client) DeleteMobileDeviceEnrollmentProfileByName(name string) error {
endpoint := fmt.Sprintf("%s/name/%s", uriMobileDeviceEnrollmentProfiles, name)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf("failed to delete mobile device enrollment profile by name: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}
// DeleteMobileDeviceEnrollmentProfileByInvitation deletes a mobile device enrollment profile by its invitation.
func (c *Client) DeleteMobileDeviceEnrollmentProfileByInvitation(invitation string) error {
endpoint := fmt.Sprintf("%s/invitation/%s", uriMobileDeviceEnrollmentProfiles, invitation)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf("failed to delete mobile device enrollment profile by invitation: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}