in internal/clients/data_plane_client.go [279:345]
func (client *DataPlaneClient) Action(ctx context.Context, resourceID string, action string, apiVersion string, method string, body interface{}, options RequestOptions) (interface{}, error) {
// build request
urlPath := fmt.Sprintf("https://%s", resourceID)
if action != "" {
urlPath = fmt.Sprintf("%s/%s", resourceID, action)
}
req, err := runtime.NewRequest(ctx, method, urlPath)
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", apiVersion)
for key, value := range options.QueryParameters {
reqQP.Set(key, value)
}
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header.Set("Accept", "application/json")
for key, value := range options.Headers {
req.Raw().Header.Set(key, value)
}
if method != "GET" && body != nil {
err = runtime.MarshalAsJSON(req, body)
}
if err != nil {
return nil, err
}
// send request
pipeline, err := client.cachedPipeline(urlPath)
if err != nil {
return nil, err
}
resp, err := pipeline.Do(req)
if err != nil {
return nil, err
}
if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated, http.StatusAccepted) {
return nil, runtime.NewResponseError(resp)
}
// poll until done
pt, err := runtime.NewPoller[interface{}](resp, pipeline, nil)
if err == nil {
resp, err := pt.PollUntilDone(ctx, &runtime.PollUntilDoneOptions{
Frequency: 10 * time.Second,
})
return resp, err
}
// unmarshal response
var responseBody interface{}
contentType := resp.Header.Get("Content-Type")
switch {
case strings.Contains(contentType, "text/plain"):
payload, err := runtime.Payload(resp)
if err != nil {
return nil, err
}
responseBody = string(payload)
case strings.Contains(contentType, "application/json"):
if err := runtime.UnmarshalAsJSON(resp, &responseBody); err != nil {
return nil, err
}
default:
}
return responseBody, nil
}