mdmctl: don't send a request body for GET requests (#821)

This commit is contained in:
Kory Prince
2022-05-13 13:24:12 -05:00
committed by GitHub
parent 13b6a440e5
commit 50fb48b7f3
5 changed files with 8 additions and 6 deletions

View File

@@ -97,6 +97,10 @@ func JSONErrorDecoder(r *http.Response) error {
return errors.New(w.Error)
}
func EncodeEmptyRequest(c context.Context, r *http.Request, request interface{}) error {
return nil
}
func EncodeRequestWithToken(token string, next httptransport.EncodeRequestFunc) httptransport.EncodeRequestFunc {
return func(ctx context.Context, r *http.Request, request interface{}) error {
r.SetBasicAuth("micromdm", token)

View File

@@ -42,7 +42,7 @@ func NewHTTPClient(instance, token string, logger log.Logger, opts ...httptransp
getDEPTokensEndpoint = httptransport.NewClient(
"GET",
httputil.CopyURL(u, "/v1/dep-tokens"),
httputil.EncodeRequestWithToken(token, httptransport.EncodeJSONRequest),
httputil.EncodeRequestWithToken(token, httputil.EncodeEmptyRequest),
decodeGetDEPTokensResponse,
opts...,
).Endpoint()

View File

@@ -65,7 +65,7 @@ func NewHTTPClient(instance, token string, logger log.Logger, opts ...httptransp
getAccountInfoEndpoint = httptransport.NewClient(
"GET",
httputil.CopyURL(u, "/v1/dep/account"),
httputil.EncodeRequestWithToken(token, httptransport.EncodeJSONRequest),
httputil.EncodeRequestWithToken(token, httputil.EncodeEmptyRequest),
decodeGetAccountInfoResponse,
opts...,
).Endpoint()

View File

@@ -18,7 +18,6 @@ func (svc *DEPService) GetAccountInfo(ctx context.Context) (*dep.Account, error)
return svc.client.Account()
}
type getAccountInfoRequest struct{}
type getAccountInfoResponse struct {
*dep.Account
Err error `json:"err,omitempty"`
@@ -44,8 +43,7 @@ func MakeGetAccountInfoEndpoint(svc Service) endpoint.Endpoint {
}
func (e Endpoints) GetAccountInfo(ctx context.Context) (*dep.Account, error) {
request := getAccountInfoRequest{}
response, err := e.GetAccountInfoEndpoint(ctx, request)
response, err := e.GetAccountInfoEndpoint(ctx, nil)
if err != nil {
return nil, err
}

View File

@@ -43,7 +43,7 @@ func NewHTTPClient(instance, token string, logger log.Logger, opts ...httptransp
getAutoAssignersEndpoint = httptransport.NewClient(
"GET",
httputil.CopyURL(u, "/v1/dep/autoassigners"),
httputil.EncodeRequestWithToken(token, httptransport.EncodeJSONRequest),
httputil.EncodeRequestWithToken(token, httputil.EncodeEmptyRequest),
decodeGetAutoAssignersResponse,
opts...,
).Endpoint()