mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-12 04:55:39 +08:00
Fix several compilation errors regarding syntax.
This commit is contained in:
@@ -18,6 +18,6 @@ func makeEnrollEndpoint(svc Service) endpoint.Endpoint {
|
||||
if err != nil {
|
||||
return mdmEnrollResponse{}, err
|
||||
}
|
||||
return mdmEnrollResponse{profile}
|
||||
return mdmEnrollResponse{profile}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
15
main.go
15
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)
|
||||
|
||||
Reference in New Issue
Block a user