forked from micromdm/micromdm
/
server.go
60 lines (51 loc) · 1.96 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package dep
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 {
DefineProfileEndpoint endpoint.Endpoint
FetchProfileEndpoint endpoint.Endpoint
GetAccountInfoEndpoint endpoint.Endpoint
GetDeviceDetailsEndpoint endpoint.Endpoint
}
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
return Endpoints{
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 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
// POST /v1/dep/devices get device details given a list of serials
r.Methods("PUT").Path("/v1/dep/profiles").Handler(httptransport.NewServer(
e.DefineProfileEndpoint,
decodeDefineProfileRequest,
httputil.EncodeJSONResponse,
options...,
))
r.Methods("POST").Path("/v1/dep/profiles").Handler(httptransport.NewServer(
e.FetchProfileEndpoint,
decodeFetchProfileRequest,
httputil.EncodeJSONResponse,
options...,
))
r.Methods("GET").Path("/v1/dep/account").Handler(httptransport.NewServer(
e.GetAccountInfoEndpoint,
decodeGetAccountInfoRequest,
httputil.EncodeJSONResponse,
options...,
))
r.Methods("POST").Path("/v1/dep/devices").Handler(httptransport.NewServer(
e.GetDeviceDetailsEndpoint,
decodeDeviceDetailsRequest,
httputil.EncodeJSONResponse,
options...,
))
}