forked from micromdm/micromdm
/
client.go
56 lines (49 loc) · 1.39 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
package profile
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 applyProfileEndpoint endpoint.Endpoint
{
applyProfileEndpoint = httptransport.NewClient(
"PUT",
httputil.CopyURL(u, "/v1/profiles"),
httputil.EncodeRequestWithToken(token, httptransport.EncodeJSONRequest),
decodeApplyProfileResponse,
opts...,
).Endpoint()
}
var getProfilesEndpoint endpoint.Endpoint
{
getProfilesEndpoint = httptransport.NewClient(
"GET",
httputil.CopyURL(u, "/v1/profiles"),
httputil.EncodeRequestWithToken(token, httptransport.EncodeJSONRequest),
decodeGetProfilesResponse,
opts...,
).Endpoint()
}
var removeProfilesEndpoint endpoint.Endpoint
{
removeProfilesEndpoint = httptransport.NewClient(
"DELETE",
httputil.CopyURL(u, "/v1/profiles"),
httputil.EncodeRequestWithToken(token, httptransport.EncodeJSONRequest),
decodeRemoveProfileResponse,
opts...,
).Endpoint()
}
return Endpoints{
ApplyProfileEndpoint: applyProfileEndpoint,
GetProfilesEndpoint: getProfilesEndpoint,
RemoveProfilesEndpoint: removeProfilesEndpoint,
}, nil
}