Fix several compilation errors regarding syntax.

This commit is contained in:
Mosen
2016-06-28 20:32:30 +10:00
committed by Victor Vrantchan
parent d1718b85de
commit de3726baad
4 changed files with 25 additions and 15 deletions

View File

@@ -18,6 +18,6 @@ func makeEnrollEndpoint(svc Service) endpoint.Endpoint {
if err != nil {
return mdmEnrollResponse{}, err
}
return mdmEnrollResponse{profile}
return mdmEnrollResponse{profile}, nil
}
}

View File

@@ -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

View File

@@ -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
}

View File

@@ -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
}