-
Notifications
You must be signed in to change notification settings - Fork 5
/
jamfproapi_self_service_branding_macos.go
181 lines (141 loc) · 5.97 KB
/
jamfproapi_self_service_branding_macos.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
// jamfproapi_self_service_branding_macos.go
// Jamf Pro Api - Self Service Branding macOS
// api reference: https://developer.jamf.com/jamf-pro/reference/get_v1-self-service-branding-macos
// Jamf Pro Api requires the structs to support an JSON data structure.
package jamfpro
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
const uriSelfServiceBrandingMacOS = "/api/v1/self-service/branding/macos"
// Response
// ResponseSelfServiceBranding is the structure that holds the list of self-service branding configurations for macOS.
type ResponseSelfServiceBrandingList struct {
TotalCount int `json:"totalCount"`
Results []ResourceSelfServiceBrandingDetail `json:"results"`
}
// Resource
// SelfServiceBrandingDetail represents the details of a self-service branding configuration.
type ResourceSelfServiceBrandingDetail struct {
ID string `json:"id"`
ApplicationName string `json:"applicationName"`
BrandingName string `json:"brandingName"`
BrandingNameSecondary string `json:"brandingNameSecondary"`
IconId int `json:"iconId"`
BrandingHeaderImageId int `json:"brandingHeaderImageId"`
}
// CRUD
// GetSelfServiceBrandingMacOS retrieves the list of self-service branding configurations for macOS.
func (c *Client) GetSelfServiceBrandingMacOS(sort_filter string) (*ResponseSelfServiceBrandingList, error) {
resp, err := c.DoPaginatedGet(
uriSelfServiceBrandingMacOS,
standardPageSize,
startingPageNumber,
sort_filter,
)
if err != nil {
return nil, fmt.Errorf(errMsgFailedPaginatedGet, "self service branding", err)
}
var out ResponseSelfServiceBrandingList
out.TotalCount = resp.Size
for _, value := range resp.Results {
var newObj ResourceSelfServiceBrandingDetail
err := mapstructure.Decode(value, &newObj)
if err != nil {
return nil, fmt.Errorf(errMsgFailedMapstruct, "self service branding", err)
}
out.Results = append(out.Results, newObj)
}
return &out, nil
}
// GetSelfServiceBrandingMacOSByID retrieves a specific self-service branding configuration for macOS by ID.
func (c *Client) GetSelfServiceBrandingMacOSByID(id string) (*ResourceSelfServiceBrandingDetail, error) {
var out ResourceSelfServiceBrandingDetail
endpoint := fmt.Sprintf("%s/%s", uriSelfServiceBrandingMacOS, id)
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &out)
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
if err != nil {
fmt.Printf(errMsgFailedGetByID, "self service branding", id, err)
return nil, err
}
return &out, nil
}
// GetSelfServiceBrandingMacOSByNameByID retrieves a specific self-service branding configuration for macOS by its name.
func (c *Client) GetSelfServiceBrandingMacOSByName(name string) (*ResourceSelfServiceBrandingDetail, error) {
all_ssbrandings, err := c.GetSelfServiceBrandingMacOS("")
if err != nil {
return nil, fmt.Errorf(errMsgFailedPaginatedGet, "self service brandings", err)
}
for _, value := range all_ssbrandings.Results {
if value.BrandingName == name {
return &value, nil
}
}
return nil, fmt.Errorf(errMsgFailedGetByName, "self service branding", name, errMsgNoName)
}
// CreateSelfServiceBrandingMacOS creates a new self-service branding configuration for macOS.
func (c *Client) CreateSelfServiceBrandingMacOS(branding *ResourceSelfServiceBrandingDetail) (*ResourceSelfServiceBrandingDetail, error) {
endpoint := uriSelfServiceBrandingMacOS
var response ResourceSelfServiceBrandingDetail
resp, err := c.HTTP.DoRequest("POST", endpoint, branding, &response)
if err != nil {
return nil, fmt.Errorf("failed to create self-service branding: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &response, nil
}
// UpdateSelfServiceBrandingMacOSByID updates an existing self-service branding configuration for macOS.
func (c *Client) UpdateSelfServiceBrandingMacOSByID(id string, brandingUpdate *ResourceSelfServiceBrandingDetail) (*ResourceSelfServiceBrandingDetail, error) {
endpoint := fmt.Sprintf("%s/%s", uriSelfServiceBrandingMacOS, id)
var response ResourceSelfServiceBrandingDetail
resp, err := c.HTTP.DoRequest("PUT", endpoint, brandingUpdate, &response)
if err != nil {
return nil, fmt.Errorf("failed to update self-service branding: %v", err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return &response, nil
}
// UpdateSelfServiceBrandingMacOSByName updates a self-service branding configuration for macOS by name.
func (c *Client) UpdateSelfServiceBrandingMacOSByName(name string, brandingUpdate *ResourceSelfServiceBrandingDetail) (*ResourceSelfServiceBrandingDetail, error) {
target, err := c.GetSelfServiceBrandingMacOSByName(name)
if err != nil {
return nil, fmt.Errorf(errMsgFailedGetByName, "self service branding", name, err)
}
target_id := target.ID
resp, err := c.UpdateSelfServiceBrandingMacOSByID(target_id, brandingUpdate)
if err != nil {
return nil, fmt.Errorf(errMsgFailedUpdateByName, "self service branding", name, err)
}
return resp, nil
}
// DeleteSelfServiceBrandingMacOSByID deletes a self-service branding configuration for macOS by ID.
func (c *Client) DeleteSelfServiceBrandingMacOSByID(id string) error {
endpoint := fmt.Sprintf("%s/%s", uriSelfServiceBrandingMacOS, id)
resp, err := c.HTTP.DoRequest("DELETE", endpoint, nil, nil)
if err != nil {
return fmt.Errorf(errMsgFailedDeleteByID, "self service branding", id, err)
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
return nil
}
// DeleteSelfServiceBrandingMacOSByName deletes a self-service branding configuration for macOS by name.
func (c *Client) DeleteSelfServiceBrandingMacOSByName(name string) error {
target, err := c.GetSelfServiceBrandingMacOSByName(name)
if err != nil {
return fmt.Errorf(errMsgFailedGetByName, "self service branding", name, err)
}
target_id := target.ID
err = c.DeleteSelfServiceBrandingMacOSByID(target_id)
if err != nil {
return fmt.Errorf(errMsgFailedDeleteByName, "self service branding", name, err)
}
return nil
}