/
classicapi_mobile_device_provisioning_profiles.go
308 lines (238 loc) · 10.9 KB
/
classicapi_mobile_device_provisioning_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
// classicapi_mobile_device_provisioning_profiles.go
// Jamf Pro Classic Api - Mobile Device Provisioning Profiles
// API reference: https://developer.jamf.com/jamf-pro/reference/mobiledeviceprovisioningprofiles
// Jamf Pro Classic API requires the structs to support an XML data structure.
package jamfpro
import (
"encoding/xml"
"fmt"
)
const uriMobileDeviceProvisioningProfiles = "/JSSResource/mobiledeviceprovisioningprofiles"
// List
// ResponseMobileDeviceProvisioningProfilesList represents the response for a list of mobile device provisioning profiles.
type ResponseMobileDeviceProvisioningProfilesList struct {
Size int `xml:"size"`
MobileDeviceProvisioningProfile []MobileDeviceProvisioningProfilesListItem `xml:"mobile_device_provisioning_profile"`
}
type MobileDeviceProvisioningProfilesListItem struct {
ID int `xml:"id"`
Name string `xml:"name"`
DisplayName string `xml:"display_name"`
UUID string `xml:"uuid"`
}
// Resource
// ResourceMobileDeviceProvisioningProfile represents the detailed structure for a mobile device provisioning profile.
type ResourceMobileDeviceProvisioningProfile struct {
General MobileDeviceProvisioningProfileSubsetGeneral `xml:"general"`
}
// Subsets
type MobileDeviceProvisioningProfileSubsetGeneral struct {
ID int `xml:"id"`
Name string `xml:"name"`
DisplayName string `xml:"display_name"`
UUID string `xml:"uuid"`
}
// CRUD
// GetMobileDeviceProvisioningProfiles retrieves a serialized list of mobile device provisioning profiles.
func (c *Client) GetMobileDeviceProvisioningProfiles() (*ResponseMobileDeviceProvisioningProfilesList, error) {
endpoint := uriMobileDeviceProvisioningProfiles
var profiles ResponseMobileDeviceProvisioningProfilesList
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &profiles)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGet, "mobile device provisioning profiles", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &profiles, nil
}
// GetMobileDeviceProvisioningProfileByID fetches a specific mobile device provisioning profile by its ID.
func (c *Client) GetMobileDeviceProvisioningProfileByID(id int) (*ResourceMobileDeviceProvisioningProfile, error) {
endpoint := fmt.Sprintf("%s/id/%d", uriMobileDeviceProvisioningProfiles, id)
var profile ResourceMobileDeviceProvisioningProfile
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &profile)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByID, "mobile device provisioning profile", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &profile, nil
}
// GetMobileDeviceProvisioningProfileByName fetches a specific mobile device provisioning profile by its name.
func (c *Client) GetMobileDeviceProvisioningProfileByName(name string) (*ResourceMobileDeviceProvisioningProfile, error) {
endpoint := fmt.Sprintf("%s/name/%s", uriMobileDeviceProvisioningProfiles, name)
var profile ResourceMobileDeviceProvisioningProfile
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &profile)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByName, "mobile device provisioning profile", name, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &profile, nil
}
// GetMobileDeviceProvisioningProfileByUUID fetches a specific mobile device provisioning profile by its UUID.
func (c *Client) GetMobileDeviceProvisioningProfileByUUID(uuid string) (*ResourceMobileDeviceProvisioningProfile, error) {
endpoint := fmt.Sprintf("%s/uuid/%s", uriMobileDeviceProvisioningProfiles, uuid)
var profile ResourceMobileDeviceProvisioningProfile
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &profile)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByString, "mobile device provisioning profile", "uuid", uuid, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &profile, nil
}
// CreateMobileDeviceProvisioningProfileByID creates a new mobile device provisioning profile by its ID.
func (c *Client) CreateMobileDeviceProvisioningProfile(id int, profile *ResourceMobileDeviceProvisioningProfile) (*ResourceMobileDeviceProvisioningProfile, error) {
endpoint := fmt.Sprintf("%s/id/%d", uriMobileDeviceProvisioningProfiles, id)
requestBody := struct {
XMLName xml.Name `xml:"mobile_device_provisioning_profile"`
*ResourceMobileDeviceProvisioningProfile
}{
ResourceMobileDeviceProvisioningProfile: profile,
}
var responseProfile ResourceMobileDeviceProvisioningProfile
resp, err := c.HTTP.DoRequest("POST", endpoint, &requestBody, &responseProfile)
if err != nil {
return nil, fmt.Errorf(errMsgFailedCreateWithValue, "mobile device provisioning profile", "id", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &responseProfile, nil
}
// CreateMobileDeviceProvisioningProfileByName creates a new mobile device provisioning profile by its name.
func (c *Client) CreateMobileDeviceProvisioningProfileByName(name string, profile *ResourceMobileDeviceProvisioningProfile) (*ResourceMobileDeviceProvisioningProfile, error) {
endpoint := fmt.Sprintf("%s/name/%s", uriMobileDeviceProvisioningProfiles, name)
requestBody := struct {
XMLName xml.Name `xml:"mobile_device_provisioning_profile"`
*ResourceMobileDeviceProvisioningProfile
}{
ResourceMobileDeviceProvisioningProfile: profile,
}
var responseProfile ResourceMobileDeviceProvisioningProfile
resp, err := c.HTTP.DoRequest("POST", endpoint, &requestBody, &responseProfile)
if err != nil {
return nil, fmt.Errorf(errMsgFailedCreateWithValue, "mobile device provisioning profile", "name", name, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &responseProfile, nil
}
// QUERY is this creating by a UUID? - yes. you can use https://imazing.com/profile-editor to test
// CreateMobileDeviceProvisioningProfileByUUID creates a new mobile device provisioning profile by its UUID.
func (c *Client) CreateMobileDeviceProvisioningProfileByUUID(uuid string, profile *ResourceMobileDeviceProvisioningProfile) (*ResourceMobileDeviceProvisioningProfile, error) {
endpoint := fmt.Sprintf("%s/uuid/%s", uriMobileDeviceProvisioningProfiles, uuid)
requestBody := struct {
XMLName xml.Name `xml:"mobile_device_provisioning_profile"`
*ResourceMobileDeviceProvisioningProfile
}{
ResourceMobileDeviceProvisioningProfile: profile,
}
var responseProfile ResourceMobileDeviceProvisioningProfile
resp, err := c.HTTP.DoRequest("POST", endpoint, &requestBody, &responseProfile)
if err != nil {
return nil, fmt.Errorf(errMsgFailedCreateWithValue, "mobile device provisioning profile", "uuid", uuid, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &responseProfile, nil
}
// UpdateMobileDeviceProvisioningProfileByID updates a mobile device provisioning profile by its ID.
func (c *Client) UpdateMobileDeviceProvisioningProfileByID(id int, profile *ResourceMobileDeviceProvisioningProfile) (*ResourceMobileDeviceProvisioningProfile, error) {
endpoint := fmt.Sprintf("%s/id/%d", uriMobileDeviceProvisioningProfiles, id)
requestBody := struct {
XMLName xml.Name `xml:"mobile_device_provisioning_profile"`
*ResourceMobileDeviceProvisioningProfile
}{
ResourceMobileDeviceProvisioningProfile: profile,
}
var updatedProfile ResourceMobileDeviceProvisioningProfile
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &updatedProfile)
if err != nil {
return nil, fmt.Errorf(errMsgFailedUpdateByID, "mobile device provisioning profile", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &updatedProfile, nil
}
// UpdateMobileDeviceProvisioningProfileByName updates a mobile device provisioning profile by its name.
func (c *Client) UpdateMobileDeviceProvisioningProfileByName(name string, profile *ResourceMobileDeviceProvisioningProfile) (*ResourceMobileDeviceProvisioningProfile, error) {
endpoint := fmt.Sprintf("%s/name/%s", uriMobileDeviceProvisioningProfiles, name)
requestBody := struct {
XMLName xml.Name `xml:"mobile_device_provisioning_profile"`
*ResourceMobileDeviceProvisioningProfile
}{
ResourceMobileDeviceProvisioningProfile: profile,
}
var updatedProfile ResourceMobileDeviceProvisioningProfile
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &updatedProfile)
if err != nil {
return nil, fmt.Errorf(errMsgFailedUpdateByName, "mobile device provisioning profile", name, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &updatedProfile, nil
}
// UpdateMobileDeviceProvisioningProfileByUUID updates a mobile device provisioning profile by its UUID.
func (c *Client) UpdateMobileDeviceProvisioningProfileByUUID(uuid string, profile *ResourceMobileDeviceProvisioningProfile) (*ResourceMobileDeviceProvisioningProfile, error) {
endpoint := fmt.Sprintf("%s/uuid/%s", uriMobileDeviceProvisioningProfiles, uuid)
requestBody := struct {
XMLName xml.Name `xml:"mobile_device_provisioning_profile"`
*ResourceMobileDeviceProvisioningProfile
}{
ResourceMobileDeviceProvisioningProfile: profile,
}
var updatedProfile ResourceMobileDeviceProvisioningProfile
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &updatedProfile)
if err != nil {
return nil, fmt.Errorf(errMsgFailedUpdateByString, "mobile device provisioning profile", "uuid", uuid, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &updatedProfile, nil
}
// DeleteMobileDeviceProvisioningProfileByID deletes a mobile device provisioning profile by ID
func (c *Client) DeleteMobileDeviceProvisioningProfileByID(id int) error {
endpoint := fmt.Sprintf("%s/id/%d", uriMobileDeviceProvisioningProfiles, id)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf(errMsgFailedDeleteByID, "mobile device provisioning profile", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}
// DeleteMobileDeviceProvisioningProfileByName deletes a mobile device provisioning profile by Name
func (c *Client) DeleteMobileDeviceProvisioningProfileByName(name string) error {
endpoint := fmt.Sprintf("%s/name/%s", uriMobileDeviceProvisioningProfiles, name)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf(errMsgFailedDeleteByName, "mobile device provisioning profile", name, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}
// DeleteMobileDeviceProvisioningProfileByUUID deletes a mobile device provisioning profile by UUID
func (c *Client) DeleteMobileDeviceProvisioningProfileByUUID(uuid string) error {
endpoint := fmt.Sprintf("%s/uuid/%s", uriMobileDeviceProvisioningProfiles, uuid)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf(errMsgFailedDeleteByString, "mobile device provisioning profile", "uuid", uuid, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}