-
Notifications
You must be signed in to change notification settings - Fork 5
/
jamfproapi_managed_software_updates.go
247 lines (193 loc) · 9.13 KB
/
jamfproapi_managed_software_updates.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
// jamfproapi_managed_software_updates.go
// Jamf Pro Api - Managed Software Updates (BETA)
// api reference: https://developer.jamf.com/jamf-pro/reference/get_v1-managed-software-updates-available-updates
// Jamf Pro API requires the structs to support a JSON data structure.
package jamfpro
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
const uriManagedSoftwareUpdates = "/api/v1/managed-software-updates"
// Structs
// List
type ResponseManagedSoftwareUpdateList struct {
AvailableUpdates ResourceAvailableUpdates `json:"availableUpdates"`
}
type ResponseManagedSoftwareUpdatePlanList struct {
TotalCount int `json:"totalCount"`
Results []ResourceManagedSoftwareUpdatePlanList `json:"results"`
}
type ResourceManagedSoftwareUpdatePlanList struct {
PlanUuid string `json:"planUuid,omitempty"`
Device ManagedSoftwareUpdatePlanListSubsetDevice `json:"device,omitempty"`
UpdateAction string `json:"updateAction,omitempty"`
VersionType string `json:"versionType,omitempty"`
SpecificVersion string `json:"specificVersion,omitempty"`
MaxDeferrals int `json:"maxDeferrals,omitempty"`
ForceInstallLocalDateTime string `json:"forceInstallLocalDateTime,omitempty"`
RecipeId string `json:"recipeId,omitempty"`
Status ManagedSoftwareUpdatePlanListSubsetStatus `json:"status,omitempty"`
}
type ManagedSoftwareUpdatePlanListSubsetDevice struct {
DeviceId string `json:"deviceId,omitempty"`
ObjectType string `json:"objectType,omitempty"`
Href string `json:"href,omitempty"`
}
type ManagedSoftwareUpdatePlanListSubsetStatus struct {
State string `json:"state,omitempty"`
ErrorReasons []string `json:"errorReasons"`
}
// Response
type ResponseManagedSoftwareUpdatePlanCreate struct {
Plans []ManagedSoftwareUpdatePlanCreateSubsetPlan `json:"plans"`
}
type ManagedSoftwareUpdatePlanCreateSubsetPlan struct {
Device ManagedSoftwareUpdatePlanCreateSubsetDevice `json:"device"`
PlanID string `json:"planId"`
Href string `json:"href"`
}
type ManagedSoftwareUpdatePlanCreateSubsetDevice struct {
DeviceID string `json:"deviceId"`
ObjectType string `json:"objectType"`
Href string `json:"href"`
}
type ResponseManagedSoftwareUpdateFeatureToggle struct {
Toggle bool `json:"toggle"`
ForceInstallLocalDateEnabled bool `json:"forceInstallLocalDateEnabled"`
DssEnabled bool `json:"dssEnabled"`
RecipeEnabled bool `json:"recipeEnabled"`
}
// Resource
type ResourceAvailableUpdates struct {
MacOS []string `json:"macOS"`
IOS []string `json:"iOS"`
}
// ResourceManagedSoftwareUpdatePlan represents the payload structure for creating a managed software update plan.
type ResourceManagedSoftwareUpdatePlan struct {
Devices []ManagedSoftwareUpdatePlanObject `json:"devices,omitempty"`
Group ManagedSoftwareUpdatePlanObject `json:"group,omitempty"`
Config ManagedSoftwareUpdatePlanConfig `json:"config,omitempty"`
}
// ManagedSoftwareUpdatePlanDevice defines the structure for device objects in the managed software update plan.
type ManagedSoftwareUpdatePlanObject struct {
ObjectType string `json:"objectType,omitempty"`
DeviceId string `json:"deviceId,omitempty"`
GroupId string `json:"groupId,omitempty"`
}
// ManagedSoftwareUpdatePlanConfig defines the configuration for a managed software update plan.
type ManagedSoftwareUpdatePlanConfig struct {
UpdateAction string `json:"updateAction,omitempty"`
VersionType string `json:"versionType,omitempty"`
SpecificVersion string `json:"specificVersion,omitempty"`
MaxDeferrals int `json:"maxDeferrals,omitempty"`
ForceInstallLocalDateTime string `json:"forceInstallLocalDateTime,omitempty"`
}
// ResourceManagedSoftwareUpdateFeatureToggle represents the payload for updating the feature toggle.
type ResourceManagedSoftwareUpdateFeatureToggle struct {
Toggle bool `json:"toggle"`
}
// CRUD
// GetManagedSoftwareUpdates retrieves a list of all available managed software updates
func (c *Client) GetManagedSoftwareUpdates() (*ResponseManagedSoftwareUpdateList, error) {
endpoint := fmt.Sprintf("%s/available-updates", uriManagedSoftwareUpdates)
var updateList ResponseManagedSoftwareUpdateList
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &updateList)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGet, "self service settings", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &updateList, nil
}
// GetManagedSoftwareUpdatePlans retrieves a list of all available managed software updates
func (c *Client) GetManagedSoftwareUpdatePlans(sort_filter string) (*ResponseManagedSoftwareUpdatePlanList, error) {
resp, err := c.DoPaginatedGet(
uriManagedSoftwareUpdates+"/plans",
standardPageSize,
startingPageNumber,
sort_filter,
)
if err != nil {
return nil, fmt.Errorf(errMsgFailedPaginatedGet, "managed software update plans", err)
}
var out ResponseManagedSoftwareUpdatePlanList
out.TotalCount = resp.Size
for _, value := range resp.Results {
var newObj ResourceManagedSoftwareUpdatePlanList
err := mapstructure.Decode(value, &newObj)
if err != nil {
return nil, fmt.Errorf(errMsgFailedMapstruct, "script", err)
}
out.Results = append(out.Results, newObj)
}
return &out, nil
}
// CreateManagedSoftwareUpdatePlanByDeviceID Creates Managed Software Update Plan by Device ID
func (c *Client) CreateManagedSoftwareUpdatePlanByDeviceID(plan *ResourceManagedSoftwareUpdatePlan) (*ResponseManagedSoftwareUpdatePlanCreate, error) {
endpoint := uriManagedSoftwareUpdates + "/plans"
var responseManagedSoftwareUpdatePlanCreate ResponseManagedSoftwareUpdatePlanCreate
resp, err := c.HTTP.DoRequest("POST", endpoint, plan, &responseManagedSoftwareUpdatePlanCreate)
if err != nil {
return nil, fmt.Errorf("failed to create managed software update plan: %v", err)
}
if resp != nil {
defer resp.Body.Close()
}
return &responseManagedSoftwareUpdatePlanCreate, nil
}
// GetManagedSoftwareUpdateFeatureToggle retrieves the current managed software update feature toggle settings
func (c *Client) GetManagedSoftwareUpdateFeatureToggle() (*ResourceManagedSoftwareUpdateFeatureToggle, error) {
endpoint := fmt.Sprintf("%s/plans/feature-toggle", uriManagedSoftwareUpdates)
var featureToggle ResourceManagedSoftwareUpdateFeatureToggle
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &featureToggle)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGet, "managed software update feature toggle", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &featureToggle, nil
}
// UpdateManagedSoftwareUpdateFeatureToggle updates the feature toggle for managed software updates.
func (c *Client) UpdateManagedSoftwareUpdateFeatureToggle(payload *ResourceManagedSoftwareUpdateFeatureToggle) (*ResponseManagedSoftwareUpdateFeatureToggle, error) {
endpoint := fmt.Sprintf("%s/plans/feature-toggle", uriManagedSoftwareUpdates)
// Define a variable to hold the response
var response ResponseManagedSoftwareUpdateFeatureToggle
// Perform the request and unmarshal the response
resp, err := c.HTTP.DoRequest("PUT", endpoint, payload, &response)
if err != nil {
return nil, fmt.Errorf("failed to update managed software update feature toggle: %v", err)
}
// Ensure the response body gets closed
if resp != nil {
defer resp.Body.Close()
}
return &response, nil
}
// CreateManagedSoftwareUpdatePlanByDeviceGroupID creates a managed software update plan by group ID
func (c *Client) CreateManagedSoftwareUpdatePlanByGroupID(plan *ResourceManagedSoftwareUpdatePlan) (*ResponseManagedSoftwareUpdatePlanCreate, error) {
endpoint := uriManagedSoftwareUpdates + "/plans/group"
var responseManagedSoftwareUpdatePlanCreate ResponseManagedSoftwareUpdatePlanCreate
resp, err := c.HTTP.DoRequest("POST", endpoint, plan, &responseManagedSoftwareUpdatePlanCreate)
if err != nil {
return nil, fmt.Errorf("failed to create managed software update plan: %v", err)
}
if resp != nil {
defer resp.Body.Close()
}
return &responseManagedSoftwareUpdatePlanCreate, nil
}
// GetManagedSoftwareUpdatePlansByGroupID retrieves managed software update plans for a specific group ID.
func (c *Client) GetManagedSoftwareUpdatePlansByGroupID(groupId string, groupType string) (*ResponseManagedSoftwareUpdatePlanList, error) {
endpoint := fmt.Sprintf("%s/plans/group/%s?group-type=%s", uriManagedSoftwareUpdates, groupId, groupType)
var responseManagedSoftwareUpdatePlanList ResponseManagedSoftwareUpdatePlanList
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &responseManagedSoftwareUpdatePlanList)
if err != nil {
return nil, fmt.Errorf("failed to get managed software update plans: %v", err)
}
if resp != nil {
defer resp.Body.Close()
}
return &responseManagedSoftwareUpdatePlanList, nil
}