mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-08 10:45:34 +08:00
Closes #302 This package still needs a lot of work, but I feel like this is a good stopping point. In a follow up, I plan on writing some tests, and refactoring some of the ways the sync.Watcher goroutines are managed.
65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
package sync
|
|
|
|
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"
|
|
)
|
|
|
|
func NewService(syncer Syncer, db DB) *DEPSyncService {
|
|
return &DEPSyncService{syncer: syncer, db: db}
|
|
}
|
|
|
|
type Endpoints struct {
|
|
SyncNowEndpoint endpoint.Endpoint
|
|
ApplyAutoAssignerEndpoint endpoint.Endpoint
|
|
GetAutoAssignersEndpoint endpoint.Endpoint
|
|
RemoveAutoAssignerEndpoint endpoint.Endpoint
|
|
}
|
|
|
|
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
|
|
return Endpoints{
|
|
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 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
|
|
// DELETE /v1/dep/autoassigners remove a DEP auto-assigner
|
|
|
|
r.Methods("POST").Path("/v1/dep/syncnow").Handler(httptransport.NewServer(
|
|
e.SyncNowEndpoint,
|
|
decodeEmptyRequest,
|
|
encodeEmptyResponse,
|
|
options...,
|
|
))
|
|
|
|
r.Methods("POST").Path("/v1/dep/autoassigners").Handler(httptransport.NewServer(
|
|
e.ApplyAutoAssignerEndpoint,
|
|
decodeApplyAutoAssignerRequest,
|
|
httputil.EncodeJSONResponse,
|
|
options...,
|
|
))
|
|
|
|
r.Methods("GET").Path("/v1/dep/autoassigners").Handler(httptransport.NewServer(
|
|
e.GetAutoAssignersEndpoint,
|
|
decodeEmptyRequest,
|
|
httputil.EncodeJSONResponse,
|
|
options...,
|
|
))
|
|
|
|
r.Methods("DELETE").Path("/v1/dep/autoassigners").Handler(httptransport.NewServer(
|
|
e.RemoveAutoAssignerEndpoint,
|
|
decodeRemoveAutoAssignerRequest,
|
|
httputil.EncodeJSONResponse,
|
|
options...,
|
|
))
|
|
}
|