...

Source file src/github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-04-01/storage/managementpolicies.go

Documentation: github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-04-01/storage

     1  package storage
     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/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // ManagementPoliciesClient is the the Azure Storage Management API.
    19  type ManagementPoliciesClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewManagementPoliciesClient creates an instance of the ManagementPoliciesClient client.
    24  func NewManagementPoliciesClient(subscriptionID string) ManagementPoliciesClient {
    25  	return NewManagementPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewManagementPoliciesClientWithBaseURI creates an instance of the ManagementPoliciesClient client using a custom
    29  // endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
    30  // stack).
    31  func NewManagementPoliciesClientWithBaseURI(baseURI string, subscriptionID string) ManagementPoliciesClient {
    32  	return ManagementPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // CreateOrUpdate sets the managementpolicy to the specified storage account.
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group within the user's subscription. The name is case
    38  // insensitive.
    39  // accountName - the name of the storage account within the specified resource group. Storage account names
    40  // must be between 3 and 24 characters in length and use numbers and lower-case letters only.
    41  // properties - the ManagementPolicy set to a storage account.
    42  func (client ManagementPoliciesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, accountName string, properties ManagementPolicy) (result ManagementPolicy, err error) {
    43  	if tracing.IsEnabled() {
    44  		ctx = tracing.StartSpan(ctx, fqdn+"/ManagementPoliciesClient.CreateOrUpdate")
    45  		defer func() {
    46  			sc := -1
    47  			if result.Response.Response != nil {
    48  				sc = result.Response.Response.StatusCode
    49  			}
    50  			tracing.EndSpan(ctx, sc, err)
    51  		}()
    52  	}
    53  	if err := validation.Validate([]validation.Validation{
    54  		{TargetValue: resourceGroupName,
    55  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    56  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
    57  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
    58  		{TargetValue: accountName,
    59  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
    60  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
    61  		{TargetValue: client.SubscriptionID,
    62  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    63  		{TargetValue: properties,
    64  			Constraints: []validation.Constraint{{Target: "properties.ManagementPolicyProperties", Name: validation.Null, Rule: false,
    65  				Chain: []validation.Constraint{{Target: "properties.ManagementPolicyProperties.Policy", Name: validation.Null, Rule: true,
    66  					Chain: []validation.Constraint{{Target: "properties.ManagementPolicyProperties.Policy.Rules", Name: validation.Null, Rule: true, Chain: nil}}},
    67  				}}}}}); err != nil {
    68  		return result, validation.NewError("storage.ManagementPoliciesClient", "CreateOrUpdate", err.Error())
    69  	}
    70  
    71  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, accountName, properties)
    72  	if err != nil {
    73  		err = autorest.NewErrorWithError(err, "storage.ManagementPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request")
    74  		return
    75  	}
    76  
    77  	resp, err := client.CreateOrUpdateSender(req)
    78  	if err != nil {
    79  		result.Response = autorest.Response{Response: resp}
    80  		err = autorest.NewErrorWithError(err, "storage.ManagementPoliciesClient", "CreateOrUpdate", resp, "Failure sending request")
    81  		return
    82  	}
    83  
    84  	result, err = client.CreateOrUpdateResponder(resp)
    85  	if err != nil {
    86  		err = autorest.NewErrorWithError(err, "storage.ManagementPoliciesClient", "CreateOrUpdate", resp, "Failure responding to request")
    87  		return
    88  	}
    89  
    90  	return
    91  }
    92  
    93  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    94  func (client ManagementPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, properties ManagementPolicy) (*http.Request, error) {
    95  	pathParameters := map[string]interface{}{
    96  		"accountName":          autorest.Encode("path", accountName),
    97  		"managementPolicyName": autorest.Encode("path", "default"),
    98  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
    99  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
   100  	}
   101  
   102  	const APIVersion = "2019-04-01"
   103  	queryParameters := map[string]interface{}{
   104  		"api-version": APIVersion,
   105  	}
   106  
   107  	preparer := autorest.CreatePreparer(
   108  		autorest.AsContentType("application/json; charset=utf-8"),
   109  		autorest.AsPut(),
   110  		autorest.WithBaseURL(client.BaseURI),
   111  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/managementPolicies/{managementPolicyName}", pathParameters),
   112  		autorest.WithJSON(properties),
   113  		autorest.WithQueryParameters(queryParameters))
   114  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   115  }
   116  
   117  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   118  // http.Response Body if it receives an error.
   119  func (client ManagementPoliciesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   120  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   121  }
   122  
   123  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   124  // closes the http.Response Body.
   125  func (client ManagementPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result ManagementPolicy, err error) {
   126  	err = autorest.Respond(
   127  		resp,
   128  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   129  		autorest.ByUnmarshallingJSON(&result),
   130  		autorest.ByClosing())
   131  	result.Response = autorest.Response{Response: resp}
   132  	return
   133  }
   134  
   135  // Delete deletes the managementpolicy associated with the specified storage account.
   136  // Parameters:
   137  // resourceGroupName - the name of the resource group within the user's subscription. The name is case
   138  // insensitive.
   139  // accountName - the name of the storage account within the specified resource group. Storage account names
   140  // must be between 3 and 24 characters in length and use numbers and lower-case letters only.
   141  func (client ManagementPoliciesClient) Delete(ctx context.Context, resourceGroupName string, accountName string) (result autorest.Response, err error) {
   142  	if tracing.IsEnabled() {
   143  		ctx = tracing.StartSpan(ctx, fqdn+"/ManagementPoliciesClient.Delete")
   144  		defer func() {
   145  			sc := -1
   146  			if result.Response != nil {
   147  				sc = result.Response.StatusCode
   148  			}
   149  			tracing.EndSpan(ctx, sc, err)
   150  		}()
   151  	}
   152  	if err := validation.Validate([]validation.Validation{
   153  		{TargetValue: resourceGroupName,
   154  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   155  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   156  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   157  		{TargetValue: accountName,
   158  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
   159  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
   160  		{TargetValue: client.SubscriptionID,
   161  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   162  		return result, validation.NewError("storage.ManagementPoliciesClient", "Delete", err.Error())
   163  	}
   164  
   165  	req, err := client.DeletePreparer(ctx, resourceGroupName, accountName)
   166  	if err != nil {
   167  		err = autorest.NewErrorWithError(err, "storage.ManagementPoliciesClient", "Delete", nil, "Failure preparing request")
   168  		return
   169  	}
   170  
   171  	resp, err := client.DeleteSender(req)
   172  	if err != nil {
   173  		result.Response = resp
   174  		err = autorest.NewErrorWithError(err, "storage.ManagementPoliciesClient", "Delete", resp, "Failure sending request")
   175  		return
   176  	}
   177  
   178  	result, err = client.DeleteResponder(resp)
   179  	if err != nil {
   180  		err = autorest.NewErrorWithError(err, "storage.ManagementPoliciesClient", "Delete", resp, "Failure responding to request")
   181  		return
   182  	}
   183  
   184  	return
   185  }
   186  
   187  // DeletePreparer prepares the Delete request.
   188  func (client ManagementPoliciesClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
   189  	pathParameters := map[string]interface{}{
   190  		"accountName":          autorest.Encode("path", accountName),
   191  		"managementPolicyName": autorest.Encode("path", "default"),
   192  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
   193  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
   194  	}
   195  
   196  	const APIVersion = "2019-04-01"
   197  	queryParameters := map[string]interface{}{
   198  		"api-version": APIVersion,
   199  	}
   200  
   201  	preparer := autorest.CreatePreparer(
   202  		autorest.AsDelete(),
   203  		autorest.WithBaseURL(client.BaseURI),
   204  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/managementPolicies/{managementPolicyName}", pathParameters),
   205  		autorest.WithQueryParameters(queryParameters))
   206  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   207  }
   208  
   209  // DeleteSender sends the Delete request. The method will close the
   210  // http.Response Body if it receives an error.
   211  func (client ManagementPoliciesClient) DeleteSender(req *http.Request) (*http.Response, error) {
   212  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   213  }
   214  
   215  // DeleteResponder handles the response to the Delete request. The method always
   216  // closes the http.Response Body.
   217  func (client ManagementPoliciesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   218  	err = autorest.Respond(
   219  		resp,
   220  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   221  		autorest.ByClosing())
   222  	result.Response = resp
   223  	return
   224  }
   225  
   226  // Get gets the managementpolicy associated with the specified storage account.
   227  // Parameters:
   228  // resourceGroupName - the name of the resource group within the user's subscription. The name is case
   229  // insensitive.
   230  // accountName - the name of the storage account within the specified resource group. Storage account names
   231  // must be between 3 and 24 characters in length and use numbers and lower-case letters only.
   232  func (client ManagementPoliciesClient) Get(ctx context.Context, resourceGroupName string, accountName string) (result ManagementPolicy, err error) {
   233  	if tracing.IsEnabled() {
   234  		ctx = tracing.StartSpan(ctx, fqdn+"/ManagementPoliciesClient.Get")
   235  		defer func() {
   236  			sc := -1
   237  			if result.Response.Response != nil {
   238  				sc = result.Response.Response.StatusCode
   239  			}
   240  			tracing.EndSpan(ctx, sc, err)
   241  		}()
   242  	}
   243  	if err := validation.Validate([]validation.Validation{
   244  		{TargetValue: resourceGroupName,
   245  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   246  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   247  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   248  		{TargetValue: accountName,
   249  			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
   250  				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}}},
   251  		{TargetValue: client.SubscriptionID,
   252  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   253  		return result, validation.NewError("storage.ManagementPoliciesClient", "Get", err.Error())
   254  	}
   255  
   256  	req, err := client.GetPreparer(ctx, resourceGroupName, accountName)
   257  	if err != nil {
   258  		err = autorest.NewErrorWithError(err, "storage.ManagementPoliciesClient", "Get", nil, "Failure preparing request")
   259  		return
   260  	}
   261  
   262  	resp, err := client.GetSender(req)
   263  	if err != nil {
   264  		result.Response = autorest.Response{Response: resp}
   265  		err = autorest.NewErrorWithError(err, "storage.ManagementPoliciesClient", "Get", resp, "Failure sending request")
   266  		return
   267  	}
   268  
   269  	result, err = client.GetResponder(resp)
   270  	if err != nil {
   271  		err = autorest.NewErrorWithError(err, "storage.ManagementPoliciesClient", "Get", resp, "Failure responding to request")
   272  		return
   273  	}
   274  
   275  	return
   276  }
   277  
   278  // GetPreparer prepares the Get request.
   279  func (client ManagementPoliciesClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
   280  	pathParameters := map[string]interface{}{
   281  		"accountName":          autorest.Encode("path", accountName),
   282  		"managementPolicyName": autorest.Encode("path", "default"),
   283  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
   284  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
   285  	}
   286  
   287  	const APIVersion = "2019-04-01"
   288  	queryParameters := map[string]interface{}{
   289  		"api-version": APIVersion,
   290  	}
   291  
   292  	preparer := autorest.CreatePreparer(
   293  		autorest.AsGet(),
   294  		autorest.WithBaseURL(client.BaseURI),
   295  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/managementPolicies/{managementPolicyName}", pathParameters),
   296  		autorest.WithQueryParameters(queryParameters))
   297  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   298  }
   299  
   300  // GetSender sends the Get request. The method will close the
   301  // http.Response Body if it receives an error.
   302  func (client ManagementPoliciesClient) GetSender(req *http.Request) (*http.Response, error) {
   303  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   304  }
   305  
   306  // GetResponder handles the response to the Get request. The method always
   307  // closes the http.Response Body.
   308  func (client ManagementPoliciesClient) GetResponder(resp *http.Response) (result ManagementPolicy, err error) {
   309  	err = autorest.Respond(
   310  		resp,
   311  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   312  		autorest.ByUnmarshallingJSON(&result),
   313  		autorest.ByClosing())
   314  	result.Response = autorest.Response{Response: resp}
   315  	return
   316  }
   317  

View as plain text