...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2021-01-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  // PoliciesClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
    18  type PoliciesClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewPoliciesClient creates an instance of the PoliciesClient client.
    23  func NewPoliciesClient(subscriptionID string) PoliciesClient {
    24  	return NewPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewPoliciesClientWithBaseURI creates an instance of the PoliciesClient client using a custom endpoint.  Use this
    28  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewPoliciesClientWithBaseURI(baseURI string, subscriptionID string) PoliciesClient {
    30  	return PoliciesClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // List lists of backup policies associated with Recovery Services Vault. API provides pagination parameters to fetch
    34  // scoped results.
    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  // filter - oData filter options.
    39  func (client PoliciesClient) List(ctx context.Context, vaultName string, resourceGroupName string, filter string) (result ProtectionPolicyResourceListPage, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/PoliciesClient.List")
    42  		defer func() {
    43  			sc := -1
    44  			if result.pprl.Response.Response != nil {
    45  				sc = result.pprl.Response.Response.StatusCode
    46  			}
    47  			tracing.EndSpan(ctx, sc, err)
    48  		}()
    49  	}
    50  	result.fn = client.listNextResults
    51  	req, err := client.ListPreparer(ctx, vaultName, resourceGroupName, filter)
    52  	if err != nil {
    53  		err = autorest.NewErrorWithError(err, "backup.PoliciesClient", "List", nil, "Failure preparing request")
    54  		return
    55  	}
    56  
    57  	resp, err := client.ListSender(req)
    58  	if err != nil {
    59  		result.pprl.Response = autorest.Response{Response: resp}
    60  		err = autorest.NewErrorWithError(err, "backup.PoliciesClient", "List", resp, "Failure sending request")
    61  		return
    62  	}
    63  
    64  	result.pprl, err = client.ListResponder(resp)
    65  	if err != nil {
    66  		err = autorest.NewErrorWithError(err, "backup.PoliciesClient", "List", resp, "Failure responding to request")
    67  		return
    68  	}
    69  	if result.pprl.hasNextLink() && result.pprl.IsEmpty() {
    70  		err = result.NextWithContext(ctx)
    71  		return
    72  	}
    73  
    74  	return
    75  }
    76  
    77  // ListPreparer prepares the List request.
    78  func (client PoliciesClient) ListPreparer(ctx context.Context, vaultName string, resourceGroupName string, filter string) (*http.Request, error) {
    79  	pathParameters := map[string]interface{}{
    80  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    81  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    82  		"vaultName":         autorest.Encode("path", vaultName),
    83  	}
    84  
    85  	const APIVersion = "2021-01-01"
    86  	queryParameters := map[string]interface{}{
    87  		"api-version": APIVersion,
    88  	}
    89  	if len(filter) > 0 {
    90  		queryParameters["$filter"] = autorest.Encode("query", filter)
    91  	}
    92  
    93  	preparer := autorest.CreatePreparer(
    94  		autorest.AsGet(),
    95  		autorest.WithBaseURL(client.BaseURI),
    96  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies", pathParameters),
    97  		autorest.WithQueryParameters(queryParameters))
    98  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    99  }
   100  
   101  // ListSender sends the List request. The method will close the
   102  // http.Response Body if it receives an error.
   103  func (client PoliciesClient) ListSender(req *http.Request) (*http.Response, error) {
   104  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   105  }
   106  
   107  // ListResponder handles the response to the List request. The method always
   108  // closes the http.Response Body.
   109  func (client PoliciesClient) ListResponder(resp *http.Response) (result ProtectionPolicyResourceList, err error) {
   110  	err = autorest.Respond(
   111  		resp,
   112  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   113  		autorest.ByUnmarshallingJSON(&result),
   114  		autorest.ByClosing())
   115  	result.Response = autorest.Response{Response: resp}
   116  	return
   117  }
   118  
   119  // listNextResults retrieves the next set of results, if any.
   120  func (client PoliciesClient) listNextResults(ctx context.Context, lastResults ProtectionPolicyResourceList) (result ProtectionPolicyResourceList, err error) {
   121  	req, err := lastResults.protectionPolicyResourceListPreparer(ctx)
   122  	if err != nil {
   123  		return result, autorest.NewErrorWithError(err, "backup.PoliciesClient", "listNextResults", nil, "Failure preparing next results request")
   124  	}
   125  	if req == nil {
   126  		return
   127  	}
   128  	resp, err := client.ListSender(req)
   129  	if err != nil {
   130  		result.Response = autorest.Response{Response: resp}
   131  		return result, autorest.NewErrorWithError(err, "backup.PoliciesClient", "listNextResults", resp, "Failure sending next results request")
   132  	}
   133  	result, err = client.ListResponder(resp)
   134  	if err != nil {
   135  		err = autorest.NewErrorWithError(err, "backup.PoliciesClient", "listNextResults", resp, "Failure responding to next results request")
   136  	}
   137  	return
   138  }
   139  
   140  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   141  func (client PoliciesClient) ListComplete(ctx context.Context, vaultName string, resourceGroupName string, filter string) (result ProtectionPolicyResourceListIterator, err error) {
   142  	if tracing.IsEnabled() {
   143  		ctx = tracing.StartSpan(ctx, fqdn+"/PoliciesClient.List")
   144  		defer func() {
   145  			sc := -1
   146  			if result.Response().Response.Response != nil {
   147  				sc = result.page.Response().Response.Response.StatusCode
   148  			}
   149  			tracing.EndSpan(ctx, sc, err)
   150  		}()
   151  	}
   152  	result.page, err = client.List(ctx, vaultName, resourceGroupName, filter)
   153  	return
   154  }
   155  

View as plain text