Files
micromdm/platform/profile/client.go
jenjac 323c05b230 GET to POST for v1/profiles endpoint (#523)
Changed GET to POST as a GET with a request body is not preferred.
2018-10-10 12:32:46 -04:00

57 lines
1.4 KiB
Go

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(
"POST",
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
}