Files
micromdm/platform/config/server.go
Victor Vrantchan 70d26149ae only register HTTP routes once (#418)
Simplified the registration of HTTP routes.
Moved basic auth middleware to use the provided go-kit library.
2018-05-12 19:17:40 -04:00

50 lines
1.6 KiB
Go

package config
import (
"github.com/go-kit/kit/endpoint"
httptransport "github.com/go-kit/kit/transport/http"
"github.com/gorilla/mux"
"github.com/micromdm/micromdm/pkg/httputil"
)
type Endpoints struct {
ApplyDEPTokensEndpoint endpoint.Endpoint
SavePushCertificateEndpoint endpoint.Endpoint
GetDEPTokensEndpoint endpoint.Endpoint
}
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
return Endpoints{
ApplyDEPTokensEndpoint: endpoint.Chain(outer, others...)(MakeApplyDEPTokensEndpoint(s)),
SavePushCertificateEndpoint: endpoint.Chain(outer, others...)(MakeSavePushCertificateEndpoint(s)),
GetDEPTokensEndpoint: endpoint.Chain(outer, others...)(MakeGetDEPTokensEndpoint(s)),
}
}
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
r.Methods("PUT").Path("/v1/config/certificate").Handler(httptransport.NewServer(
e.SavePushCertificateEndpoint,
decodeSavePushCertificateRequest,
httputil.EncodeJSONResponse,
options...,
))
r.Methods("PUT").Path("/v1/dep-tokens").Handler(httptransport.NewServer(
e.ApplyDEPTokensEndpoint,
decodeApplyDEPTokensRequest,
httputil.EncodeJSONResponse,
options...,
))
r.Methods("GET").Path("/v1/dep-tokens").Handler(httptransport.NewServer(
e.GetDEPTokensEndpoint,
decodeGetDEPTokensRequest,
httputil.EncodeJSONResponse,
options...,
))
}