-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathtype.go
95 lines (86 loc) · 2.1 KB
/
type.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
package mdm
import (
"errors"
"strconv"
)
// Shared iPad users have a static UserID that they connect to MDM with.
// In this case the MDM spec says to fallback to the UserShortName
// which should contain the managed AppleID.
const SharediPadUserID = "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"
// EnrollType identifies the type of enrollment.
type EnrollType uint
const (
Device = 1 + iota
User
UserEnrollmentDevice
UserEnrollment
SharediPad
maxEnrollType
)
// Valid tests the validity of the enrollment type
func (et EnrollType) Valid() bool {
return et > 0 && et < maxEnrollType
}
func (et EnrollType) String() string {
switch et {
case Device:
return "Device"
case User:
return "User"
case UserEnrollmentDevice:
return "User Enrollment (Device)"
case UserEnrollment:
return "User Enrollment"
case SharediPad:
return "Shared iPad"
default:
return "unknown enroll type value " + strconv.Itoa(int(et))
}
}
// ResolvedEnrollment is a sort of collapsed form of Enrollment.
type ResolvedEnrollment struct {
Type EnrollType
DeviceChannelID string
UserChannelID string
IsUserChannel bool
}
func (resolved *ResolvedEnrollment) Validate() error {
if resolved == nil {
return errors.New("nil resolved enrollment")
}
if resolved.DeviceChannelID == "" {
return errors.New("empty device channel id")
}
if !resolved.Type.Valid() {
return errors.New("invalid resolved type")
}
return nil
}
// Resolved assembles a ResolvedEnrollment from an Enrollment
func (e *Enrollment) Resolved() (r *ResolvedEnrollment) {
if e.UDID != "" {
r = new(ResolvedEnrollment)
r.Type = Device
r.DeviceChannelID = e.UDID
if e.UserID != "" {
r.IsUserChannel = true
if e.UserID == SharediPadUserID {
r.Type = SharediPad
r.UserChannelID = e.UserShortName
} else {
r.Type = User
r.UserChannelID = e.UserID
}
}
} else if e.EnrollmentID != "" {
r = new(ResolvedEnrollment)
r.Type = UserEnrollmentDevice
r.DeviceChannelID = e.EnrollmentID
if e.EnrollmentUserID != "" {
r.IsUserChannel = true
r.Type = UserEnrollment
r.UserChannelID = e.EnrollmentUserID
}
}
return
}