...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2021-07-01/backup/protectionpolicyoperationresults.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2021-07-01/backup

     1  package backup
     2  
     3  // Copyright (c) Microsoft Corporation. All rights reserved.
     4  // Licensed under the MIT License. See License.txt in the project root for license information.
     5  //
     6  // Code generated by Microsoft (R) AutoRest Code Generator.
     7  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
     8  
     9  import (
    10  	"context"
    11  	"github.com/Azure/go-autorest/autorest"
    12  	"github.com/Azure/go-autorest/autorest/azure"
    13  	"github.com/Azure/go-autorest/tracing"
    14  	"net/http"
    15  )
    16  
    17  // ProtectionPolicyOperationResultsClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
    18  type ProtectionPolicyOperationResultsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewProtectionPolicyOperationResultsClient creates an instance of the ProtectionPolicyOperationResultsClient client.
    23  func NewProtectionPolicyOperationResultsClient(subscriptionID string) ProtectionPolicyOperationResultsClient {
    24  	return NewProtectionPolicyOperationResultsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewProtectionPolicyOperationResultsClientWithBaseURI creates an instance of the
    28  // ProtectionPolicyOperationResultsClient client using a custom endpoint.  Use this when interacting with an Azure
    29  // cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewProtectionPolicyOperationResultsClientWithBaseURI(baseURI string, subscriptionID string) ProtectionPolicyOperationResultsClient {
    31  	return ProtectionPolicyOperationResultsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // Get provides the result of an operation.
    35  // Parameters:
    36  // vaultName - the name of the recovery services vault.
    37  // resourceGroupName - the name of the resource group where the recovery services vault is present.
    38  // policyName - backup policy name whose operation's result needs to be fetched.
    39  // operationID - operation ID which represents the operation whose result needs to be fetched.
    40  func (client ProtectionPolicyOperationResultsClient) Get(ctx context.Context, vaultName string, resourceGroupName string, policyName string, operationID string) (result ProtectionPolicyResource, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPolicyOperationResultsClient.Get")
    43  		defer func() {
    44  			sc := -1
    45  			if result.Response.Response != nil {
    46  				sc = result.Response.Response.StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, policyName, operationID)
    52  	if err != nil {
    53  		err = autorest.NewErrorWithError(err, "backup.ProtectionPolicyOperationResultsClient", "Get", nil, "Failure preparing request")
    54  		return
    55  	}
    56  
    57  	resp, err := client.GetSender(req)
    58  	if err != nil {
    59  		result.Response = autorest.Response{Response: resp}
    60  		err = autorest.NewErrorWithError(err, "backup.ProtectionPolicyOperationResultsClient", "Get", resp, "Failure sending request")
    61  		return
    62  	}
    63  
    64  	result, err = client.GetResponder(resp)
    65  	if err != nil {
    66  		err = autorest.NewErrorWithError(err, "backup.ProtectionPolicyOperationResultsClient", "Get", resp, "Failure responding to request")
    67  		return
    68  	}
    69  
    70  	return
    71  }
    72  
    73  // GetPreparer prepares the Get request.
    74  func (client ProtectionPolicyOperationResultsClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string, operationID string) (*http.Request, error) {
    75  	pathParameters := map[string]interface{}{
    76  		"operationId":       autorest.Encode("path", operationID),
    77  		"policyName":        autorest.Encode("path", policyName),
    78  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    79  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    80  		"vaultName":         autorest.Encode("path", vaultName),
    81  	}
    82  
    83  	const APIVersion = "2021-07-01"
    84  	queryParameters := map[string]interface{}{
    85  		"api-version": APIVersion,
    86  	}
    87  
    88  	preparer := autorest.CreatePreparer(
    89  		autorest.AsGet(),
    90  		autorest.WithBaseURL(client.BaseURI),
    91  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}/operationResults/{operationId}", pathParameters),
    92  		autorest.WithQueryParameters(queryParameters))
    93  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    94  }
    95  
    96  // GetSender sends the Get request. The method will close the
    97  // http.Response Body if it receives an error.
    98  func (client ProtectionPolicyOperationResultsClient) GetSender(req *http.Request) (*http.Response, error) {
    99  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   100  }
   101  
   102  // GetResponder handles the response to the Get request. The method always
   103  // closes the http.Response Body.
   104  func (client ProtectionPolicyOperationResultsClient) GetResponder(resp *http.Response) (result ProtectionPolicyResource, err error) {
   105  	err = autorest.Respond(
   106  		resp,
   107  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   108  		autorest.ByUnmarshallingJSON(&result),
   109  		autorest.ByClosing())
   110  	result.Response = autorest.Response{Response: resp}
   111  	return
   112  }
   113  

View as plain text