mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-05 00:45:50 +08:00
Adds the ability to send a DELETE request to clear the DEP profile assignment (#687)
for one or more serial numbers.
DELETE /v1/dep/profiles
{
"serials" : [a,b,c,d]
}
This commit is contained in:
@@ -38,6 +38,17 @@ func NewHTTPClient(instance, token string, logger log.Logger, opts ...httptransp
|
||||
).Endpoint()
|
||||
}
|
||||
|
||||
var removeProfileEndpoint endpoint.Endpoint
|
||||
{
|
||||
removeProfileEndpoint = httptransport.NewClient(
|
||||
"DELETE",
|
||||
httputil.CopyURL(u, "/v1/dep/profiles"),
|
||||
httputil.EncodeRequestWithToken(token, httptransport.EncodeJSONRequest),
|
||||
decodeRemoveProfileResponse,
|
||||
opts...,
|
||||
).Endpoint()
|
||||
}
|
||||
|
||||
var fetchProfileEndpoint endpoint.Endpoint
|
||||
{
|
||||
fetchProfileEndpoint = httptransport.NewClient(
|
||||
@@ -74,6 +85,7 @@ func NewHTTPClient(instance, token string, logger log.Logger, opts ...httptransp
|
||||
return Endpoints{
|
||||
DefineProfileEndpoint: defineProfileEndpoint,
|
||||
AssignProfileEndpoint: assignProfileEndpoint,
|
||||
RemoveProfileEndpoint: removeProfileEndpoint,
|
||||
FetchProfileEndpoint: fetchProfileEndpoint,
|
||||
GetAccountInfoEndpoint: getAccountInfoEndpoint,
|
||||
GetDeviceDetailsEndpoint: getDeviceDetailsEndpoint,
|
||||
|
||||
63
platform/dep/remove_profile.go
Normal file
63
platform/dep/remove_profile.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package dep
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
|
||||
// "github.com/micromdm/micromdm/dep"
|
||||
"github.com/micromdm/micromdm/pkg/httputil"
|
||||
)
|
||||
|
||||
func (svc *DEPService) RemoveProfile(ctx context.Context, serials ...string) (map[string]string, error) {
|
||||
if svc.client == nil {
|
||||
return nil, errors.New("DEP not configured yet. add a DEP token to enable DEP")
|
||||
}
|
||||
return svc.client.RemoveProfile(serials...)
|
||||
}
|
||||
|
||||
type removeProfileRequest struct {
|
||||
Serials []string `json:"serials"`
|
||||
}
|
||||
|
||||
type removeProfileResponse struct {
|
||||
Serials map[string]string `json:"serials"`
|
||||
Err error `json:"err,omitempty"`
|
||||
}
|
||||
|
||||
func (r removeProfileResponse) Failed() error { return r.Err }
|
||||
|
||||
func decodeRemoveProfileRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
||||
var req removeProfileRequest
|
||||
err := httputil.DecodeJSONRequest(r, &req)
|
||||
return req, err
|
||||
}
|
||||
|
||||
func decodeRemoveProfileResponse(_ context.Context, r *http.Response) (interface{}, error) {
|
||||
var resp removeProfileResponse
|
||||
err := httputil.DecodeJSONResponse(r, &resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func MakeRemoveProfileEndpoint(svc Service) endpoint.Endpoint {
|
||||
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
|
||||
req := request.(removeProfileRequest)
|
||||
resp, err := svc.RemoveProfile(ctx, req.Serials...)
|
||||
return &removeProfileResponse{
|
||||
Serials: resp,
|
||||
Err: err,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (e Endpoints) RemoveProfile(ctx context.Context, serials ...string) (map[string]string, error) {
|
||||
request := removeProfileRequest{Serials: serials}
|
||||
resp, err := e.RemoveProfileEndpoint(ctx, request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response := resp.(removeProfileResponse)
|
||||
return response.Serials, response.Err
|
||||
}
|
||||
@@ -14,11 +14,13 @@ type Endpoints struct {
|
||||
GetAccountInfoEndpoint endpoint.Endpoint
|
||||
GetDeviceDetailsEndpoint endpoint.Endpoint
|
||||
AssignProfileEndpoint endpoint.Endpoint
|
||||
RemoveProfileEndpoint endpoint.Endpoint
|
||||
}
|
||||
|
||||
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
|
||||
return Endpoints{
|
||||
AssignProfileEndpoint: endpoint.Chain(outer, others...)(MakeAssignProfileEndpoint(s)),
|
||||
RemoveProfileEndpoint: endpoint.Chain(outer, others...)(MakeRemoveProfileEndpoint(s)),
|
||||
DefineProfileEndpoint: endpoint.Chain(outer, others...)(MakeDefineProfileEndpoint(s)),
|
||||
FetchProfileEndpoint: endpoint.Chain(outer, others...)(MakeFetchProfileEndpoint(s)),
|
||||
GetAccountInfoEndpoint: endpoint.Chain(outer, others...)(MakeGetAccountInfoEndpoint(s)),
|
||||
@@ -31,7 +33,8 @@ func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.S
|
||||
// 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
|
||||
// POST /v1/dep/assign assign a specific profile ID to one or more serial
|
||||
// POST /v1/dep/assign assign a specific profile ID to one or more serials
|
||||
// DELETE /v1/dep/profiles clear an assigned DEP profile for one or more serials
|
||||
|
||||
r.Methods("PUT").Path("/v1/dep/profiles").Handler(httptransport.NewServer(
|
||||
e.DefineProfileEndpoint,
|
||||
@@ -67,4 +70,11 @@ func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.S
|
||||
httputil.EncodeJSONResponse,
|
||||
options...,
|
||||
))
|
||||
|
||||
r.Methods("DELETE").Path("/v1/dep/profiles").Handler(httptransport.NewServer(
|
||||
e.RemoveProfileEndpoint,
|
||||
decodeRemoveProfileRequest,
|
||||
httputil.EncodeJSONResponse,
|
||||
options...,
|
||||
))
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
type Service interface {
|
||||
DefineProfile(ctx context.Context, p *dep.Profile) (*dep.ProfileResponse, error)
|
||||
AssignProfile(ctx context.Context, uuid string, serials ...string) (*dep.ProfileResponse, error)
|
||||
RemoveProfile(ctx context.Context, serials ...string) (map[string]string, error)
|
||||
GetAccountInfo(ctx context.Context) (*dep.Account, error)
|
||||
GetDeviceDetails(ctx context.Context, serials []string) (*dep.DeviceDetailsResponse, error)
|
||||
FetchProfile(ctx context.Context, uuid string) (*dep.Profile, error)
|
||||
@@ -19,6 +20,7 @@ type Service interface {
|
||||
type DEPClient interface {
|
||||
DefineProfile(*dep.Profile) (*dep.ProfileResponse, error)
|
||||
AssignProfile(string, ...string) (*dep.ProfileResponse, error)
|
||||
RemoveProfile(...string) (map[string]string, error)
|
||||
FetchProfile(string) (*dep.Profile, error)
|
||||
Account() (*dep.Account, error)
|
||||
DeviceDetails(...string) (*dep.DeviceDetailsResponse, error)
|
||||
|
||||
Reference in New Issue
Block a user