This repository has been archived by the owner on Sep 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
profile.go
94 lines (86 loc) · 3.1 KB
/
profile.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
package dep
const (
defineProfilePath = "profile"
assignProfilePath = "profile/devices"
)
// ProfileService allows Defining, Assigning and Fetching profiles from DEP
type ProfileService interface {
DefineProfile(profile *Profile) (*ProfileResponse, error)
AssignProfile(profileUUID string, devices []string) (*ProfileResponse, error)
FetchProfile(profileUUID string) (*Profile, error)
}
type profileService struct {
client *depClient
}
// Profile is a DEP setup profile.
// The profile can be defined, assigned and fetched.
type Profile struct {
ProfileName string `json:"profile_name"`
URL string `json:"url"`
AllowPairing bool `json:"allow_pairing,omitempty"`
IsSupervised bool `json:"is_supervised,omitempty"`
IsMultiUser bool `json:"is_multi_user,omitempty"`
IsMandatory bool `json:"is_mandatory,omitempty"`
AwaitDeviceConfigured bool `json:"await_device_configured,omitempty"`
IsMDMRemovable bool `json:"is_mdm_removable"`
SupportPhoneNumber string `json:"support_phone_number,omitempty"`
AutoAdvanceSetup bool `json:"auto_advance_setup,omitempty"`
SupportEmailAddress string `json:"support_email_address,omitempty"`
OrgMagic string `json:"org_magic"`
AnchorCerts []string `json:"anchor_certs,omitempty"`
SupervisingHostCerts []string `json:"supervising_host_certs,omitempty"`
SkipSetupItems []string `json:"skip_setup_items,omitempty"`
Department string `json:"department,omitempty"`
Devices []string `json:"devices"`
}
// ProfileResponse is the response body for Define Profile
type ProfileResponse struct {
ProfileUUID string `json:"profile_uuid"`
Devices map[string]string `json:"devices"`
}
// DefineProfile is a Define Profile request to DEP
func (s profileService) DefineProfile(request *Profile) (*ProfileResponse, error) {
var response ProfileResponse
req, err := s.client.NewRequest("POST", defineProfilePath, request)
if err != nil {
return nil, err
}
err = s.client.Do(req, &response)
if err != nil {
return nil, err
}
return &response, nil
}
// AssignProfile is an assign profile request to DEP
func (s profileService) AssignProfile(profileUUID string, devices []string) (*ProfileResponse, error) {
var response ProfileResponse
var request = struct {
ProfileUUID string `json:"profile_uuid"`
Devices []string `json:"devices"`
}{profileUUID, devices}
req, err := s.client.NewRequest("PUT", assignProfilePath, request)
if err != nil {
return nil, err
}
err = s.client.Do(req, &response)
if err != nil {
return nil, err
}
return &response, nil
}
// FetchProfile is a Fetch Profile request to DEP
func (s profileService) FetchProfile(profileUUID string) (*Profile, error) {
var response Profile
req, err := s.client.NewRequest("GET", defineProfilePath, nil)
if err != nil {
return nil, err
}
query := req.URL.Query()
query.Add("profile_uuid", profileUUID)
req.URL.RawQuery = query.Encode()
err = s.client.Do(req, &response)
if err != nil {
return nil, err
}
return &response, nil
}