/
assign_profile.go
64 lines (53 loc) · 1.77 KB
/
assign_profile.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
61
62
63
64
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) AssignProfile(ctx context.Context, id string, serials ...string) (*dep.ProfileResponse, error) {
if svc.client == nil {
return nil, errors.New("DEP not configured yet. add a DEP token to enable DEP")
}
return svc.client.AssignProfile(id, serials...)
}
type assignProfileRequest struct {
ID string `json:"id"`
Serials []string `json:"serials"`
}
type assignProfileResponse struct {
*dep.ProfileResponse
Err error `json:"err,omitempty"`
}
func (r assignProfileResponse) Failed() error { return r.Err }
func decodeAssignProfileRequest(ctx context.Context, r *http.Request) (interface{}, error) {
var req assignProfileRequest
err := httputil.DecodeJSONRequest(r, &req)
return req, err
}
func decodeAssignProfileResponse(_ context.Context, r *http.Response) (interface{}, error) {
var resp assignProfileResponse
err := httputil.DecodeJSONResponse(r, &resp)
return resp, err
}
func MakeAssignProfileEndpoint(svc Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
req := request.(assignProfileRequest)
resp, err := svc.AssignProfile(ctx, req.ID, req.Serials...)
return &assignProfileResponse{
ProfileResponse: resp,
Err: err,
}, nil
}
}
func (e Endpoints) AssignProfile(ctx context.Context, id string, serials ...string) (*dep.ProfileResponse, error) {
request := assignProfileRequest{ID: id, Serials: serials}
resp, err := e.AssignProfileEndpoint(ctx, request)
if err != nil {
return nil, err
}
response := resp.(assignProfileResponse)
return response.ProfileResponse, response.Err
}