mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-06 17:53:14 +08:00
Changed GET to POST for "get apps" as a GET with a request body is not preferred. Changed POST to PUT for "upload apps" as POST is now used for "get apps".
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package appstore
|
|
|
|
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 appUploadEndpoint endpoint.Endpoint
|
|
{
|
|
appUploadEndpoint = httptransport.NewClient(
|
|
"PUT",
|
|
httputil.CopyURL(u, "/v1/apps"),
|
|
httputil.EncodeRequestWithToken(token, encodeUploadAppRequest),
|
|
decodeUploadAppResponse,
|
|
opts...,
|
|
).Endpoint()
|
|
}
|
|
|
|
var listAppsEndpoint endpoint.Endpoint
|
|
{
|
|
listAppsEndpoint = httptransport.NewClient(
|
|
"POST",
|
|
httputil.CopyURL(u, "/v1/apps"),
|
|
httputil.EncodeRequestWithToken(token, httptransport.EncodeJSONRequest),
|
|
decodeListAppsResponse,
|
|
opts...,
|
|
).Endpoint()
|
|
}
|
|
|
|
return Endpoints{
|
|
AppUploadEndpoint: appUploadEndpoint,
|
|
ListAppsEndpoint: listAppsEndpoint,
|
|
}, nil
|
|
}
|