DataProtectionPlatformGoPlu.../commitorrollbackrestore_cli...

245 строки
11 KiB
Go

//go:build go1.18
// +build go1.18
// Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.9.0, generator: @autorest/go@4.0.0-preview.42)
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
package dataprotectiondatasourceplugin
import (
"context"
"errors"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"net/http"
"net/url"
"strconv"
"strings"
)
type CommitOrRollbackRestoreClient struct {
pl runtime.Pipeline
}
// NewCommitOrRollbackRestoreClient creates a new instance of CommitOrRollbackRestoreClient with the specified values.
// pl - the pipeline used for sending requests and handling responses.
func NewCommitOrRollbackRestoreClient(pl runtime.Pipeline) *CommitOrRollbackRestoreClient {
client := &CommitOrRollbackRestoreClient{
pl: pl,
}
return client
}
// Cancel - Cancel the operation. Poll the LRO to get the final status.
// If the operation fails it returns an *azcore.ResponseError type.
// Generated from API version 2022-03-01-preview
// operationID - Unique Id of this LRO operation
// subscriptionID - SubscriptionId of the resource
// resourceID - unique id of the resource
// taskID - unique id of the current task
// xmsClientRequestID - correlation request Id for tracking a particular call.
// parameters - Request body for operation
// options - CommitOrRollbackRestoreClientCancelOptions contains the optional parameters for the CommitOrRollbackRestoreClient.Cancel
// method.
func (client *CommitOrRollbackRestoreClient) Cancel(ctx context.Context, operationID string, subscriptionID string, resourceID string, taskID string, xmsClientRequestID string, parameters CancelRequest, options *CommitOrRollbackRestoreClientCancelOptions) (CommitOrRollbackRestoreClientCancelResponse, error) {
req, err := client.cancelCreateRequest(ctx, operationID, subscriptionID, resourceID, taskID, xmsClientRequestID, parameters, options)
if err != nil {
return CommitOrRollbackRestoreClientCancelResponse{}, err
}
resp, err := client.pl.Do(req)
if err != nil {
return CommitOrRollbackRestoreClientCancelResponse{}, err
}
if !runtime.HasStatusCode(resp, http.StatusOK) {
return CommitOrRollbackRestoreClientCancelResponse{}, runtime.NewResponseError(resp)
}
return client.cancelHandleResponse(resp)
}
// cancelCreateRequest creates the Cancel request.
func (client *CommitOrRollbackRestoreClient) cancelCreateRequest(ctx context.Context, operationID string, subscriptionID string, resourceID string, taskID string, xmsClientRequestID string, parameters CancelRequest, options *CommitOrRollbackRestoreClientCancelOptions) (*policy.Request, error) {
urlPath := "/plugin/commitOrRollbackRestoreOperations/{operationId}:cancel"
if operationID == "" {
return nil, errors.New("parameter operationID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{operationId}", url.PathEscape(operationID))
req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths( host, urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2022-03-01-preview")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["subscription-id"] = []string{subscriptionID}
req.Raw().Header["resource-id"] = []string{resourceID}
req.Raw().Header["task-id"] = []string{taskID}
req.Raw().Header["x-ms-client-request-id"] = []string{xmsClientRequestID}
req.Raw().Header["Accept"] = []string{"application/json"}
return req, runtime.MarshalAsJSON(req, parameters)
}
// cancelHandleResponse handles the Cancel response.
func (client *CommitOrRollbackRestoreClient) cancelHandleResponse(resp *http.Response) (CommitOrRollbackRestoreClientCancelResponse, error) {
result := CommitOrRollbackRestoreClientCancelResponse{}
if val := resp.Header.Get("Retry-After"); val != "" {
retryAfter32, err := strconv.ParseInt(val, 10, 32)
retryAfter := int32(retryAfter32)
if err != nil {
return CommitOrRollbackRestoreClientCancelResponse{}, err
}
result.RetryAfter = &retryAfter
}
if val := resp.Header.Get("x-ms-error-code"); val != "" {
result.XMSErrorCode = &val
}
if val := resp.Header.Get("x-ms-request-id"); val != "" {
result.XMSRequestID = &val
}
if err := runtime.UnmarshalAsJSON(resp, &result.CommitOrRollbackRestoreResponse); err != nil {
return CommitOrRollbackRestoreClientCancelResponse{}, err
}
return result, nil
}
// Get - Gets the status of a commitOrRollbackRestore LRO.
// If the operation fails it returns an *azcore.ResponseError type.
// Generated from API version 2022-03-01-preview
// operationID - Unique Id of this LRO operation
// subscriptionID - SubscriptionId of the resource
// resourceID - Unique id of the resource
// taskID - Unique id of the current task
// xmsClientRequestID - Correlation request Id for tracking a particular request.
// options - CommitOrRollbackRestoreClientGetOptions contains the optional parameters for the CommitOrRollbackRestoreClient.Get
// method.
func (client *CommitOrRollbackRestoreClient) Get(ctx context.Context, operationID string, subscriptionID string, resourceID string, taskID string, xmsClientRequestID string, options *CommitOrRollbackRestoreClientGetOptions) (CommitOrRollbackRestoreClientGetResponse, error) {
req, err := client.getCreateRequest(ctx, operationID, subscriptionID, resourceID, taskID, xmsClientRequestID, options)
if err != nil {
return CommitOrRollbackRestoreClientGetResponse{}, err
}
resp, err := client.pl.Do(req)
if err != nil {
return CommitOrRollbackRestoreClientGetResponse{}, err
}
if !runtime.HasStatusCode(resp, http.StatusOK) {
return CommitOrRollbackRestoreClientGetResponse{}, runtime.NewResponseError(resp)
}
return client.getHandleResponse(resp)
}
// getCreateRequest creates the Get request.
func (client *CommitOrRollbackRestoreClient) getCreateRequest(ctx context.Context, operationID string, subscriptionID string, resourceID string, taskID string, xmsClientRequestID string, options *CommitOrRollbackRestoreClientGetOptions) (*policy.Request, error) {
urlPath := "/plugin/commitOrRollbackRestoreOperations/{operationId}"
if operationID == "" {
return nil, errors.New("parameter operationID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{operationId}", url.PathEscape(operationID))
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths( host, urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2022-03-01-preview")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["subscription-id"] = []string{subscriptionID}
req.Raw().Header["resource-id"] = []string{resourceID}
req.Raw().Header["task-id"] = []string{taskID}
req.Raw().Header["x-ms-client-request-id"] = []string{xmsClientRequestID}
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// getHandleResponse handles the Get response.
func (client *CommitOrRollbackRestoreClient) getHandleResponse(resp *http.Response) (CommitOrRollbackRestoreClientGetResponse, error) {
result := CommitOrRollbackRestoreClientGetResponse{}
if val := resp.Header.Get("Retry-After"); val != "" {
retryAfter32, err := strconv.ParseInt(val, 10, 32)
retryAfter := int32(retryAfter32)
if err != nil {
return CommitOrRollbackRestoreClientGetResponse{}, err
}
result.RetryAfter = &retryAfter
}
if val := resp.Header.Get("x-ms-error-code"); val != "" {
result.XMSErrorCode = &val
}
if val := resp.Header.Get("x-ms-request-id"); val != "" {
result.XMSRequestID = &val
}
if err := runtime.UnmarshalAsJSON(resp, &result.CommitOrRollbackRestoreResponse); err != nil {
return CommitOrRollbackRestoreClientGetResponse{}, err
}
return result, nil
}
// RefreshTokens - Refresh tokens for a given operation.
// If the operation fails it returns an *azcore.ResponseError type.
// Generated from API version 2022-03-01-preview
// operationID - Unique Id of this LRO operation
// subscriptionID - SubscriptionId of the resource
// resourceID - unique id of the resource
// taskID - unique id of the current task
// xmsClientRequestID - correlation request Id for tracking a particular call.
// parameters - Request body for operation
// options - CommitOrRollbackRestoreClientRefreshTokensOptions contains the optional parameters for the CommitOrRollbackRestoreClient.RefreshTokens
// method.
func (client *CommitOrRollbackRestoreClient) RefreshTokens(ctx context.Context, operationID string, subscriptionID string, resourceID string, taskID string, xmsClientRequestID string, parameters RefreshTokensRequest, options *CommitOrRollbackRestoreClientRefreshTokensOptions) (CommitOrRollbackRestoreClientRefreshTokensResponse, error) {
req, err := client.refreshTokensCreateRequest(ctx, operationID, subscriptionID, resourceID, taskID, xmsClientRequestID, parameters, options)
if err != nil {
return CommitOrRollbackRestoreClientRefreshTokensResponse{}, err
}
resp, err := client.pl.Do(req)
if err != nil {
return CommitOrRollbackRestoreClientRefreshTokensResponse{}, err
}
if !runtime.HasStatusCode(resp, http.StatusOK) {
return CommitOrRollbackRestoreClientRefreshTokensResponse{}, runtime.NewResponseError(resp)
}
return client.refreshTokensHandleResponse(resp)
}
// refreshTokensCreateRequest creates the RefreshTokens request.
func (client *CommitOrRollbackRestoreClient) refreshTokensCreateRequest(ctx context.Context, operationID string, subscriptionID string, resourceID string, taskID string, xmsClientRequestID string, parameters RefreshTokensRequest, options *CommitOrRollbackRestoreClientRefreshTokensOptions) (*policy.Request, error) {
urlPath := "/plugin/commitOrRollbackRestoreOperations/{operationId}:refreshTokens"
if operationID == "" {
return nil, errors.New("parameter operationID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{operationId}", url.PathEscape(operationID))
req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths( host, urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2022-03-01-preview")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["subscription-id"] = []string{subscriptionID}
req.Raw().Header["resource-id"] = []string{resourceID}
req.Raw().Header["task-id"] = []string{taskID}
req.Raw().Header["x-ms-client-request-id"] = []string{xmsClientRequestID}
req.Raw().Header["Accept"] = []string{"application/json"}
return req, runtime.MarshalAsJSON(req, parameters)
}
// refreshTokensHandleResponse handles the RefreshTokens response.
func (client *CommitOrRollbackRestoreClient) refreshTokensHandleResponse(resp *http.Response) (CommitOrRollbackRestoreClientRefreshTokensResponse, error) {
result := CommitOrRollbackRestoreClientRefreshTokensResponse{}
if val := resp.Header.Get("Retry-After"); val != "" {
retryAfter32, err := strconv.ParseInt(val, 10, 32)
retryAfter := int32(retryAfter32)
if err != nil {
return CommitOrRollbackRestoreClientRefreshTokensResponse{}, err
}
result.RetryAfter = &retryAfter
}
if val := resp.Header.Get("x-ms-error-code"); val != "" {
result.XMSErrorCode = &val
}
if val := resp.Header.Get("x-ms-request-id"); val != "" {
result.XMSRequestID = &val
}
if err := runtime.UnmarshalAsJSON(resp, &result.CommitOrRollbackRestoreResponse); err != nil {
return CommitOrRollbackRestoreClientRefreshTokensResponse{}, err
}
return result, nil
}