mirror of
https://github.com/micromdm/micromdm/
synced 2026-06-19 18:45:45 +08:00
The new remove devices command takes a UDID or list of UDIDs as input and calls the devices delete endpoint. Since serial number isn't strictly required by the spec it seemed to make more sense to keep the remove working with only UDIDs. The get devices command with a serial number filter can always be used to look up a UDID from a serial number.
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package device
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/go-kit/kit/endpoint"
|
|
"github.com/micromdm/micromdm/pkg/httputil"
|
|
)
|
|
|
|
func (svc *DeviceService) RemoveDevices(ctx context.Context, udids []string) error {
|
|
for _, udid := range udids {
|
|
err := svc.store.Delete(udid)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type removeDevicesRequest struct {
|
|
Identifiers []string `json:"udids"`
|
|
}
|
|
|
|
type removeDevicesResponse struct {
|
|
Err error `json:"err,omitempty"`
|
|
}
|
|
|
|
func (r removeDevicesResponse) Failed() error { return r.Err }
|
|
|
|
func decodeRemoveDevicesRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
var req removeDevicesRequest
|
|
err := httputil.DecodeJSONRequest(r, &req)
|
|
return req, err
|
|
}
|
|
|
|
func decodeRemoveDevicesResponse(_ context.Context, r *http.Response) (interface{}, error) {
|
|
var resp removeDevicesResponse
|
|
err := httputil.DecodeJSONResponse(r, &resp)
|
|
return resp, err
|
|
}
|
|
|
|
func MakeRemoveDevicesEndpoint(svc Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
|
|
req := request.(removeDevicesRequest)
|
|
err = svc.RemoveDevices(ctx, req.Identifiers)
|
|
return removeDevicesResponse{
|
|
Err: err,
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
func (e Endpoints) RemoveDevices(ctx context.Context, ids []string) error {
|
|
request := removeDevicesRequest{Identifiers: ids}
|
|
resp, err := e.RemoveDevicesEndpoint(ctx, request)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return resp.(removeDevicesResponse).Err
|
|
}
|