mirror of
https://github.com/micromdm/micromdm/
synced 2026-05-13 01:46:05 +08:00
mdmctl: don't send a request body for GET requests (#821)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user