...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2020-02-02/backup/client.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2020-02-02/backup

     1  // Deprecated: Please note, this package has been deprecated. A replacement package is available [github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservicesbackup](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservicesbackup). We strongly encourage you to upgrade to continue receiving updates. See [Migration Guide](https://aka.ms/azsdk/golang/t2/migration) for guidance on upgrading. Refer to our [deprecation policy](https://azure.github.io/azure-sdk/policies_support.html) for more details.
     2  //
     3  // Package backup implements the Azure ARM Backup service API version .
     4  //
     5  // Open API 2.0 Specs for Azure RecoveryServices Backup service
     6  package backup
     7  
     8  // Copyright (c) Microsoft Corporation. All rights reserved.
     9  // Licensed under the MIT License. See License.txt in the project root for license information.
    10  //
    11  // Code generated by Microsoft (R) AutoRest Code Generator.
    12  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
    13  
    14  import (
    15  	"context"
    16  	"github.com/Azure/go-autorest/autorest"
    17  	"github.com/Azure/go-autorest/autorest/azure"
    18  	"github.com/Azure/go-autorest/tracing"
    19  	"net/http"
    20  )
    21  
    22  const (
    23  	// DefaultBaseURI is the default URI used for the service Backup
    24  	DefaultBaseURI = "https://management.azure.com"
    25  )
    26  
    27  // BaseClient is the base client for Backup.
    28  type BaseClient struct {
    29  	autorest.Client
    30  	BaseURI        string
    31  	SubscriptionID string
    32  }
    33  
    34  // New creates an instance of the BaseClient client.
    35  func New(subscriptionID string) BaseClient {
    36  	return NewWithBaseURI(DefaultBaseURI, subscriptionID)
    37  }
    38  
    39  // NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint.  Use this when interacting with
    40  // an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    41  func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient {
    42  	return BaseClient{
    43  		Client:         autorest.NewClientWithUserAgent(UserAgent()),
    44  		BaseURI:        baseURI,
    45  		SubscriptionID: subscriptionID,
    46  	}
    47  }
    48  
    49  // GetOperationStatus sends the get operation status request.
    50  // Parameters:
    51  // vaultName - the name of the recovery services vault.
    52  // resourceGroupName - the name of the resource group where the recovery services vault is present.
    53  // privateEndpointConnectionName - the name of the private endpoint connection.
    54  // operationID - operation id
    55  func (client BaseClient) GetOperationStatus(ctx context.Context, vaultName string, resourceGroupName string, privateEndpointConnectionName string, operationID string) (result OperationStatus, err error) {
    56  	if tracing.IsEnabled() {
    57  		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetOperationStatus")
    58  		defer func() {
    59  			sc := -1
    60  			if result.Response.Response != nil {
    61  				sc = result.Response.Response.StatusCode
    62  			}
    63  			tracing.EndSpan(ctx, sc, err)
    64  		}()
    65  	}
    66  	req, err := client.GetOperationStatusPreparer(ctx, vaultName, resourceGroupName, privateEndpointConnectionName, operationID)
    67  	if err != nil {
    68  		err = autorest.NewErrorWithError(err, "backup.BaseClient", "GetOperationStatus", nil, "Failure preparing request")
    69  		return
    70  	}
    71  
    72  	resp, err := client.GetOperationStatusSender(req)
    73  	if err != nil {
    74  		result.Response = autorest.Response{Response: resp}
    75  		err = autorest.NewErrorWithError(err, "backup.BaseClient", "GetOperationStatus", resp, "Failure sending request")
    76  		return
    77  	}
    78  
    79  	result, err = client.GetOperationStatusResponder(resp)
    80  	if err != nil {
    81  		err = autorest.NewErrorWithError(err, "backup.BaseClient", "GetOperationStatus", resp, "Failure responding to request")
    82  		return
    83  	}
    84  
    85  	return
    86  }
    87  
    88  // GetOperationStatusPreparer prepares the GetOperationStatus request.
    89  func (client BaseClient) GetOperationStatusPreparer(ctx context.Context, vaultName string, resourceGroupName string, privateEndpointConnectionName string, operationID string) (*http.Request, error) {
    90  	pathParameters := map[string]interface{}{
    91  		"operationId":                   autorest.Encode("path", operationID),
    92  		"privateEndpointConnectionName": autorest.Encode("path", privateEndpointConnectionName),
    93  		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
    94  		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
    95  		"vaultName":                     autorest.Encode("path", vaultName),
    96  	}
    97  
    98  	const APIVersion = "2020-02-02"
    99  	queryParameters := map[string]interface{}{
   100  		"api-version": APIVersion,
   101  	}
   102  
   103  	preparer := autorest.CreatePreparer(
   104  		autorest.AsGet(),
   105  		autorest.WithBaseURL(client.BaseURI),
   106  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/privateEndpointConnections/{privateEndpointConnectionName}/operationsStatus/{operationId}", pathParameters),
   107  		autorest.WithQueryParameters(queryParameters))
   108  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   109  }
   110  
   111  // GetOperationStatusSender sends the GetOperationStatus request. The method will close the
   112  // http.Response Body if it receives an error.
   113  func (client BaseClient) GetOperationStatusSender(req *http.Request) (*http.Response, error) {
   114  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   115  }
   116  
   117  // GetOperationStatusResponder handles the response to the GetOperationStatus request. The method always
   118  // closes the http.Response Body.
   119  func (client BaseClient) GetOperationStatusResponder(resp *http.Response) (result OperationStatus, err error) {
   120  	err = autorest.Respond(
   121  		resp,
   122  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   123  		autorest.ByUnmarshallingJSON(&result),
   124  		autorest.ByClosing())
   125  	result.Response = autorest.Response{Response: resp}
   126  	return
   127  }
   128  

View as plain text