From a68c3e00142f9acf5616bb78f958eb18b49d32e7 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. --- enroll/endpoint.go | 2 +- enroll/profile.go | 14 +++++++++----- enroll/service.go | 14 +++++++------- enroll/transport.go | 10 ++++++++-- main.go | 15 +++++++++------ 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/enroll/endpoint.go b/enroll/endpoint.go index 5b62faec..ad57b658 100644 --- a/enroll/endpoint.go +++ b/enroll/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/enroll/profile.go b/enroll/profile.go index f1cdbe88..c309f768 100644 --- a/enroll/profile.go +++ b/enroll/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/enroll/service.go b/enroll/service.go index bd2073bf..4b54c170 100644 --- a/enroll/service.go +++ b/enroll/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/enroll/transport.go b/enroll/transport.go index 2abb7bf0..23eed120 100644 --- a/enroll/transport.go +++ b/enroll/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 } diff --git a/main.go b/main.go index 69a9eecb..bc0ea823 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,8 @@ import ( "net/http" "os" + "database/sql" + "github.com/DavidHuie/gomigrate" "github.com/RobotsAndPencils/buford/certificate" "github.com/RobotsAndPencils/buford/push" "github.com/go-kit/kit/log" @@ -16,14 +18,13 @@ import ( "github.com/micromdm/micromdm/command" "github.com/micromdm/micromdm/connect" "github.com/micromdm/micromdm/device" + "github.com/micromdm/micromdm/enroll" "github.com/micromdm/micromdm/management" "github.com/micromdm/micromdm/workflow" stdprometheus "github.com/prometheus/client_golang/prometheus" - "golang.org/x/net/context" "github.com/rs/cors" - "github.com/DavidHuie/gomigrate" + "golang.org/x/net/context" "time" - "database/sql" ) var ( @@ -187,12 +188,14 @@ func main() { commandSvc := command.NewService(commandDB) checkinSvc := checkin.NewService(deviceDB, mgmtSvc, commandSvc, enrollmentProfile) connectSvc := connect.NewService(deviceDB, commandSvc) + enrollSvc := enroll.NewService() httpLogger := log.NewContext(logger).With("component", "http") managementHandler := management.ServiceHandler(ctx, mgmtSvc, httpLogger) commandHandler := command.ServiceHandler(ctx, commandSvc, httpLogger) checkinHandler := checkin.ServiceHandler(ctx, checkinSvc, httpLogger) connectHandler := connect.ServiceHandler(ctx, connectSvc, httpLogger) + enrollHandler := enroll.ServiceHandler(ctx, enrollSvc, httpLogger) mux := http.NewServeMux() @@ -201,13 +204,15 @@ func main() { mux.Handle("/mdm/commands/", commandHandler) mux.Handle("/mdm/checkin", checkinHandler) mux.Handle("/mdm/connect", connectHandler) + mux.Handle("/mdm/enroll", enrollHandler) + if *flPkgRepo != "" { mux.Handle("/repo/", http.StripPrefix("/repo/", http.FileServer(http.Dir(*flPkgRepo)))) } if *flCorsOrigin != "" { c := cors.New(cors.Options{ - AllowedOrigins: []string{*flCorsOrigin}, + AllowedOrigins: []string{*flCorsOrigin}, AllowCredentials: true, }) @@ -217,8 +222,6 @@ func main() { http.Handle("/", mux) } - - http.Handle("/metrics", stdprometheus.Handler()) serve(logger, *flTLS, *flPort, *flTLSKey, *flTLSCert)