From de3726baade5ee18281511cd790b915ff1fe89a2 Mon Sep 17 00:00:00 2001 From: Mosen Date: Tue, 28 Jun 2016 20:32:30 +1000 Subject: [PATCH] Fix several compilation errors regarding syntax. --- endpoint.go | 2 +- profile.go | 14 +++++++++----- service.go | 14 +++++++------- transport.go | 10 ++++++++-- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/endpoint.go b/endpoint.go index 5b62faec..ad57b658 100644 --- a/endpoint.go +++ b/endpoint.go @@ -18,6 +18,6 @@ func makeEnrollEndpoint(svc Service) endpoint.Endpoint { if err != nil { return mdmEnrollResponse{}, err } - return mdmEnrollResponse{profile} + return mdmEnrollResponse{profile}, nil } } diff --git a/profile.go b/profile.go index f1cdbe88..c309f768 100644 --- a/profile.go +++ b/profile.go @@ -33,19 +33,23 @@ type Profile struct { ConsentText map[string]string `json:"consent_text" db:"consent_text" plist:"omitempty"` } -func NewProfile() Profile { +func NewProfile() *Profile { + payloadUuid := uuid.NewV4() + return &Profile{ PayloadVersion: 1, PayloadType: "Configuration", - PayloadUUID: uuid.NewV4(), + PayloadUUID: payloadUuid.String(), } } -func NewPayload(identifier string) Payload { +func NewPayload(identifier string) *Payload { + payloadUuid := uuid.NewV4() + return &Payload{ PayloadVersion: 1, PayloadIdentifier: identifier, - PayloadUUID: uuid.NewV4(), + PayloadUUID: payloadUuid.String(), } } @@ -62,7 +66,7 @@ type SCEPPayload struct { // TODO: Actually this is one of those non-nested payloads that doesnt respect the PayloadContent key. type MDMPayload struct { - Payload + Payload Payload AccessRights int CheckInURL string CheckOutWhenRemoved bool diff --git a/service.go b/service.go index bd2073bf..4b54c170 100644 --- a/service.go +++ b/service.go @@ -1,12 +1,12 @@ package enroll type Service interface { - Enroll() (Profile, error) + Enroll() (*Profile, error) } func NewService() Service { - scepSubject := []string{ - []string{ + scepSubject := [][][]string{ + [][]string{ []string{"O", "MicroMDM"}, []string{"CN", "MDM Identity Certificate:UDID"}, }, @@ -25,7 +25,7 @@ type service struct { Topic string // APNS Topic for MDM notifications } -func (svc service) Enroll() (Profile, error) { +func (svc service) Enroll() (*Profile, error) { profile := NewProfile() profile.PayloadIdentifier = "com.github.micromdm.micromdm.mdm" profile.PayloadOrganization = "MicroMDM" @@ -48,7 +48,7 @@ func (svc service) Enroll() (Profile, error) { scepPayload.PayloadContent = scepContent mdmPayload := MDMPayload{ - Payload{ + Payload: Payload{ PayloadVersion: 1, PayloadType: "com.apple.mdm", PayloadDescription: "Enrolls with the MDM server", @@ -66,7 +66,7 @@ func (svc service) Enroll() (Profile, error) { caPayload.PayloadDisplayName = "Root certificate for MicroMDM" caPayload.PayloadDescription = "Installs the root CA certificate for MicroMDM" - append(profile.PayloadContent, scepPayload, mdmPayload, caPayload) + profile.PayloadContent = []interface{}{scepPayload, mdmPayload, caPayload} - return profile + return profile, nil } diff --git a/transport.go b/transport.go index 2abb7bf0..23eed120 100644 --- a/transport.go +++ b/transport.go @@ -8,6 +8,7 @@ import ( kitlog "github.com/go-kit/kit/log" kithttp "github.com/go-kit/kit/transport/http" "github.com/gorilla/mux" + "github.com/groob/plist" ) // ServiceHandler returns an HTTP Handler for the enroll service @@ -36,8 +37,13 @@ func decodeMDMEnrollRequest(_ context.Context, r *http.Request) (interface{}, er func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { resp := response.(mdmEnrollResponse) - if len(resp) != 0 { - w.Write(resp) + plistData, err := plist.Marshal(resp) + if err != nil { + return err + } + + if len(plistData) != 0 { + w.Write(plistData) } return nil }