-
Notifications
You must be signed in to change notification settings - Fork 5
/
jamfproapi_patch_policies.go
75 lines (60 loc) · 2.17 KB
/
jamfproapi_patch_policies.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
// jamfproapi_patch_policies.go
// Jamf Pro Api - Patch Policies On Dashboard
// api reference: https://developer.jamf.com/jamf-pro/reference/get_v2-patch-policies
// Jamf Pro Api requires the structs to support an JSON data structure.
package jamfpro
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
const uriPatchPoliciesJamfProAPI = "/api/v2/patch-policies"
// List
// Struct for paginated response for patch policies
type ResponsePatchPoliciesList struct {
Size int `json:"totalCount"`
Results []ResourcePatchPolicy `json:"results"`
}
// Response
// Response struct for creating a patch policy
type ResponsePatchPolicyCreate struct {
ID string `json:"id"`
Href string `json:"href"`
}
// Resource
// Resource struct representing a Patch Policy object from Pro API
type ResourcePatchPolicy struct {
ID string `json:"id"`
PolicyName string `json:"policyName"`
PolicyEnabled bool `json:"policyEnabled"`
PolicyTargetVersion string `json:"policyTargetVersion"`
PolicyDeploymentMethod string `json:"policyDeploymentMethod"`
SoftwareTitle string `json:"softwareTitle"`
SoftwareTitleConfigurationId string `json:"softwareTitleConfigurationId"`
Pending int `json:"pending"`
Completed int `json:"completed"`
Deferred int `json:"deferred"`
Failed int `json:"failed"`
}
// Gets full list of patch policies & handles pagination
func (c *Client) GetPatchPolicies(sortFilter string) (*ResponsePatchPoliciesList, error) {
resp, err := c.DoPaginatedGet(
uriPatchPoliciesJamfProAPI+"/policy-details",
standardPageSize,
startingPageNumber,
sortFilter,
)
if err != nil {
return nil, fmt.Errorf(errMsgFailedPaginatedGet, "patch policies", err)
}
var out ResponsePatchPoliciesList
out.Size = resp.Size
for _, value := range resp.Results {
var newObj ResourcePatchPolicy
err := mapstructure.Decode(value, &newObj)
if err != nil {
return nil, fmt.Errorf(errMsgFailedMapstruct, "patch policy", err)
}
out.Results = append(out.Results, newObj)
}
return &out, nil
}