-
Notifications
You must be signed in to change notification settings - Fork 5
/
classicapi_mobile_devices.go
413 lines (349 loc) · 16.1 KB
/
classicapi_mobile_devices.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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
// classicapi_mobile_devices.go
// Jamf Pro Classic Api - Mobile Devices
// API reference: https://developer.jamf.com/jamf-pro/reference/mobiledevices
// Jamf Pro Classic API requires the structs to support an XML data structure.
package jamfpro
import (
"encoding/xml"
"fmt"
)
const uriMobileDevices = "/JSSResource/mobiledevices"
// List
// ResponseMobileDevicesList represents the structure for a list of mobile devices.
type ResponseMobileDeviceList struct {
MobileDevices []MobileDeviceListItem `xml:"mobile_device"`
}
type MobileDeviceListItem struct {
ID int `xml:"id"`
Name string `xml:"name"`
DeviceName string `xml:"device_name"`
UDID string `xml:"udid"`
SerialNumber string `xml:"serial_number"`
PhoneNumber string `xml:"phone_number"`
WifiMacAddress string `xml:"wifi_mac_address"`
Managed bool `xml:"managed"`
Supervised bool `xml:"supervised"`
Model string `xml:"model"`
ModelIdentifier string `xml:"model_identifier"`
ModelDisplay string `xml:"model_display"`
Username string `xml:"username"`
}
// Resource
// ResourceMobileDevice represents the structure for a of a mobile device.
type ResourceMobileDevice struct {
General MobileDeviceSubsetGeneral `xml:"general"`
Location MobileDeviceSubsetLocation `xml:"location"`
Purchasing MobileDeviceSubsetPurchasing `xml:"purchasing"`
Applications []MobileDeviceSubsetApplication `xml:"applications>application"`
SecurityObject MobileDeviceSubsetSecurity `xml:"security_object"`
Network MobileDeviceSubsetNetwork `xml:"network"`
Certificates []MobileDeviceSubsetCertificate `xml:"certificates>certificate"`
ConfigurationProfiles []MobileDeviceSubsetConfigurationProfile `xml:"configuration_profiles>configuration_profile"`
ProvisioningProfiles []MobileDeviceSubsetProvisioningProfile `xml:"provisioning_profiles>mobile_device_provisioning_profile"`
MobileDeviceGroups []MobileDeviceSubsetGroup `xml:"mobile_device_groups>mobile_device_group"`
ExtensionAttributes []MobileDeviceSubsetExtensionAttribute `xml:"extension_attributes>extension_attribute"`
}
// Subsets & Containers
type MobileDeviceSubsetGeneral struct {
ID int `xml:"id"`
DisplayName string `xml:"display_name"`
DeviceName string `xml:"device_name"`
Name string `xml:"name"`
AssetTag string `xml:"asset_tag"`
LastInventoryUpdate string `xml:"last_inventory_update"`
LastInventoryUpdateEpoch int64 `xml:"last_inventory_update_epoch"`
LastInventoryUpdateUTC string `xml:"last_inventory_update_utc"`
Capacity int `xml:"capacity"`
CapacityMB int `xml:"capacity_mb"`
Available int `xml:"available"`
AvailableMB int `xml:"available_mb"`
PercentageUsed int `xml:"percentage_used"`
OSType string `xml:"os_type"`
OSVersion string `xml:"os_version"`
OSBuild string `xml:"os_build"`
SerialNumber string `xml:"serial_number"`
UDID string `xml:"udid"`
InitialEntryDateEpoch int64 `xml:"initial_entry_date_epoch"`
InitialEntryDateUTC string `xml:"initial_entry_date_utc"`
PhoneNumber string `xml:"phone_number"`
IPAddress string `xml:"ip_address"`
WifiMacAddress string `xml:"wifi_mac_address"`
BluetoothMacAddress string `xml:"bluetooth_mac_address"`
ModemFirmware string `xml:"modem_firmware"`
Model string `xml:"model"`
ModelIdentifier string `xml:"model_identifier"`
ModelNumber string `xml:"model_number"`
ModelDisplay string `xml:"model_display"`
DeviceOwnershipLevel string `xml:"device_ownership_level"`
LastEnrollmentEpoch int64 `xml:"last_enrollment_epoch"`
LastEnrollmentUTC string `xml:"last_enrollment_utc"`
Managed bool `xml:"managed"`
Supervised bool `xml:"supervised"`
ExchangeActiveSyncDeviceIdentifier string `xml:"exchange_activesync_device_identifier"`
Shared string `xml:"shared"`
Tethered string `xml:"tethered"`
BatteryLevel int `xml:"battery_level"`
BLECapable bool `xml:"ble_capable"`
DeviceLocatorServiceEnabled bool `xml:"device_locator_service_enabled"`
DoNotDisturbEnabled bool `xml:"do_not_disturb_enabled"`
CloudBackupEnabled bool `xml:"cloud_backup_enabled"`
LastCloudBackupDateEpoch int64 `xml:"last_cloud_backup_date_epoch"`
LastCloudBackupDateUTC string `xml:"last_cloud_backup_date_utc"`
LocationServicesEnabled bool `xml:"location_services_enabled"`
ItunesStoreAccountIsActive bool `xml:"itunes_store_account_is_active"`
LastBackupTimeEpoch int64 `xml:"last_backup_time_epoch"`
LastBackupTimeUTC string `xml:"last_backup_time_utc"`
}
type MobileDeviceSubsetLocation struct {
Username string `xml:"username"`
RealName string `xml:"realname"`
EmailAddress string `xml:"email_address"`
Position string `xml:"position"`
Phone string `xml:"phone"`
PhoneNumber string `xml:"phone_number"`
Department string `xml:"department"`
Building string `xml:"building"`
Room int `xml:"room"`
}
type MobileDeviceSubsetPurchasing struct {
IsPurchased bool `xml:"is_purchased"`
IsLeased bool `xml:"is_leased"`
PONumber string `xml:"po_number"`
Vendor string `xml:"vendor"`
ApplecareID string `xml:"applecare_id"`
PurchasePrice string `xml:"purchase_price"`
PurchasingAccount string `xml:"purchasing_account"`
PODate string `xml:"po_date"`
PODateEpoch int64 `xml:"po_date_epoch"`
PODateUTC string `xml:"po_date_utc"`
WarrantyExpires string `xml:"warranty_expires"`
WarrantyExpiresEpoch int64 `xml:"warranty_expires_epoch"`
WarrantyExpiresUTC string `xml:"warranty_expires_utc"`
LeaseExpires string `xml:"lease_expires"`
LeaseExpiresEpoch int64 `xml:"lease_expires_epoch"`
LeaseExpiresUTC string `xml:"lease_expires_utc"`
LifeExpectancy int `xml:"life_expectancy"`
PurchasingContact string `xml:"purchasing_contact"`
}
type MobileDeviceSubsetApplication struct {
ApplicationName string `xml:"application_name"`
ApplicationVersion string `xml:"application_version"`
Identifier string `xml:"identifier"`
}
type MobileDeviceSubsetSecurity struct {
DataProtection bool `xml:"data_protection"`
BlockLevelEncryptionCapable bool `xml:"block_level_encryption_capable"`
FileLevelEncryptionCapable bool `xml:"file_level_encryption_capable"`
PasscodePresent bool `xml:"passcode_present"`
PasscodeCompliant bool `xml:"passcode_compliant"`
PasscodeCompliantWithProfile bool `xml:"passcode_compliant_with_profile"`
PasscodeLockGracePeriodEnforced string `xml:"passcode_lock_grace_period_enforced"`
HardwareEncryption string `xml:"hardware_encryption"`
ActivationLockEnabled bool `xml:"activation_lock_enabled"`
JailbreakDetected string `xml:"jailbreak_detected"`
LostModeEnabled bool `xml:"lost_mode_enabled"`
LostModeEnforced bool `xml:"lost_mode_enforced"`
LostModeEnableIssuedEpoch int64 `xml:"lost_mode_enable_issued_epoch"`
LostModeEnableIssuedUTC string `xml:"lost_mode_enable_issued_utc"`
LostModeMessage string `xml:"lost_mode_message"`
LostModePhone string `xml:"lost_mode_phone"`
LostModeFootnote string `xml:"lost_mode_footnote"`
LostLocationEpoch int64 `xml:"lost_location_epoch"`
LostLocationUTC string `xml:"lost_location_utc"`
LostLocationLatitude float64 `xml:"lost_location_latitude"`
LostLocationLongitude float64 `xml:"lost_location_longitude"`
LostLocationAltitude float64 `xml:"lost_location_altitude"`
LostLocationSpeed float64 `xml:"lost_location_speed"`
LostLocationCourse float64 `xml:"lost_location_course"`
LostLocationHorizontalAccuracy float64 `xml:"lost_location_horizontal_accuracy"`
LostLocationVerticalAccuracy float64 `xml:"lost_location_vertical_accuracy"`
}
type MobileDeviceSubsetNetwork struct {
HomeCarrierNetwork string `xml:"home_carrier_network"`
CellularTechnology string `xml:"cellular_technology"`
VoiceRoamingEnabled string `xml:"voice_roaming_enabled"`
IMEI string `xml:"imei"`
ICCID string `xml:"iccid"`
CurrentCarrierNetwork string `xml:"current_carrier_network"`
CarrierSettingsVersion int `xml:"carrier_settings_version"`
CurrentMobileCountryCode int `xml:"current_mobile_country_code"`
CurrentMobileNetworkCode int `xml:"current_mobile_network_code"`
HomeMobileCountryCode int `xml:"home_mobile_country_code"`
HomeMobileNetworkCode int `xml:"home_mobile_network_code"`
DataRoamingEnabled bool `xml:"data_roaming_enabled"`
PhoneNumber string `xml:"phone_number"`
}
type MobileDeviceSubsetCertificate struct {
CommonName string `xml:"common_name"`
Identity bool `xml:"identity"`
}
type MobileDeviceSubsetConfigurationProfile struct {
DisplayName string `xml:"display_name"`
Version int `xml:"version"`
Identifier string `xml:"identifier"`
UUID string `xml:"uuid"`
}
type MobileDeviceSubsetProvisioningProfile struct {
DisplayName string `xml:"display_name"`
ExpirationDate string `xml:"expiration_date"`
ExpirationDateEpoch int64 `xml:"expiration_date_epoch"`
ExpirationDateUTC string `xml:"expiration_date_utc"`
UUID string `xml:"uuid"`
}
type MobileDeviceSubsetGroup struct {
ID int `xml:"id"`
Name string `xml:"name"`
}
type MobileDeviceSubsetExtensionAttribute struct {
ID int `xml:"id"`
Name string `xml:"name"`
Type string `xml:"type"`
Value string `xml:"value"`
}
// CRUD
// GetMobileDevices retrieves a list of all mobile devices.
func (c *Client) GetMobileDevices() (*ResponseMobileDeviceList, error) {
endpoint := uriMobileDevices
var mobileDevices ResponseMobileDeviceList
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &mobileDevices)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGet, "mobile devices", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &mobileDevices, nil
}
// GetMobileDeviceByID retrieves a specific mobile device by its ID.
func (c *Client) GetMobileDeviceByID(id int) (*ResourceMobileDevice, error) {
endpoint := fmt.Sprintf("%s/id/%d", uriMobileDevices, id)
var device ResourceMobileDevice
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &device)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByID, "mobile device", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &device, nil
}
// GetMobileDeviceByName retrieves a specific mobile device by its name.
func (c *Client) GetMobileDeviceByName(name string) (*ResourceMobileDevice, error) {
endpoint := fmt.Sprintf("%s/name/%s", uriMobileDevices, name)
var device ResourceMobileDevice
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &device)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByName, "mobile device", name, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &device, nil
}
// GetMobileDeviceByIDAndDataSubset retrieves a specific subset of data for a mobile device by its ID.
func (c *Client) GetMobileDeviceByIDAndDataSubset(id int, subset string) (*ResourceMobileDevice, error) {
endpoint := fmt.Sprintf("%s/id/%d/subset/%s", uriMobileDevices, id, subset)
var deviceSubset ResourceMobileDevice
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &deviceSubset)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByID, "mobile device with data subset", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &deviceSubset, nil
}
// GetMobileDeviceByNameAndDataSubset retrieves a specific subset of data for a mobile device by its name.
func (c *Client) GetMobileDeviceByNameAndDataSubset(name, subset string) (*ResourceMobileDevice, error) {
endpoint := fmt.Sprintf("%s/name/%s/subset/%s", uriMobileDevices, name, subset)
var deviceSubset ResourceMobileDevice
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &deviceSubset)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByName, "mobile device with data subset", name, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &deviceSubset, nil
}
// CreateMobileDevice creates a new mobile device device.
func (c *Client) CreateMobileDevice(attribute *ResourceMobileDevice) (*ResourceMobileDevice, error) {
endpoint := fmt.Sprintf("%s/id/0", uriMobileDevices)
requestBody := struct {
XMLName xml.Name `xml:"mobile_device"`
*ResourceMobileDevice
}{
ResourceMobileDevice: attribute,
}
var responseAttribute ResourceMobileDevice
resp, err := c.HTTP.DoRequest("POST", endpoint, &requestBody, &responseAttribute)
if err != nil {
return nil, fmt.Errorf(errMsgFailedCreate, "mobile device", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &responseAttribute, nil
}
// UpdateMobileDeviceByID updates a mobile device by its ID.
func (c *Client) UpdateMobileDeviceByID(id int, attribute *ResourceMobileDevice) (*ResourceMobileDevice, error) {
endpoint := fmt.Sprintf("%s/id/%d", uriMobileDevices, id)
requestBody := struct {
XMLName xml.Name `xml:"mobile_device"`
*ResourceMobileDevice
}{
ResourceMobileDevice: attribute,
}
var responseAttribute ResourceMobileDevice
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &responseAttribute)
if err != nil {
return nil, fmt.Errorf(errMsgFailedUpdateByID, "mobile device", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &responseAttribute, nil
}
// UpdateMobileDeviceByName updates a mobile device by its name.
func (c *Client) UpdateMobileDeviceByName(name string, attribute *ResourceMobileDevice) (*ResourceMobileDevice, error) {
endpoint := fmt.Sprintf("%s/name/%s", uriMobileDevices, name)
requestBody := struct {
XMLName xml.Name `xml:"mobile_device"`
*ResourceMobileDevice
}{
ResourceMobileDevice: attribute,
}
var responseAttribute ResourceMobileDevice
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &responseAttribute)
if err != nil {
return nil, fmt.Errorf(errMsgFailedUpdateByName, "mobile device", name, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &responseAttribute, nil
}
// DeleteMobileDeviceByID deletes a mobile device by its ID.
func (c *Client) DeleteMobileDeviceByID(id int) error {
endpoint := fmt.Sprintf("%s/id/%d", uriMobileDevices, id)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf(errMsgFailedDeleteByID, "mobile device", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}
// DeleteMobileDeviceByName deletes a mobile device by its name.
func (c *Client) DeleteMobileDeviceByName(name string) error {
endpoint := fmt.Sprintf("%s/name/%s", uriMobileDevices, name)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf(errMsgFailedDeleteByName, "mobile device", name, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}