-
Notifications
You must be signed in to change notification settings - Fork 5
/
classicapi_advanced_computer_searches.go
382 lines (309 loc) · 11.5 KB
/
classicapi_advanced_computer_searches.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
/*
Filename: classicapi_advanced_computer_searches.go
- Jamf Pro Classic API
- Resource: Advanced Computer Searches
- API reference: https://developer.jamf.com/jamf-pro/reference/advancedcomputersearches
- Data Structure: XML
Shared data structure resources in this endpoint:
- SharedResourceSite
- SharedContainerCriteria
- SharedAdvancedSearchSubsetDisplayField
*/
package jamfpro
import (
"encoding/xml"
"fmt"
)
const uriAPIAdvancedComputerSearches = "/JSSResource/advancedcomputersearches"
// List
// ResponseAdvancedComputerSearchesList represents the structure for multiple advanced computer searches.
type ResponseAdvancedComputerSearchesList struct {
Size int `xml:"size"`
AdvancedComputerSearches []AdvancedComputerSearchListItem `xml:"advanced_computer_search"`
}
type AdvancedComputerSearchListItem struct {
ID int `json:"id,omitempty" xml:"id"`
Name string `json:"name,omitempty" xml:"name"`
}
// Resource
// ResourceAdvancedComputerSearch represents the structure of the response for an advanced computer search.
type ResourceAdvancedComputerSearch struct {
ID int `xml:"id"`
Name string `xml:"name"`
ViewAs string `xml:"view_as,omitempty"`
Sort1 string `xml:"sort_1,omitempty"`
Sort2 string `xml:"sort_2,omitempty"`
Sort3 string `xml:"sort_3,omitempty"`
Criteria SharedContainerCriteria `xml:"criteria,omitempty"`
DisplayFields []SharedAdvancedSearchContainerDisplayField `xml:"display_fields,omitempty"`
Computers []AdvancedComputerSearchContainerComputers `xml:"computer,omitempty"`
Site *SharedResourceSite `xml:"site,omitempty"`
}
// Responses
type ResponseAdvancedComputerSearchCreatedAndUpdated struct {
ID int `json:"id,omitempty" xml:"id,omitempty"`
}
// Subsets & Containers
// Computer
type AdvancedComputerSearchContainerComputers struct {
Size int
Computer AdvancedComputerSearchSubsetComputer `xml:"computers"`
}
type AdvancedComputerSearchSubsetComputer struct {
ID int `xml:"id"`
Name string `xml:"name"`
UDID string `xml:"udid,omitempty"`
ComputerName string `xml:"Computer_Name,omitempty"`
}
// CRUD
/*
Function: GetAdvancedComputerSearches
Method: GET
Path: /JSSResource/advancedcomputersearches
Description: Gets a list of all Jamf Pro Advanced Computer Search resources.
Parameters: None
Returns: ResponseAdvancedComputerSearchesList - A list of advanced computer searches.
Errors: Returns an error if the request fails.
Example:
searches, err := client.GetAdvancedComputerSearches()
if err != nil {
log.Fatal(err)
}
fmt.Println(searches)
*/
func (c *Client) GetAdvancedComputerSearches() (*ResponseAdvancedComputerSearchesList, error) {
endpoint := uriAPIAdvancedComputerSearches
var searchesList ResponseAdvancedComputerSearchesList
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &searchesList)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGet, "advance computer searches", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &searchesList, nil
}
/*
Function: GetAdvancedComputerSearchByID
Method: GET
Path: /JSSResource/advancedcomputersearches/id/{id}
Description: Gets a Jamf Pro advanced computer search resource by its ID.
Parameters:
- id (int): The ID of the advanced computer search.
Returns: ResourceAdvancedComputerSearch - The advanced computer search resource.
Example:
search, err := client.GetAdvancedComputerSearchByID(123)
if err != nil {
log.Fatal(err)
}
fmt.Println(search)
Errors: Returns an error if the request fails or if the ID is not found.
*/
func (c *Client) GetAdvancedComputerSearchByID(id int) (*ResourceAdvancedComputerSearch, error) {
endpoint := fmt.Sprintf("%s/id/%d", uriAPIAdvancedComputerSearches, id)
var search ResourceAdvancedComputerSearch
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &search)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByID, "advance computer search", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &search, nil
}
/*
Function: GetAdvancedComputerSearchByName
Method: GET
Path: /JSSResource/advancedcomputersearches/name/{name}
Description: Gets a Jamf Pro advanced computer search resource by its name.
Parameters:
- name (string): The name of the advanced computer search.
Returns: ResourceAdvancedComputerSearch - The advanced computer search resource.
Example:
search, err := client.GetAdvancedComputerSearchByName("SearchName")
if err != nil {
log.Fatal(err)
}
fmt.Println(search)
Errors: Returns an error if the request fails or if the name is not found.
*/
func (c *Client) GetAdvancedComputerSearchByName(name string) (*ResourceAdvancedComputerSearch, error) {
endpoint := fmt.Sprintf("%s/name/%s", uriAPIAdvancedComputerSearches, name)
var search ResourceAdvancedComputerSearch
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &search)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByName, "advance computer search", name, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &search, nil
}
/*
Function: CreateAdvancedComputerSearch
Method: POST
Path: /JSSResource/advancedcomputersearches
Description: Creates a new Jamf Pro advanced computer search resource.
Parameters:
- search (*ResourceAdvancedComputerSearch): The advanced computer search resource to create.
Returns: ResponseAdvancedComputerSearchCreatedAndUpdated - The ID of the created advanced computer search resource.
Example:
newSearch := &jamfpro.ResourceAdvancedComputerSearch{
Name: "New Search",
// Other fields...
}
created, err := client.CreateAdvancedComputerSearch(newSearch)
if err != nil {
log.Fatal(err)
}
fmt.Println(created)
Errors: Returns an error if the request fails or if the resource cannot be created.
*/
func (c *Client) CreateAdvancedComputerSearch(search *ResourceAdvancedComputerSearch) (*ResponseAdvancedComputerSearchCreatedAndUpdated, error) {
endpoint := uriAPIAdvancedComputerSearches
requestBody := struct {
XMLName xml.Name `xml:"advanced_computer_search"`
*ResourceAdvancedComputerSearch
}{
ResourceAdvancedComputerSearch: search,
}
var createdSearch ResponseAdvancedComputerSearchCreatedAndUpdated
resp, err := c.HTTP.DoRequest("POST", endpoint, &requestBody, &createdSearch)
if err != nil {
return nil, fmt.Errorf(errMsgFailedCreate, "advance computer search", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &createdSearch, nil
}
/*
Function: UpdateAdvancedComputerSearchByID
Method: PUT
Path: /JSSResource/advancedcomputersearches/id/{id}
Description: Updates an existing Jamf Pro advanced computer search resource by its ID.
Parameters:
- id (int): The ID of the advanced computer search.
- search (*ResourceAdvancedComputerSearch): The updated advanced computer search resource.
Returns: ResponseAdvancedComputerSearchCreatedAndUpdated - The ID of the updated advanced computer search resource.
Example:
updatedSearch := &jamfpro.ResourceAdvancedComputerSearch{
Name: "Updated Search",
// Other fields...
}
updated, err := client.UpdateAdvancedComputerSearchByID(123, updatedSearch)
if err != nil {
log.Fatal(err)
}
fmt.Println(updated)
Errors: Returns an error if the request fails or if the resource cannot be updated.
*/
func (c *Client) UpdateAdvancedComputerSearchByID(id int, search *ResourceAdvancedComputerSearch) (*ResponseAdvancedComputerSearchCreatedAndUpdated, error) {
endpoint := fmt.Sprintf("%s/id/%d", uriAPIAdvancedComputerSearches, id)
requestBody := struct {
XMLName xml.Name `xml:"advanced_computer_search"`
*ResourceAdvancedComputerSearch
}{
ResourceAdvancedComputerSearch: search,
}
var updatedSearch ResponseAdvancedComputerSearchCreatedAndUpdated
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &updatedSearch)
if err != nil {
return nil, fmt.Errorf(errMsgFailedUpdateByID, "advance computer search", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &updatedSearch, nil
}
/*
Function: UpdateAdvancedComputerSearchByName
Method: PUT
Path: /JSSResource/advancedcomputersearches/name/{name}
Description: Updates an existing Jamf Pro advanced computer search resource by its name.
Parameters:
- name (string): The name of the advanced computer search.
- search (*ResourceAdvancedComputerSearch): The updated advanced computer search resource.
Returns: ResponseAdvancedComputerSearchCreatedAndUpdated - The ID of the updated advanced computer search resource.
Example:
updatedSearch := &jamfpro.ResourceAdvancedComputerSearch{
Name: "Updated Search",
// Other fields...
}
updated, err := client.UpdateAdvancedComputerSearchByName("SearchName", updatedSearch)
if err != nil {
log.Fatal(err)
}
fmt.Println(updated)
Errors: Returns an error if the request fails or if the resource cannot be updated.
*/
func (c *Client) UpdateAdvancedComputerSearchByName(name string, search *ResourceAdvancedComputerSearch) (*ResponseAdvancedComputerSearchCreatedAndUpdated, error) {
endpoint := fmt.Sprintf("%s/name/%s", uriAPIAdvancedComputerSearches, name)
requestBody := struct {
XMLName xml.Name `xml:"advanced_computer_search"`
*ResourceAdvancedComputerSearch
}{
ResourceAdvancedComputerSearch: search,
}
var updatedSearch ResponseAdvancedComputerSearchCreatedAndUpdated
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &updatedSearch)
if err != nil {
return nil, fmt.Errorf(errMsgFailedUpdateByName, "advance computer search", name, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &updatedSearch, nil
}
/*
Function: DeleteAdvancedComputerSearchByID
Method: DELETE
Path: /JSSResource/advancedcomputersearches/id/{id}
Description: Deletes an existing Jamf Pro advanced computer search resource by its ID.
Parameters:
- id (int): The ID of the advanced computer search.
Returns: None
Example:
err := client.DeleteAdvancedComputerSearchByID(123)
if err != nil {
log.Fatal(err)
}
Errors: Returns an error if the request fails or if the resource cannot be deleted.
*/
func (c *Client) DeleteAdvancedComputerSearchByID(id int) error {
endpoint := fmt.Sprintf("%s/id/%d", uriAPIAdvancedComputerSearches, id)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf(errMsgFailedDeleteByID, "advance computer search", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}
/*
Function: DeleteAdvancedComputerSearchByName
Method: DELETE
Path: /JSSResource/advancedcomputersearches/name/{name}
Description: Deletes an existing Jamf Pro advanced computer search resource by its name.
Parameters:
- name (string): The name of the advanced computer search.
Returns: None
Example:
err := client.DeleteAdvancedComputerSearchByName("SearchName")
if err != nil {
log.Fatal(err)
}
Errors: Returns an error if the request fails or if the resource cannot be deleted.
*/
func (c *Client) DeleteAdvancedComputerSearchByName(name string) error {
endpoint := fmt.Sprintf("%s/name/%s", uriAPIAdvancedComputerSearches, name)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf(errMsgFailedDeleteByName, "advance computer search", name, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}