/
client.go
93 lines (82 loc) · 2.42 KB
/
client.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package dep
import (
"net/url"
"github.com/go-kit/kit/endpoint"
"github.com/go-kit/kit/log"
httptransport "github.com/go-kit/kit/transport/http"
"github.com/micromdm/micromdm/pkg/httputil"
)
func NewHTTPClient(instance, token string, logger log.Logger, opts ...httptransport.ClientOption) (Service, error) {
u, err := url.Parse(instance)
if err != nil {
return nil, err
}
var defineProfileEndpoint endpoint.Endpoint
{
defineProfileEndpoint = httptransport.NewClient(
"PUT",
httputil.CopyURL(u, "/v1/dep/profiles"),
httputil.EncodeRequestWithToken(token, httptransport.EncodeJSONRequest),
decodeDefineProfileResponse,
opts...,
).Endpoint()
}
var assignProfileEndpoint endpoint.Endpoint
{
assignProfileEndpoint = httptransport.NewClient(
"POST",
httputil.CopyURL(u, "/v1/dep/assign"),
httputil.EncodeRequestWithToken(token, httptransport.EncodeJSONRequest),
decodeAssignProfileResponse,
opts...,
).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(
"POST",
httputil.CopyURL(u, "/v1/dep/profiles"),
httputil.EncodeRequestWithToken(token, httptransport.EncodeJSONRequest),
decodeFetchProfileResponse,
opts...,
).Endpoint()
}
var getAccountInfoEndpoint endpoint.Endpoint
{
getAccountInfoEndpoint = httptransport.NewClient(
"GET",
httputil.CopyURL(u, "/v1/dep/account"),
httputil.EncodeRequestWithToken(token, httputil.EncodeEmptyRequest),
decodeGetAccountInfoResponse,
opts...,
).Endpoint()
}
var getDeviceDetailsEndpoint endpoint.Endpoint
{
getDeviceDetailsEndpoint = httptransport.NewClient(
"POST",
httputil.CopyURL(u, "/v1/dep/devices"),
httputil.EncodeRequestWithToken(token, httptransport.EncodeJSONRequest),
decodeDeviceDetailsResponse,
opts...,
).Endpoint()
}
return Endpoints{
DefineProfileEndpoint: defineProfileEndpoint,
AssignProfileEndpoint: assignProfileEndpoint,
RemoveProfileEndpoint: removeProfileEndpoint,
FetchProfileEndpoint: fetchProfileEndpoint,
GetAccountInfoEndpoint: getAccountInfoEndpoint,
GetDeviceDetailsEndpoint: getDeviceDetailsEndpoint,
}, nil
}