-
Notifications
You must be signed in to change notification settings - Fork 5
/
classicapi_vpp_assignments.go
190 lines (146 loc) · 4.99 KB
/
classicapi_vpp_assignments.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
// classicapi_vpp_assignments.go
// Jamf Pro Classic Api - VPP Assignments
// api reference: https://developer.jamf.com/jamf-pro/reference/vppassignments
// Jamf Pro Classic Api requires the structs to support an XML data structure.
// classicapi_vpp_assignments.go
package jamfpro
import (
"encoding/xml"
"fmt"
)
const uriVPPAssignments = "/JSSResource/vppassignments"
// List
// Struct for the list of VPP assignments
type ResponseVPPAssignmentsList struct {
VPPAssignments []VPPAssignmentsListItem `xml:"vpp_assignment"`
}
type VPPAssignmentsListItem struct {
ID int `xml:"id"`
VPPAdminAccountID int `xml:"vpp_admin_account_id"`
Name string `xml:"name"`
}
// Resource
// Structs for the detailed VPP assignment response
type ResourceVPPAssignment struct {
General VPPAssignmentSubsetGeneral `xml:"general"`
IOSApps []VPPSubsetVPPApp `xml:"ios_apps>ios_app"`
MacApps []VPPSubsetVPPApp `xml:"mac_apps>mac_app"`
EBooks []VPPSubsetVPPApp `xml:"ebooks>ebook"`
Scope VPPAssignmentSubsetScope `xml:"scope"`
}
// Subsets & Containers
// General
type VPPAssignmentSubsetGeneral struct {
ID int `xml:"id"`
Name string `xml:"name"`
VPPAdminAccountID int `xml:"vpp_admin_account_id"`
VPPAdminAccountName string `xml:"vpp_admin_account_name"`
}
// Scope
type VPPAssignmentSubsetScope struct {
AllJSSUsers bool `xml:"all_jss_users"`
JSSUsers []VPPSubsetVPPUser `xml:"jss_users>user"`
JSSUserGroups []VPPSubsetVPPUserGroup `xml:"jss_user_groups>user_group"`
Limitations VPPAssignmentSubsetScopeLimitations `xml:"limitations"`
Exclusions VPPAssignmentSubsetScopeExclusions `xml:"exclusions"`
}
type VPPAssignmentSubsetScopeLimitations struct {
UserGroups []VPPSubsetVPPUserGroup `xml:"user_groups>user_group"`
}
type VPPAssignmentSubsetScopeExclusions struct {
JSSUsers []VPPSubsetVPPUser `xml:"jss_users>user"`
UserGroups []VPPSubsetVPPUserGroup `xml:"user_groups>user_group"`
JSSUserGroups []VPPSubsetVPPUserGroup `xml:"jss_user_groups>user_group"`
}
// Shared
type VPPSubsetVPPApp struct {
AdamID int `xml:"adam_id"`
Name string `xml:"name"`
}
// Struct for VPP user
type VPPSubsetVPPUser struct {
ID int `xml:"id"`
Name string `xml:"name"`
}
// Struct for VPP user group
type VPPSubsetVPPUserGroup struct {
ID int `xml:"id"`
Name string `xml:"name"`
}
// CRUD
// GetVPPAssignments fetches a list of VPP assignments
func (c *Client) GetVPPAssignments() (*ResponseVPPAssignmentsList, error) {
endpoint := uriVPPAssignments
var assignments ResponseVPPAssignmentsList
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &assignments)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGet, "vpp assignments", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &assignments, nil
}
// GetVPPAssignmentByID fetches a VPP assignment by its ID
func (c *Client) GetVPPAssignmentByID(id int) (*ResourceVPPAssignment, error) {
endpoint := fmt.Sprintf("%s/id/%d", uriVPPAssignments, id)
var assignment ResourceVPPAssignment
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &assignment)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByID, "vpp assignment", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &assignment, nil
}
// CreateVPPAssignment creates a new VPP assignment
func (c *Client) CreateVPPAssignment(assignment *ResourceVPPAssignment) error {
endpoint := fmt.Sprintf("%s/id/0", uriVPPAssignments)
requestBody := struct {
XMLName xml.Name `xml:"vpp_assignment"`
*ResourceVPPAssignment
}{
ResourceVPPAssignment: assignment,
}
var handleResponse struct{}
resp, err := c.HTTP.DoRequest("POST", endpoint, &requestBody, &handleResponse)
if err != nil {
return fmt.Errorf(errMsgFailedCreate, "vpp assignment", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}
// UpdateVPPAssignmentByID updates a VPP assignment by its ID
func (c *Client) UpdateVPPAssignmentByID(id int, assignment *ResourceVPPAssignment) error {
endpoint := fmt.Sprintf("%s/id/%d", uriVPPAssignments, id)
requestBody := struct {
XMLName xml.Name `xml:"vpp_assignment"`
*ResourceVPPAssignment
}{
ResourceVPPAssignment: assignment,
}
var handleResponse struct{}
resp, err := c.HTTP.DoRequest("PUT", endpoint, &requestBody, &handleResponse)
if err != nil {
return fmt.Errorf(errMsgFailedUpdateByID, "vpp assignment", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}
// DeleteVPPAssignmentByID deletes a VPP assignment by its ID
func (c *Client) DeleteVPPAssignmentByID(id int) error {
endpoint := fmt.Sprintf("%s/id/%d", uriVPPAssignments, id)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf(errMsgFailedDeleteByID, "vpp assignment", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}