...

Source file src/github.com/Azure/azure-sdk-for-go/services/dataprotection/mgmt/2021-07-01/dataprotection/backuppolicies.go

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

     1  package dataprotection
     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  // BackupPoliciesClient is the open API 2.0 Specs for Azure Data Protection service
    18  type BackupPoliciesClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewBackupPoliciesClient creates an instance of the BackupPoliciesClient client.
    23  func NewBackupPoliciesClient(subscriptionID string) BackupPoliciesClient {
    24  	return NewBackupPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewBackupPoliciesClientWithBaseURI creates an instance of the BackupPoliciesClient client using a custom endpoint.
    28  // Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewBackupPoliciesClientWithBaseURI(baseURI string, subscriptionID string) BackupPoliciesClient {
    30  	return BackupPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // CreateOrUpdate sends the create or update request.
    34  // Parameters:
    35  // vaultName - the name of the backup vault.
    36  // resourceGroupName - the name of the resource group where the backup vault is present.
    37  // backupPolicyName - name of the policy
    38  // parameters - request body for operation
    39  func (client BackupPoliciesClient) CreateOrUpdate(ctx context.Context, vaultName string, resourceGroupName string, backupPolicyName string, parameters BaseBackupPolicyResource) (result BaseBackupPolicyResource, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/BackupPoliciesClient.CreateOrUpdate")
    42  		defer func() {
    43  			sc := -1
    44  			if result.Response.Response != nil {
    45  				sc = result.Response.Response.StatusCode
    46  			}
    47  			tracing.EndSpan(ctx, sc, err)
    48  		}()
    49  	}
    50  	req, err := client.CreateOrUpdatePreparer(ctx, vaultName, resourceGroupName, backupPolicyName, parameters)
    51  	if err != nil {
    52  		err = autorest.NewErrorWithError(err, "dataprotection.BackupPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request")
    53  		return
    54  	}
    55  
    56  	resp, err := client.CreateOrUpdateSender(req)
    57  	if err != nil {
    58  		result.Response = autorest.Response{Response: resp}
    59  		err = autorest.NewErrorWithError(err, "dataprotection.BackupPoliciesClient", "CreateOrUpdate", resp, "Failure sending request")
    60  		return
    61  	}
    62  
    63  	result, err = client.CreateOrUpdateResponder(resp)
    64  	if err != nil {
    65  		err = autorest.NewErrorWithError(err, "dataprotection.BackupPoliciesClient", "CreateOrUpdate", resp, "Failure responding to request")
    66  		return
    67  	}
    68  
    69  	return
    70  }
    71  
    72  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    73  func (client BackupPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, vaultName string, resourceGroupName string, backupPolicyName string, parameters BaseBackupPolicyResource) (*http.Request, error) {
    74  	pathParameters := map[string]interface{}{
    75  		"backupPolicyName":  autorest.Encode("path", backupPolicyName),
    76  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    77  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    78  		"vaultName":         autorest.Encode("path", vaultName),
    79  	}
    80  
    81  	const APIVersion = "2021-07-01"
    82  	queryParameters := map[string]interface{}{
    83  		"api-version": APIVersion,
    84  	}
    85  
    86  	preparer := autorest.CreatePreparer(
    87  		autorest.AsContentType("application/json; charset=utf-8"),
    88  		autorest.AsPut(),
    89  		autorest.WithBaseURL(client.BaseURI),
    90  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataProtection/backupVaults/{vaultName}/backupPolicies/{backupPolicyName}", pathParameters),
    91  		autorest.WithJSON(parameters),
    92  		autorest.WithQueryParameters(queryParameters))
    93  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    94  }
    95  
    96  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
    97  // http.Response Body if it receives an error.
    98  func (client BackupPoliciesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
    99  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   100  }
   101  
   102  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   103  // closes the http.Response Body.
   104  func (client BackupPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result BaseBackupPolicyResource, 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  
   114  // Delete sends the delete request.
   115  // Parameters:
   116  // vaultName - the name of the backup vault.
   117  // resourceGroupName - the name of the resource group where the backup vault is present.
   118  func (client BackupPoliciesClient) Delete(ctx context.Context, vaultName string, resourceGroupName string, backupPolicyName string) (result autorest.Response, err error) {
   119  	if tracing.IsEnabled() {
   120  		ctx = tracing.StartSpan(ctx, fqdn+"/BackupPoliciesClient.Delete")
   121  		defer func() {
   122  			sc := -1
   123  			if result.Response != nil {
   124  				sc = result.Response.StatusCode
   125  			}
   126  			tracing.EndSpan(ctx, sc, err)
   127  		}()
   128  	}
   129  	req, err := client.DeletePreparer(ctx, vaultName, resourceGroupName, backupPolicyName)
   130  	if err != nil {
   131  		err = autorest.NewErrorWithError(err, "dataprotection.BackupPoliciesClient", "Delete", nil, "Failure preparing request")
   132  		return
   133  	}
   134  
   135  	resp, err := client.DeleteSender(req)
   136  	if err != nil {
   137  		result.Response = resp
   138  		err = autorest.NewErrorWithError(err, "dataprotection.BackupPoliciesClient", "Delete", resp, "Failure sending request")
   139  		return
   140  	}
   141  
   142  	result, err = client.DeleteResponder(resp)
   143  	if err != nil {
   144  		err = autorest.NewErrorWithError(err, "dataprotection.BackupPoliciesClient", "Delete", resp, "Failure responding to request")
   145  		return
   146  	}
   147  
   148  	return
   149  }
   150  
   151  // DeletePreparer prepares the Delete request.
   152  func (client BackupPoliciesClient) DeletePreparer(ctx context.Context, vaultName string, resourceGroupName string, backupPolicyName string) (*http.Request, error) {
   153  	pathParameters := map[string]interface{}{
   154  		"backupPolicyName":  autorest.Encode("path", backupPolicyName),
   155  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   156  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   157  		"vaultName":         autorest.Encode("path", vaultName),
   158  	}
   159  
   160  	const APIVersion = "2021-07-01"
   161  	queryParameters := map[string]interface{}{
   162  		"api-version": APIVersion,
   163  	}
   164  
   165  	preparer := autorest.CreatePreparer(
   166  		autorest.AsDelete(),
   167  		autorest.WithBaseURL(client.BaseURI),
   168  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataProtection/backupVaults/{vaultName}/backupPolicies/{backupPolicyName}", pathParameters),
   169  		autorest.WithQueryParameters(queryParameters))
   170  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   171  }
   172  
   173  // DeleteSender sends the Delete request. The method will close the
   174  // http.Response Body if it receives an error.
   175  func (client BackupPoliciesClient) DeleteSender(req *http.Request) (*http.Response, error) {
   176  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   177  }
   178  
   179  // DeleteResponder handles the response to the Delete request. The method always
   180  // closes the http.Response Body.
   181  func (client BackupPoliciesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   182  	err = autorest.Respond(
   183  		resp,
   184  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   185  		autorest.ByClosing())
   186  	result.Response = resp
   187  	return
   188  }
   189  
   190  // Get gets a backup policy belonging to a backup vault
   191  // Parameters:
   192  // vaultName - the name of the backup vault.
   193  // resourceGroupName - the name of the resource group where the backup vault is present.
   194  func (client BackupPoliciesClient) Get(ctx context.Context, vaultName string, resourceGroupName string, backupPolicyName string) (result BaseBackupPolicyResource, err error) {
   195  	if tracing.IsEnabled() {
   196  		ctx = tracing.StartSpan(ctx, fqdn+"/BackupPoliciesClient.Get")
   197  		defer func() {
   198  			sc := -1
   199  			if result.Response.Response != nil {
   200  				sc = result.Response.Response.StatusCode
   201  			}
   202  			tracing.EndSpan(ctx, sc, err)
   203  		}()
   204  	}
   205  	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, backupPolicyName)
   206  	if err != nil {
   207  		err = autorest.NewErrorWithError(err, "dataprotection.BackupPoliciesClient", "Get", nil, "Failure preparing request")
   208  		return
   209  	}
   210  
   211  	resp, err := client.GetSender(req)
   212  	if err != nil {
   213  		result.Response = autorest.Response{Response: resp}
   214  		err = autorest.NewErrorWithError(err, "dataprotection.BackupPoliciesClient", "Get", resp, "Failure sending request")
   215  		return
   216  	}
   217  
   218  	result, err = client.GetResponder(resp)
   219  	if err != nil {
   220  		err = autorest.NewErrorWithError(err, "dataprotection.BackupPoliciesClient", "Get", resp, "Failure responding to request")
   221  		return
   222  	}
   223  
   224  	return
   225  }
   226  
   227  // GetPreparer prepares the Get request.
   228  func (client BackupPoliciesClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, backupPolicyName string) (*http.Request, error) {
   229  	pathParameters := map[string]interface{}{
   230  		"backupPolicyName":  autorest.Encode("path", backupPolicyName),
   231  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   232  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   233  		"vaultName":         autorest.Encode("path", vaultName),
   234  	}
   235  
   236  	const APIVersion = "2021-07-01"
   237  	queryParameters := map[string]interface{}{
   238  		"api-version": APIVersion,
   239  	}
   240  
   241  	preparer := autorest.CreatePreparer(
   242  		autorest.AsGet(),
   243  		autorest.WithBaseURL(client.BaseURI),
   244  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataProtection/backupVaults/{vaultName}/backupPolicies/{backupPolicyName}", pathParameters),
   245  		autorest.WithQueryParameters(queryParameters))
   246  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   247  }
   248  
   249  // GetSender sends the Get request. The method will close the
   250  // http.Response Body if it receives an error.
   251  func (client BackupPoliciesClient) GetSender(req *http.Request) (*http.Response, error) {
   252  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   253  }
   254  
   255  // GetResponder handles the response to the Get request. The method always
   256  // closes the http.Response Body.
   257  func (client BackupPoliciesClient) GetResponder(resp *http.Response) (result BaseBackupPolicyResource, err error) {
   258  	err = autorest.Respond(
   259  		resp,
   260  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   261  		autorest.ByUnmarshallingJSON(&result),
   262  		autorest.ByClosing())
   263  	result.Response = autorest.Response{Response: resp}
   264  	return
   265  }
   266  
   267  // List returns list of backup policies belonging to a backup vault
   268  // Parameters:
   269  // vaultName - the name of the backup vault.
   270  // resourceGroupName - the name of the resource group where the backup vault is present.
   271  func (client BackupPoliciesClient) List(ctx context.Context, vaultName string, resourceGroupName string) (result BaseBackupPolicyResourceListPage, err error) {
   272  	if tracing.IsEnabled() {
   273  		ctx = tracing.StartSpan(ctx, fqdn+"/BackupPoliciesClient.List")
   274  		defer func() {
   275  			sc := -1
   276  			if result.bbprl.Response.Response != nil {
   277  				sc = result.bbprl.Response.Response.StatusCode
   278  			}
   279  			tracing.EndSpan(ctx, sc, err)
   280  		}()
   281  	}
   282  	result.fn = client.listNextResults
   283  	req, err := client.ListPreparer(ctx, vaultName, resourceGroupName)
   284  	if err != nil {
   285  		err = autorest.NewErrorWithError(err, "dataprotection.BackupPoliciesClient", "List", nil, "Failure preparing request")
   286  		return
   287  	}
   288  
   289  	resp, err := client.ListSender(req)
   290  	if err != nil {
   291  		result.bbprl.Response = autorest.Response{Response: resp}
   292  		err = autorest.NewErrorWithError(err, "dataprotection.BackupPoliciesClient", "List", resp, "Failure sending request")
   293  		return
   294  	}
   295  
   296  	result.bbprl, err = client.ListResponder(resp)
   297  	if err != nil {
   298  		err = autorest.NewErrorWithError(err, "dataprotection.BackupPoliciesClient", "List", resp, "Failure responding to request")
   299  		return
   300  	}
   301  	if result.bbprl.hasNextLink() && result.bbprl.IsEmpty() {
   302  		err = result.NextWithContext(ctx)
   303  		return
   304  	}
   305  
   306  	return
   307  }
   308  
   309  // ListPreparer prepares the List request.
   310  func (client BackupPoliciesClient) ListPreparer(ctx context.Context, vaultName string, resourceGroupName string) (*http.Request, error) {
   311  	pathParameters := map[string]interface{}{
   312  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   313  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   314  		"vaultName":         autorest.Encode("path", vaultName),
   315  	}
   316  
   317  	const APIVersion = "2021-07-01"
   318  	queryParameters := map[string]interface{}{
   319  		"api-version": APIVersion,
   320  	}
   321  
   322  	preparer := autorest.CreatePreparer(
   323  		autorest.AsGet(),
   324  		autorest.WithBaseURL(client.BaseURI),
   325  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataProtection/backupVaults/{vaultName}/backupPolicies", pathParameters),
   326  		autorest.WithQueryParameters(queryParameters))
   327  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   328  }
   329  
   330  // ListSender sends the List request. The method will close the
   331  // http.Response Body if it receives an error.
   332  func (client BackupPoliciesClient) ListSender(req *http.Request) (*http.Response, error) {
   333  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   334  }
   335  
   336  // ListResponder handles the response to the List request. The method always
   337  // closes the http.Response Body.
   338  func (client BackupPoliciesClient) ListResponder(resp *http.Response) (result BaseBackupPolicyResourceList, err error) {
   339  	err = autorest.Respond(
   340  		resp,
   341  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   342  		autorest.ByUnmarshallingJSON(&result),
   343  		autorest.ByClosing())
   344  	result.Response = autorest.Response{Response: resp}
   345  	return
   346  }
   347  
   348  // listNextResults retrieves the next set of results, if any.
   349  func (client BackupPoliciesClient) listNextResults(ctx context.Context, lastResults BaseBackupPolicyResourceList) (result BaseBackupPolicyResourceList, err error) {
   350  	req, err := lastResults.baseBackupPolicyResourceListPreparer(ctx)
   351  	if err != nil {
   352  		return result, autorest.NewErrorWithError(err, "dataprotection.BackupPoliciesClient", "listNextResults", nil, "Failure preparing next results request")
   353  	}
   354  	if req == nil {
   355  		return
   356  	}
   357  	resp, err := client.ListSender(req)
   358  	if err != nil {
   359  		result.Response = autorest.Response{Response: resp}
   360  		return result, autorest.NewErrorWithError(err, "dataprotection.BackupPoliciesClient", "listNextResults", resp, "Failure sending next results request")
   361  	}
   362  	result, err = client.ListResponder(resp)
   363  	if err != nil {
   364  		err = autorest.NewErrorWithError(err, "dataprotection.BackupPoliciesClient", "listNextResults", resp, "Failure responding to next results request")
   365  	}
   366  	return
   367  }
   368  
   369  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   370  func (client BackupPoliciesClient) ListComplete(ctx context.Context, vaultName string, resourceGroupName string) (result BaseBackupPolicyResourceListIterator, err error) {
   371  	if tracing.IsEnabled() {
   372  		ctx = tracing.StartSpan(ctx, fqdn+"/BackupPoliciesClient.List")
   373  		defer func() {
   374  			sc := -1
   375  			if result.Response().Response.Response != nil {
   376  				sc = result.page.Response().Response.Response.StatusCode
   377  			}
   378  			tracing.EndSpan(ctx, sc, err)
   379  		}()
   380  	}
   381  	result.page, err = client.List(ctx, vaultName, resourceGroupName)
   382  	return
   383  }
   384  

View as plain text