-
Notifications
You must be signed in to change notification settings - Fork 5
/
jamfproapi_computer_prestages.go
318 lines (265 loc) · 13.6 KB
/
jamfproapi_computer_prestages.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
// jamfproapi_computer_prestages.go
// Jamf Pro Api - Computer Prestages
// api reference: https://developer.jamf.com/jamf-pro/reference/get_v2-computer-prestages-scope
// Jamf Pro API requires the structs to support a JSON data structure.
package jamfpro
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
const uriComputerPrestagesV2 = "/api/v2/computer-prestages"
const uriComputerPrestagesV3 = "/api/v3/computer-prestages"
// List
type ResponseComputerPrestagesList struct {
TotalCount *int `json:"totalCount"`
Results []ResourceComputerPrestage `json:"results"`
}
// Responses
// ResponseDeviceScope represents the structure of the response for a specific computer prestage scope.
type ResponseDeviceScope struct {
PrestageId string `json:"prestageId"`
Assignments []DeviceScopeSubsetAssignmentItem `json:"assignments"`
VersionLock int `json:"versionLock"`
}
// AssignmentItem represents the structure of each assignment within the prestage scope.
type DeviceScopeSubsetAssignmentItem struct {
SerialNumber string `json:"serialNumber"`
AssignmentDate string `json:"assignmentDate"`
UserAssigned string `json:"userAssigned"`
}
// ResponseComputerPrestageCreate represents the response structure for creating a building.
type ResponseComputerPrestageCreate struct {
ID string `json:"id"`
Href string `json:"href"`
}
// Resource
type ResourceComputerPrestage struct {
ID string `json:"id"`
DisplayName string `json:"displayName"`
Mandatory bool `json:"mandatory"`
MDMRemovable bool `json:"mdmRemovable"`
SupportPhoneNumber string `json:"supportPhoneNumber,omitempty"`
SupportEmailAddress string `json:"supportEmailAddress,omitempty"`
Department string `json:"department,omitempty"`
DefaultPrestage bool `json:"defaultPrestage"`
EnrollmentSiteId string `json:"enrollmentSiteId,omitempty"`
KeepExistingSiteMembership bool `json:"keepExistingSiteMembership"`
KeepExistingLocationInformation bool `json:"keepExistingLocationInformation"`
RequireAuthentication bool `json:"requireAuthentication"`
AuthenticationPrompt string `json:"authenticationPrompt,omitempty"`
PreventActivationLock bool `json:"preventActivationLock"`
EnableDeviceBasedActivationLock bool `json:"enableDeviceBasedActivationLock"`
DeviceEnrollmentProgramInstanceId string `json:"deviceEnrollmentProgramInstanceId,omitempty"`
SkipSetupItems ComputerPrestageSubsetSkipSetupItems `json:"skipSetupItems"`
LocationInformation ComputerPrestageSubsetLocationInformation `json:"locationInformation"`
PurchasingInformation ComputerPrestageSubsetPurchasingInformation `json:"purchasingInformation"`
AnchorCertificates []string `json:"anchorCertificates,omitempty"`
EnrollmentCustomizationId string `json:"enrollmentCustomizationId,omitempty"`
Language string `json:"language,omitempty"`
Region string `json:"region,omitempty"`
AutoAdvanceSetup bool `json:"autoAdvanceSetup"`
InstallProfilesDuringSetup bool `json:"installProfilesDuringSetup"`
PrestageInstalledProfileIds []string `json:"prestageInstalledProfileIds,omitempty"`
CustomPackageIds []string `json:"customPackageIds,omitempty"`
CustomPackageDistributionPointId string `json:"customPackageDistributionPointId,omitempty"`
EnableRecoveryLock bool `json:"enableRecoveryLock"`
RecoveryLockPasswordType string `json:"recoveryLockPasswordType,omitempty"`
RecoveryLockPassword string `json:"recoveryLockPassword,omitempty"`
RotateRecoveryLockPassword bool `json:"rotateRecoveryLockPassword"`
ProfileUuid string `json:"profileUuid,omitempty"`
SiteId string `json:"siteId,omitempty"`
VersionLock int `json:"versionLock,omitempty"`
AccountSettings ComputerPrestageSubsetAccountSettings `json:"accountSettings"`
}
// Subsets & Containers
type ComputerPrestageSubsetSkipSetupItems struct {
Biometric bool `json:"Biometric"`
TermsOfAddress bool `json:"TermsOfAddress"`
FileVault bool `json:"FileVault"`
ICloudDiagnostics bool `json:"iCloudDiagnostics"`
Diagnostics bool `json:"Diagnostics"`
Accessibility bool `json:"Accessibility"`
AppleID bool `json:"AppleID"`
ScreenTime bool `json:"ScreenTime"`
Siri bool `json:"Siri"`
DisplayTone bool `json:"DisplayTone"`
Restore bool `json:"Restore"`
Appearance bool `json:"Appearance"`
Privacy bool `json:"Privacy"`
Payment bool `json:"Payment"`
Registration bool `json:"Registration"`
TOS bool `json:"TOS"`
ICloudStorage bool `json:"iCloudStorage"`
Location bool `json:"Location"`
}
type ComputerPrestageSubsetLocationInformation struct {
Username string `json:"username"`
Realname string `json:"realname"`
Phone string `json:"phone"`
Email string `json:"email"`
Room string `json:"room"`
Position string `json:"position"`
DepartmentId string `json:"departmentId,omitempty"`
BuildingId string `json:"buildingId,omitempty"`
ID string `json:"id,omitempty"`
VersionLock int `json:"versionLock"`
}
type ComputerPrestageSubsetPurchasingInformation struct {
ID string `json:"id,omitempty"`
Leased bool `json:"leased"`
Purchased bool `json:"purchased"`
AppleCareId string `json:"appleCareId"`
PONumber string `json:"poNumber"`
Vendor string `json:"vendor"`
PurchasePrice string `json:"purchasePrice"`
LifeExpectancy int `json:"lifeExpectancy"`
PurchasingAccount string `json:"purchasingAccount"`
PurchasingContact string `json:"purchasingContact"`
LeaseDate string `json:"leaseDate,omitempty"`
PODate string `json:"poDate,omitempty"`
WarrantyDate string `json:"warrantyDate,omitempty"`
VersionLock int `json:"versionLock"`
}
type ComputerPrestageSubsetAccountSettings struct {
ID string `json:"id,omitempty"`
PayloadConfigured bool `json:"payloadConfigured"`
LocalAdminAccountEnabled bool `json:"localAdminAccountEnabled"`
AdminUsername string `json:"adminUsername,omitempty"`
AdminPassword string `json:"adminPassword,omitempty"`
HiddenAdminAccount bool `json:"hiddenAdminAccount"`
LocalUserManaged bool `json:"localUserManaged"`
UserAccountType string `json:"userAccountType,omitempty"`
VersionLock int `json:"versionLock,omitempty"`
PrefillPrimaryAccountInfoFeatureEnabled bool `json:"prefillPrimaryAccountInfoFeatureEnabled"`
PrefillType string `json:"prefillType,omitempty"`
PrefillAccountFullName string `json:"prefillAccountFullName,omitempty"`
PrefillAccountUserName string `json:"prefillAccountUserName,omitempty"`
PreventPrefillInfoFromModification bool `json:"preventPrefillInfoFromModification"`
}
// CRUD
// GetComputerPrestagesV3 retrieves all computer prestage information with optional sorting.
func (c *Client) GetComputerPrestages(sort_filter string) (*ResponseComputerPrestagesList, error) {
resp, err := c.DoPaginatedGet(
uriComputerPrestagesV3,
standardPageSize,
startingPageNumber,
sort_filter,
)
if err != nil {
return nil, fmt.Errorf(errMsgFailedPaginatedGet, "computer prestages", err)
}
var out ResponseComputerPrestagesList
out.TotalCount = &resp.Size
for _, value := range resp.Results {
var newObj ResourceComputerPrestage
err := mapstructure.Decode(value, &newObj)
if err != nil {
return nil, fmt.Errorf(errMsgFailedMapstruct, "computer prestages", err)
}
out.Results = append(out.Results, newObj)
}
return &out, nil
}
// GetComputerPrestageByID retrieves a specific computer prestage by its ID.
func (c *Client) GetComputerPrestageByID(id string) (*ResourceComputerPrestage, error) {
endpoint := fmt.Sprintf("%s/%s", uriComputerPrestagesV3, id)
var prestage ResourceComputerPrestage
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &prestage)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByID, "computer prestage", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &prestage, nil
}
// GetComputerPrestageByName retrieves a specific computer prestage by its name.
func (c *Client) GetComputerPrestageByName(name string) (*ResourceComputerPrestage, error) {
prestages, err := c.GetComputerPrestages("")
if err != nil {
return nil, fmt.Errorf(errMsgFailedPaginatedGet, "computer prestages", err)
}
for _, value := range prestages.Results {
if value.DisplayName == name {
return &value, nil
}
}
return nil, fmt.Errorf(errMsgFailedGetByName, "computer prestage", name, errMsgNoName)
}
// CreateComputerPrestage creates a new computer prestage with the given details.
func (c *Client) CreateComputerPrestage(prestage *ResourceComputerPrestage) (*ResponseComputerPrestageCreate, error) {
endpoint := uriComputerPrestagesV3
var creationResponse ResponseComputerPrestageCreate
resp, err := c.HTTP.DoRequest("POST", endpoint, prestage, &creationResponse)
if err != nil {
return nil, fmt.Errorf(errMsgFailedCreate, "computer prestage", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &creationResponse, nil
}
// UpdateComputerPrestageByID updates a computer prestage by its ID.
func (c *Client) UpdateComputerPrestageByID(id string, prestageUpdate *ResourceComputerPrestage) (*ResourceComputerPrestage, error) {
endpoint := fmt.Sprintf("%s/%s", uriComputerPrestagesV3, id)
var updatedPrestage ResourceComputerPrestage
resp, err := c.HTTP.DoRequest("PUT", endpoint, prestageUpdate, &updatedPrestage)
if err != nil {
return nil, fmt.Errorf("failed to update computer prestage with ID %s: %v", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &updatedPrestage, nil
}
// UpdateComputerPrestageByNameByID updates a computer prestage based on its display name.
func (c *Client) UpdateComputerPrestageByName(name string, prestageUpdate *ResourceComputerPrestage) (*ResourceComputerPrestage, error) {
target, err := c.GetComputerPrestageByName(name)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByName, "computer prestage", name, err)
}
target_id := target.ID
resp, err := c.UpdateComputerPrestageByID(target_id, prestageUpdate)
if err != nil {
return nil, fmt.Errorf(errMsgFailedUpdateByName, "computer prestage", name, err)
}
return resp, nil
}
// DeleteComputerPrestageByID deletes a computer prestage by its ID
func (c *Client) DeleteComputerPrestageByID(id string) error {
endpoint := fmt.Sprintf("%s/%s", uriComputerPrestagesV3, id)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf(errMsgFailedDeleteByID, "computer prestage", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}
// DeleteComputerPrestageByNameByID deletes a computer prestage by its name.
func (c *Client) DeleteComputerPrestageByName(name string) error {
target, err := c.GetComputerPrestageByName(name)
if err != nil {
return fmt.Errorf(errMsgFailedPaginatedGet, "computer prestages", err)
}
target_id := target.ID
err = c.DeleteComputerPrestageByID(target_id)
if err != nil {
return fmt.Errorf(errMsgFailedDeleteByName, "computer prestage", name, err)
}
return nil
}
// GetDeviceScopeForComputerPrestage retrieves the device scope for a specific computer prestage by its ID.
func (c *Client) GetDeviceScopeForComputerPrestageByID(id string) (*ResponseDeviceScope, error) {
endpoint := fmt.Sprintf("%s/%s/scope", uriComputerPrestagesV2, id)
var deviceScope ResponseDeviceScope
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &deviceScope)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByID, "computer prestage scope", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &deviceScope, nil
}