mirror of
https://github.com/micromdm/micromdm/
synced 2026-05-14 18:55:38 +08:00
only register HTTP routes once (#418)
Simplified the registration of HTTP routes. Moved basic auth middleware to use the provided go-kit library.
This commit is contained in:
@@ -22,11 +22,11 @@ import (
|
||||
"github.com/RobotsAndPencils/buford/push"
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/fullsailor/pkcs7"
|
||||
"github.com/go-kit/kit/auth/basic"
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
"github.com/go-kit/kit/log"
|
||||
"github.com/go-kit/kit/log/level"
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/groob/finalizer/logutil"
|
||||
"github.com/micromdm/dep"
|
||||
"github.com/micromdm/go4/env"
|
||||
@@ -43,6 +43,7 @@ import (
|
||||
"github.com/micromdm/micromdm/mdm/connect"
|
||||
"github.com/micromdm/micromdm/mdm/enroll"
|
||||
"github.com/micromdm/micromdm/pkg/crypto"
|
||||
httputil2 "github.com/micromdm/micromdm/pkg/httputil"
|
||||
"github.com/micromdm/micromdm/platform/apns"
|
||||
apnsbuiltin "github.com/micromdm/micromdm/platform/apns/builtin"
|
||||
"github.com/micromdm/micromdm/platform/appstore"
|
||||
@@ -223,8 +224,6 @@ func serve(args []string) error {
|
||||
checkinHandlers = checkin.MakeHTTPHandlers(ctx, e, opts...)
|
||||
}
|
||||
|
||||
commandEndpoints := command.MakeServerEndpoints(sm.commandService)
|
||||
|
||||
connectOpts := []httptransport.ServerOption{
|
||||
httptransport.ServerErrorLogger(httpLogger),
|
||||
httptransport.ServerErrorEncoder(connect.EncodeError),
|
||||
@@ -246,59 +245,41 @@ func serve(args []string) error {
|
||||
profilesvc = profile.New(sm.profileDB)
|
||||
}
|
||||
|
||||
profileEndpoints := profile.MakeServerEndpoints(profilesvc)
|
||||
|
||||
var blueprintsvc blueprint.Service
|
||||
{
|
||||
blueprintsvc = blueprint.New(bpDB)
|
||||
}
|
||||
|
||||
blueprintEndpoints := blueprint.MakeServerEndpoints(blueprintsvc)
|
||||
blockEndpoints := block.MakeServerEndpoints(removeService)
|
||||
|
||||
var usersvc user.Service
|
||||
{
|
||||
usersvc = user.New(userDB)
|
||||
}
|
||||
|
||||
userEndpoints := user.MakeServerEndpoints(usersvc)
|
||||
|
||||
var configsvc config.Service
|
||||
{
|
||||
configsvc = config.New(sm.configDB)
|
||||
}
|
||||
|
||||
configEndpoints := config.MakeServerEndpoints(configsvc)
|
||||
|
||||
var appsvc appstore.Service
|
||||
{
|
||||
appsvc = appstore.New(appDB)
|
||||
}
|
||||
|
||||
appEndpoints := appstore.MakeServerEndpoints(appsvc)
|
||||
|
||||
var devicesvc device.Service
|
||||
{
|
||||
devicesvc = device.New(devDB)
|
||||
}
|
||||
deviceEndpoints := device.MakeServerEndpoints(devicesvc)
|
||||
|
||||
var depsvc depapi.Service
|
||||
{
|
||||
depsvc = depapi.New(dc, sm.pubclient)
|
||||
}
|
||||
depEndpoints := depapi.MakeServerEndpoints(depsvc)
|
||||
|
||||
apnsEndpoints := apns.MakeServerEndpoints(sm.pushService)
|
||||
|
||||
connectHandlers := connect.MakeHTTPHandlers(ctx, connectEndpoints, connectOpts...)
|
||||
|
||||
scepHandler := scep.ServiceHandler(ctx, sm.scepService, httpLogger)
|
||||
enrollHandlers := enroll.MakeHTTPHandlers(ctx, enroll.MakeServerEndpoints(sm.enrollService, sm.scepDepot), httptransport.ServerErrorLogger(httpLogger))
|
||||
|
||||
depsyncEndpoints := depsync.MakeServerEndpoints(depsync.NewService(syncer))
|
||||
|
||||
r := mux.NewRouter()
|
||||
r, options := httputil2.NewRouter(logger)
|
||||
r.Handle("/version", version.Handler())
|
||||
r.Handle("/mdm/checkin", mdmAuthSignMessageMiddleware(sm.scepDepot, checkinHandlers.CheckinHandler)).Methods("PUT")
|
||||
r.Handle("/mdm/connect", mdmAuthSignMessageMiddleware(sm.scepDepot, connectHandlers.ConnectHandler)).Methods("PUT")
|
||||
@@ -310,37 +291,42 @@ func serve(args []string) error {
|
||||
io.WriteString(w, homePage)
|
||||
})
|
||||
|
||||
profilesHandler := profile.MakeHTTPHandler(profileEndpoints, logger)
|
||||
blueprintsHandler := blueprint.MakeHTTPHandler(blueprintEndpoints, logger)
|
||||
blockhandler := block.MakeHTTPHandler(blockEndpoints, logger)
|
||||
userHandler := user.MakeHTTPHandler(userEndpoints, logger)
|
||||
configHandler := config.MakeHTTPHandler(configEndpoints, logger)
|
||||
appsHandler := appstore.MakeHTTPHandler(appEndpoints, logger)
|
||||
deviceHandler := device.MakeHTTPHandler(deviceEndpoints, logger)
|
||||
depHandlers := depapi.MakeHTTPHandler(depEndpoints, logger)
|
||||
apnsHandlers := apns.MakeHTTPHandler(apnsEndpoints, logger)
|
||||
depsyncHandlers := depsync.MakeHTTPHandler(depsyncEndpoints, logger)
|
||||
commandHandler := command.MakeHTTPHandler(commandEndpoints, logger)
|
||||
|
||||
// API commands. Only handled if the user provides an api key.
|
||||
if *flAPIKey != "" {
|
||||
r.Handle("/v1/profiles", apiAuthMiddleware(*flAPIKey, profilesHandler))
|
||||
r.Handle("/v1/blueprints", apiAuthMiddleware(*flAPIKey, blueprintsHandler))
|
||||
r.Handle("/v1/users", apiAuthMiddleware(*flAPIKey, userHandler))
|
||||
r.Handle("/v1/apps", apiAuthMiddleware(*flAPIKey, appsHandler))
|
||||
r.Handle("/v1/devices/{udid}/block", apiAuthMiddleware(*flAPIKey, blockhandler))
|
||||
r.Handle("/v1/devices/{udid}/unblock", apiAuthMiddleware(*flAPIKey, blockhandler))
|
||||
r.Handle("/v1/devices", apiAuthMiddleware(*flAPIKey, deviceHandler))
|
||||
r.Handle("/v1/dep-tokens", apiAuthMiddleware(*flAPIKey, configHandler))
|
||||
r.Handle("/v1/dep-tokens", apiAuthMiddleware(*flAPIKey, configHandler))
|
||||
r.Handle("/v1/config/certificate", apiAuthMiddleware(*flAPIKey, configHandler))
|
||||
r.Handle("/v1/dep/devices", apiAuthMiddleware(*flAPIKey, depHandlers))
|
||||
r.Handle("/v1/dep/account", apiAuthMiddleware(*flAPIKey, depHandlers))
|
||||
r.Handle("/v1/dep/profiles", apiAuthMiddleware(*flAPIKey, depHandlers))
|
||||
r.Handle("/v1/dep/syncnow", apiAuthMiddleware(*flAPIKey, depsyncHandlers))
|
||||
r.Handle("/v1/dep/autoassigners", apiAuthMiddleware(*flAPIKey, depsyncHandlers))
|
||||
r.Handle("/v1/commands", apiAuthMiddleware(*flAPIKey, commandHandler))
|
||||
r.Handle("/push/{udid}", apiAuthMiddleware(*flAPIKey, apnsHandlers))
|
||||
basicAuthEndpointMiddleware := basic.AuthMiddleware("micromdm", *flAPIKey, "micromdm")
|
||||
|
||||
configEndpoints := config.MakeServerEndpoints(configsvc, basicAuthEndpointMiddleware)
|
||||
config.RegisterHTTPHandlers(r, configEndpoints, options...)
|
||||
|
||||
apnsEndpoints := apns.MakeServerEndpoints(sm.pushService, basicAuthEndpointMiddleware)
|
||||
apns.RegisterHTTPHandlers(r, apnsEndpoints, options...)
|
||||
|
||||
deviceEndpoints := device.MakeServerEndpoints(devicesvc, basicAuthEndpointMiddleware)
|
||||
device.RegisterHTTPHandlers(r, deviceEndpoints, options...)
|
||||
|
||||
profileEndpoints := profile.MakeServerEndpoints(profilesvc, basicAuthEndpointMiddleware)
|
||||
profile.RegisterHTTPHandlers(r, profileEndpoints, options...)
|
||||
|
||||
blueprintEndpoints := blueprint.MakeServerEndpoints(blueprintsvc, basicAuthEndpointMiddleware)
|
||||
blueprint.RegisterHTTPHandlers(r, blueprintEndpoints, options...)
|
||||
|
||||
blockEndpoints := block.MakeServerEndpoints(removeService, basicAuthEndpointMiddleware)
|
||||
block.RegisterHTTPHandlers(r, blockEndpoints, options...)
|
||||
|
||||
userEndpoints := user.MakeServerEndpoints(usersvc, basicAuthEndpointMiddleware)
|
||||
user.RegisterHTTPHandlers(r, userEndpoints, options...)
|
||||
|
||||
appEndpoints := appstore.MakeServerEndpoints(appsvc, basicAuthEndpointMiddleware)
|
||||
appstore.RegisterHTTPHandlers(r, appEndpoints, options...)
|
||||
|
||||
commandEndpoints := command.MakeServerEndpoints(sm.commandService, basicAuthEndpointMiddleware)
|
||||
command.RegisterHTTPHandlers(r, commandEndpoints, options...)
|
||||
|
||||
depEndpoints := depapi.MakeServerEndpoints(depsvc, basicAuthEndpointMiddleware)
|
||||
depapi.RegisterHTTPHandlers(r, depEndpoints, options...)
|
||||
|
||||
depsyncEndpoints := depsync.MakeServerEndpoints(depsync.NewService(syncer), basicAuthEndpointMiddleware)
|
||||
depsync.RegisterHTTPHandlers(r, depsyncEndpoints, options...)
|
||||
} else {
|
||||
mainLogger.Log("msg", "no api key specified")
|
||||
}
|
||||
@@ -895,20 +881,6 @@ func mdmAuthSignMessageMiddleware(db *boltdepot.Depot, next http.Handler) http.H
|
||||
}
|
||||
}
|
||||
|
||||
func apiAuthMiddleware(token string, next http.Handler) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
_, password, ok := r.BasicAuth()
|
||||
if !ok || password != token {
|
||||
w.Header().Set("WWW-Authenticate", `Basic realm="micromdm"`)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
w.Write([]byte(`{"error": "you need to log in"}`))
|
||||
return
|
||||
}
|
||||
next.ServeHTTP(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
// implement HasCN function that belongs in micromdm/scep/depot/bolt
|
||||
// note: added bool return, different from micromdm/scep interface
|
||||
func HasCN(db *boltdepot.Depot, cn string, allowTime int, cert *x509.Certificate, revokeOldCertificate bool) (bool, error) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package depsync
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
"github.com/go-kit/kit/log"
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
@@ -20,18 +19,16 @@ type Endpoints struct {
|
||||
RemoveAutoAssignerEndpoint endpoint.Endpoint
|
||||
}
|
||||
|
||||
func MakeServerEndpoints(s Service) Endpoints {
|
||||
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
|
||||
return Endpoints{
|
||||
SyncNowEndpoint: MakeSyncNowEndpoint(s),
|
||||
ApplyAutoAssignerEndpoint: MakeApplyAutoAssignerEndpoint(s),
|
||||
GetAutoAssignersEndpoint: MakeGetAutoAssignersEndpoint(s),
|
||||
RemoveAutoAssignerEndpoint: MakeRemoveAutoAssignerEndpoint(s),
|
||||
SyncNowEndpoint: endpoint.Chain(outer, others...)(MakeSyncNowEndpoint(s)),
|
||||
ApplyAutoAssignerEndpoint: endpoint.Chain(outer, others...)(MakeApplyAutoAssignerEndpoint(s)),
|
||||
GetAutoAssignersEndpoint: endpoint.Chain(outer, others...)(MakeGetAutoAssignersEndpoint(s)),
|
||||
RemoveAutoAssignerEndpoint: endpoint.Chain(outer, others...)(MakeRemoveAutoAssignerEndpoint(s)),
|
||||
}
|
||||
}
|
||||
|
||||
func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
r, options := httputil.NewRouter(logger)
|
||||
|
||||
func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.ServerOption) {
|
||||
// POST /v1/dep/syncnow request a DEP sync operation to happen now
|
||||
// POST /v1/dep/autoassigners set a DEP auto-assigner
|
||||
// GET /v1/dep/autoassigners get list of DEP auto-assigners
|
||||
@@ -64,6 +61,4 @@ func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
httputil.EncodeJSONResponse,
|
||||
options...,
|
||||
))
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ func NewRouter(logger log.Logger) (*mux.Router, []httptransport.ServerOption) {
|
||||
options := []httptransport.ServerOption{
|
||||
httptransport.ServerErrorEncoder(ErrorEncoder),
|
||||
httptransport.ServerErrorLogger(logger),
|
||||
httptransport.ServerBefore(httptransport.PopulateRequestContext),
|
||||
}
|
||||
return r, options
|
||||
}
|
||||
@@ -28,12 +29,15 @@ func EncodeJSONResponse(ctx context.Context, w http.ResponseWriter, response int
|
||||
ErrorEncoder(ctx, f.Failed(), w)
|
||||
return nil
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
if headerer, ok := response.(httptransport.Headerer); ok {
|
||||
for k := range headerer.Headers() {
|
||||
w.Header().Set(k, headerer.Headers().Get(k))
|
||||
for k, values := range headerer.Headers() {
|
||||
for _, v := range values {
|
||||
w.Header().Add(k, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
code := http.StatusOK
|
||||
if sc, ok := response.(httptransport.StatusCoder); ok {
|
||||
code = sc.StatusCode()
|
||||
@@ -46,16 +50,18 @@ func EncodeJSONResponse(ctx context.Context, w http.ResponseWriter, response int
|
||||
}
|
||||
|
||||
func ErrorEncoder(_ context.Context, err error, w http.ResponseWriter) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
errMap := map[string]interface{}{"error": err.Error()}
|
||||
enc := json.NewEncoder(w)
|
||||
enc.SetIndent("", " ")
|
||||
|
||||
if headerer, ok := err.(httptransport.Headerer); ok {
|
||||
for k := range headerer.Headers() {
|
||||
w.Header().Set(k, headerer.Headers().Get(k))
|
||||
for k, values := range headerer.Headers() {
|
||||
for _, v := range values {
|
||||
w.Header().Add(k, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
code := http.StatusInternalServerError
|
||||
if sc, ok := err.(httptransport.StatusCoder); ok {
|
||||
|
||||
@@ -2,7 +2,6 @@ package apns
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
"github.com/go-kit/kit/log"
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
@@ -13,15 +12,13 @@ type Endpoints struct {
|
||||
PushEndpoint endpoint.Endpoint
|
||||
}
|
||||
|
||||
func MakeServerEndpoints(s Service) Endpoints {
|
||||
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
|
||||
return Endpoints{
|
||||
PushEndpoint: MakePushEndpoint(s),
|
||||
PushEndpoint: endpoint.Chain(outer, others...)(MakePushEndpoint(s)),
|
||||
}
|
||||
}
|
||||
|
||||
func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
r, options := httputil.NewRouter(logger)
|
||||
|
||||
func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.ServerOption) {
|
||||
// GET /push/:udid create an APNS Push notification for a managed device or user(deprecated)
|
||||
// POST /v1/push/:udid create an APNS Push notification for a managed device or user
|
||||
|
||||
@@ -38,6 +35,4 @@ func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
httputil.EncodeJSONResponse,
|
||||
options...,
|
||||
))
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package appstore
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
"github.com/go-kit/kit/log"
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
@@ -14,16 +13,14 @@ type Endpoints struct {
|
||||
ListAppsEndpoint endpoint.Endpoint
|
||||
}
|
||||
|
||||
func MakeServerEndpoints(s Service) Endpoints {
|
||||
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
|
||||
return Endpoints{
|
||||
AppUploadEndpoint: MakeUploadAppEndpiont(s),
|
||||
ListAppsEndpoint: MakeListAppsEndpoint(s),
|
||||
AppUploadEndpoint: endpoint.Chain(outer, others...)(MakeUploadAppEndpiont(s)),
|
||||
ListAppsEndpoint: endpoint.Chain(outer, others...)(MakeListAppsEndpoint(s)),
|
||||
}
|
||||
}
|
||||
|
||||
func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
r, options := httputil.NewRouter(logger)
|
||||
|
||||
func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.ServerOption) {
|
||||
// POST /v1/apps upload an app to the server
|
||||
// GET /v1/apps list apps managed by the server
|
||||
|
||||
@@ -40,6 +37,4 @@ func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
httputil.EncodeJSONResponse,
|
||||
options...,
|
||||
))
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package blueprint
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
"github.com/go-kit/kit/log"
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/micromdm/micromdm/pkg/httputil"
|
||||
@@ -14,17 +13,15 @@ type Endpoints struct {
|
||||
RemoveBlueprintsEndpoint endpoint.Endpoint
|
||||
}
|
||||
|
||||
func MakeServerEndpoints(s Service) Endpoints {
|
||||
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
|
||||
return Endpoints{
|
||||
GetBlueprintsEndpoint: MakeGetBlueprintsEndpoint(s),
|
||||
ApplyBlueprintEndpoint: MakeApplyBlueprintEndpoint(s),
|
||||
RemoveBlueprintsEndpoint: MakeRemoveBlueprintsEndpoint(s),
|
||||
GetBlueprintsEndpoint: endpoint.Chain(outer, others...)(MakeGetBlueprintsEndpoint(s)),
|
||||
ApplyBlueprintEndpoint: endpoint.Chain(outer, others...)(MakeApplyBlueprintEndpoint(s)),
|
||||
RemoveBlueprintsEndpoint: endpoint.Chain(outer, others...)(MakeRemoveBlueprintsEndpoint(s)),
|
||||
}
|
||||
}
|
||||
|
||||
func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
r, options := httputil.NewRouter(logger)
|
||||
|
||||
func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.ServerOption) {
|
||||
// PUT /v1/blueprints create or replace a blueprint on the server
|
||||
// GET /v1/blueprints get a list of blueprints managed by the server
|
||||
// DELETE /v1/blueprints remove one or more blueprints from the server
|
||||
@@ -49,6 +46,4 @@ func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
httputil.EncodeJSONResponse,
|
||||
options...,
|
||||
))
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package command
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
"github.com/go-kit/kit/log"
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/micromdm/micromdm/pkg/httputil"
|
||||
@@ -12,15 +11,13 @@ type Endpoints struct {
|
||||
NewCommandEndpoint endpoint.Endpoint
|
||||
}
|
||||
|
||||
func MakeServerEndpoints(s Service) Endpoints {
|
||||
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
|
||||
return Endpoints{
|
||||
NewCommandEndpoint: MakeNewCommandEndpoint(s),
|
||||
NewCommandEndpoint: endpoint.Chain(outer, others...)(MakeNewCommandEndpoint(s)),
|
||||
}
|
||||
}
|
||||
|
||||
func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
r, options := httputil.NewRouter(logger)
|
||||
|
||||
func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.ServerOption) {
|
||||
// POST /v1/commands Add new MDM Command to device queue.
|
||||
|
||||
r.Methods("POST").Path("/v1/commands").Handler(httptransport.NewServer(
|
||||
@@ -29,6 +26,4 @@ func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
httputil.EncodeJSONResponse,
|
||||
options...,
|
||||
))
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package config
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
"github.com/go-kit/kit/log"
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/micromdm/micromdm/pkg/httputil"
|
||||
@@ -14,17 +13,15 @@ type Endpoints struct {
|
||||
GetDEPTokensEndpoint endpoint.Endpoint
|
||||
}
|
||||
|
||||
func MakeServerEndpoints(s Service) Endpoints {
|
||||
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
|
||||
return Endpoints{
|
||||
ApplyDEPTokensEndpoint: MakeApplyDEPTokensEndpoint(s),
|
||||
SavePushCertificateEndpoint: MakeSavePushCertificateEndpoint(s),
|
||||
GetDEPTokensEndpoint: MakeGetDEPTokensEndpoint(s),
|
||||
ApplyDEPTokensEndpoint: endpoint.Chain(outer, others...)(MakeApplyDEPTokensEndpoint(s)),
|
||||
SavePushCertificateEndpoint: endpoint.Chain(outer, others...)(MakeSavePushCertificateEndpoint(s)),
|
||||
GetDEPTokensEndpoint: endpoint.Chain(outer, others...)(MakeGetDEPTokensEndpoint(s)),
|
||||
}
|
||||
}
|
||||
|
||||
func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
r, options := httputil.NewRouter(logger)
|
||||
|
||||
func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.ServerOption) {
|
||||
// PUT /v1/config/certificate create or replace the MDM Push Certificate
|
||||
// PUT /v1/dep-tokens create or replace a DEP OAuth token
|
||||
// GET /v1/dep-tokens get the OAuth Token used for the DEP client
|
||||
@@ -49,6 +46,4 @@ func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
httputil.EncodeJSONResponse,
|
||||
options...,
|
||||
))
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package dep
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
"github.com/go-kit/kit/log"
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
@@ -16,18 +15,16 @@ type Endpoints struct {
|
||||
GetDeviceDetailsEndpoint endpoint.Endpoint
|
||||
}
|
||||
|
||||
func MakeServerEndpoints(s Service) Endpoints {
|
||||
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
|
||||
return Endpoints{
|
||||
DefineProfileEndpoint: MakeDefineProfileEndpoint(s),
|
||||
FetchProfileEndpoint: MakeFetchProfileEndpoint(s),
|
||||
GetAccountInfoEndpoint: MakeGetAccountInfoEndpoint(s),
|
||||
GetDeviceDetailsEndpoint: MakeGetDeviceDetailsEndpoint(s),
|
||||
DefineProfileEndpoint: endpoint.Chain(outer, others...)(MakeDefineProfileEndpoint(s)),
|
||||
FetchProfileEndpoint: endpoint.Chain(outer, others...)(MakeFetchProfileEndpoint(s)),
|
||||
GetAccountInfoEndpoint: endpoint.Chain(outer, others...)(MakeGetAccountInfoEndpoint(s)),
|
||||
GetDeviceDetailsEndpoint: endpoint.Chain(outer, others...)(MakeGetDeviceDetailsEndpoint(s)),
|
||||
}
|
||||
}
|
||||
|
||||
func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
r, options := httputil.NewRouter(logger)
|
||||
|
||||
func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.ServerOption) {
|
||||
// PUT /v1/dep/profiles define a DEP profile with mdmenrollment.apple.com
|
||||
// POST /v1/dep/profiles get a DEP profile given a known profile UUID
|
||||
// GET /v1/dep/account get information about the dep account
|
||||
@@ -60,6 +57,4 @@ func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
httputil.EncodeJSONResponse,
|
||||
options...,
|
||||
))
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package device
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
"github.com/go-kit/kit/log"
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
@@ -13,15 +12,13 @@ type Endpoints struct {
|
||||
ListDevicesEndpoint endpoint.Endpoint
|
||||
}
|
||||
|
||||
func MakeServerEndpoints(s Service) Endpoints {
|
||||
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
|
||||
return Endpoints{
|
||||
ListDevicesEndpoint: MakeListDevicesEndpoint(s),
|
||||
ListDevicesEndpoint: endpoint.Chain(outer, others...)(MakeListDevicesEndpoint(s)),
|
||||
}
|
||||
}
|
||||
|
||||
func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
r, options := httputil.NewRouter(logger)
|
||||
|
||||
func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.ServerOption) {
|
||||
// GET /v1/devices get a list of devices managed by the server
|
||||
|
||||
r.Methods("GET").Path("/v1/devices").Handler(httptransport.NewServer(
|
||||
@@ -30,6 +27,4 @@ func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
httputil.EncodeJSONResponse,
|
||||
options...,
|
||||
))
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package profile
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
"github.com/go-kit/kit/log"
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/micromdm/micromdm/pkg/httputil"
|
||||
@@ -14,17 +13,15 @@ type Endpoints struct {
|
||||
RemoveProfilesEndpoint endpoint.Endpoint
|
||||
}
|
||||
|
||||
func MakeServerEndpoints(s Service) Endpoints {
|
||||
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
|
||||
return Endpoints{
|
||||
ApplyProfileEndpoint: MakeApplyProfileEndpoint(s),
|
||||
GetProfilesEndpoint: MakeGetProfilesEndpoint(s),
|
||||
RemoveProfilesEndpoint: MakeRemoveProfilesEndpoint(s),
|
||||
ApplyProfileEndpoint: endpoint.Chain(outer, others...)(MakeApplyProfileEndpoint(s)),
|
||||
GetProfilesEndpoint: endpoint.Chain(outer, others...)(MakeGetProfilesEndpoint(s)),
|
||||
RemoveProfilesEndpoint: endpoint.Chain(outer, others...)(MakeRemoveProfilesEndpoint(s)),
|
||||
}
|
||||
}
|
||||
|
||||
func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
r, options := httputil.NewRouter(logger)
|
||||
|
||||
func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.ServerOption) {
|
||||
// GET /v1/profiles get a list of profiles managed by the server
|
||||
// PUT /v1/profiles create or replace a profile on the server
|
||||
// DELETE /v1/profiles remove one or more profiles from the server
|
||||
@@ -49,6 +46,4 @@ func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
httputil.EncodeJSONResponse,
|
||||
options...,
|
||||
))
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package remove
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
"github.com/go-kit/kit/log"
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/micromdm/micromdm/pkg/httputil"
|
||||
@@ -13,16 +12,14 @@ type Endpoints struct {
|
||||
UnblockDeviceEndpoint endpoint.Endpoint
|
||||
}
|
||||
|
||||
func MakeServerEndpoints(s Service) Endpoints {
|
||||
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
|
||||
return Endpoints{
|
||||
BlockDeviceEndpoint: MakeBlockDeviceEndpoint(s),
|
||||
UnblockDeviceEndpoint: MakeUnblockDeviceEndpoint(s),
|
||||
BlockDeviceEndpoint: endpoint.Chain(outer, others...)(MakeBlockDeviceEndpoint(s)),
|
||||
UnblockDeviceEndpoint: endpoint.Chain(outer, others...)(MakeUnblockDeviceEndpoint(s)),
|
||||
}
|
||||
}
|
||||
|
||||
func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
r, options := httputil.NewRouter(logger)
|
||||
|
||||
func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.ServerOption) {
|
||||
// POST /v1/devices/:udid/block force a device to unenroll next time it connects
|
||||
// POST /v1/devices/:udid/unblock allow a blocked device to enroll again
|
||||
|
||||
@@ -39,7 +36,4 @@ func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
httputil.EncodeJSONResponse,
|
||||
options...,
|
||||
))
|
||||
|
||||
return r
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package user
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
"github.com/go-kit/kit/log"
|
||||
httptransport "github.com/go-kit/kit/transport/http"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
@@ -14,16 +13,14 @@ type Endpoints struct {
|
||||
ListUsersEndpoint endpoint.Endpoint
|
||||
}
|
||||
|
||||
func MakeServerEndpoints(s Service) Endpoints {
|
||||
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
|
||||
return Endpoints{
|
||||
ApplyUserEndpoint: MakeApplyUserEndpoint(s),
|
||||
ListUsersEndpoint: MakeListUsersEndpoint(s),
|
||||
ApplyUserEndpoint: endpoint.Chain(outer, others...)(MakeApplyUserEndpoint(s)),
|
||||
ListUsersEndpoint: endpoint.Chain(outer, others...)(MakeListUsersEndpoint(s)),
|
||||
}
|
||||
}
|
||||
|
||||
func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
r, options := httputil.NewRouter(logger)
|
||||
|
||||
func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.ServerOption) {
|
||||
// PUT /v1/users create or replace an user
|
||||
// GET /v1/users get a list of users managed by the server
|
||||
|
||||
@@ -40,6 +37,4 @@ func MakeHTTPHandler(e Endpoints, logger log.Logger) *mux.Router {
|
||||
httputil.EncodeJSONResponse,
|
||||
options...,
|
||||
))
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user