forked from deploymenttheory/go-api-sdk-jamfpro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enrollmentCustomizations.go
83 lines (67 loc) · 2.65 KB
/
enrollmentCustomizations.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
package jamfpro
import (
"fmt"
)
const uriEnrollmentCustomizations = "/api/v2/enrollment-customizations"
type ResponseEnrollmentCustomization struct {
TotalCount int `json:"totalCount"`
Results []EnrollmentCustomization `json:"results"`
}
type EnrollmentCustomization struct {
ID string `json:"id"`
SiteId string `json:"siteId"`
DisplayName string `json:"displayName"`
Description string `json:"description"`
EnrollmentCustomizationBrandingSettings EnrollmentCustomizationDataSubsetBrandingSettings `json:"enrollmentCustomizationBrandingSettings"`
}
type EnrollmentCustomizationDataSubsetBrandingSettings struct {
TextColor string `json:"textColor"`
ButtonColor string `json:"buttonColor"`
ButtonTextColor string `json:"buttonTextColor"`
BackgroundColor string `json:"backgroundColor"`
IconUrl string `json:"iconUrl"`
}
func (c *Client) GetEnrollmentCustomizationIdByName(name string) (string, error) {
var id string
customizations, err := c.GetEnrollmentCustomizations()
if err != nil {
return "", err
}
for _, v := range customizations.Results {
if v.DisplayName == name {
id = v.ID
break
}
}
return id, err
}
func (c *Client) GetEnrollmentCustomizationByName(name string) (*EnrollmentCustomization, error) {
allCustomizationsResponse, err := c.GetEnrollmentCustomizations()
if err != nil {
return nil, err
}
for _, customization := range allCustomizationsResponse.Results {
if customization.DisplayName == name {
return &customization, nil
}
}
return nil, fmt.Errorf("enrollment customization with name '%s' not found", name)
}
func (c *Client) GetEnrollmentCustomizations() (*ResponseEnrollmentCustomization, error) {
uri := fmt.Sprintf("%s?page=0&page-size=100&sort=id%%3Aasc", uriEnrollmentCustomizations)
var out ResponseEnrollmentCustomization
err := c.DoRequest("GET", uri, nil, nil, &out)
if err != nil {
return nil, fmt.Errorf("failed to get enrollment customizations: %v", err)
}
return &out, nil
}
func (c *Client) GetEnrollmentCustomizationByID(customizationID string) (*EnrollmentCustomization, error) {
uri := fmt.Sprintf("%s/%s", uriEnrollmentCustomizations, customizationID)
var out EnrollmentCustomization
err := c.DoRequest("GET", uri, nil, nil, &out)
if err != nil {
return nil, fmt.Errorf("failed to get enrollment customization by ID: %v", err)
}
return &out, nil
}