/
blueprint.go
65 lines (58 loc) · 2.37 KB
/
blueprint.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
package blueprint
import (
"errors"
"github.com/gogo/protobuf/proto"
"github.com/micromdm/micromdm/platform/blueprint/internal/blueprintproto"
)
// ApplyAt is a case-insensitive string that specifies at which point the
// system should apply a Blueprint to devices. For example if a Blueprint has
// an ApplyAt of "Enroll" then that profile will be applied immediately after
// a device's enrollment in the MDM system. Currently "Enroll" is the only
// supported value but more are planned.
const (
ApplyAtEnroll string = "Enroll"
)
type Blueprint struct {
UUID string `json:"uuid"`
Name string `json:"name"`
ApplicationURLs []string `json:"install_application_manifest_urls"`
ProfileIdentifiers []string `json:"profile_ids"`
UserUUID []string `json:"user_uuids"`
SkipPrimarySetupAccountCreation bool `json:"skip_primary_setup_account_creation"`
SetPrimarySetupAccountAsRegularUser bool `json:"set_primary_setup_account_as_regular_user"`
ApplyAt []string `json:"apply_at"`
}
func (bp *Blueprint) Verify() error {
if bp.Name == "" || bp.UUID == "" {
return errors.New("Blueprint must have Name and UUID")
}
return nil
}
func MarshalBlueprint(bp *Blueprint) ([]byte, error) {
protobp := blueprintproto.Blueprint{
Uuid: bp.UUID,
Name: bp.Name,
ManifestUrls: bp.ApplicationURLs,
ProfileIds: bp.ProfileIdentifiers,
UserUuid: bp.UserUUID,
SkipPrimarySetupAccountCreation: bp.SkipPrimarySetupAccountCreation,
SetPrimarySetupAccountAsRegularUser: bp.SetPrimarySetupAccountAsRegularUser,
ApplyAt: bp.ApplyAt,
}
return proto.Marshal(&protobp)
}
func UnmarshalBlueprint(data []byte, bp *Blueprint) error {
var pb blueprintproto.Blueprint
if err := proto.Unmarshal(data, &pb); err != nil {
return err
}
bp.UUID = pb.GetUuid()
bp.Name = pb.GetName()
bp.ApplicationURLs = pb.GetManifestUrls()
bp.ProfileIdentifiers = pb.GetProfileIds()
bp.ApplyAt = pb.GetApplyAt()
bp.UserUUID = pb.GetUserUuid()
bp.SkipPrimarySetupAccountCreation = pb.GetSkipPrimarySetupAccountCreation()
bp.SetPrimarySetupAccountAsRegularUser = pb.GetSetPrimarySetupAccountAsRegularUser()
return nil
}