...

Source file src/github.com/Azure/azure-sdk-for-go/services/storsimple8000series/mgmt/2017-06-01/storsimple/storageaccountcredentials.go

Documentation: github.com/Azure/azure-sdk-for-go/services/storsimple8000series/mgmt/2017-06-01/storsimple

     1  package storsimple
     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  // StorageAccountCredentialsClient is the client for the StorageAccountCredentials methods of the Storsimple service.
    19  type StorageAccountCredentialsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewStorageAccountCredentialsClient creates an instance of the StorageAccountCredentialsClient client.
    24  func NewStorageAccountCredentialsClient(subscriptionID string) StorageAccountCredentialsClient {
    25  	return NewStorageAccountCredentialsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewStorageAccountCredentialsClientWithBaseURI creates an instance of the StorageAccountCredentialsClient client
    29  // using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
    30  // clouds, Azure stack).
    31  func NewStorageAccountCredentialsClientWithBaseURI(baseURI string, subscriptionID string) StorageAccountCredentialsClient {
    32  	return StorageAccountCredentialsClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // CreateOrUpdate creates or updates the storage account credential.
    36  // Parameters:
    37  // storageAccountCredentialName - the storage account credential name.
    38  // parameters - the storage account credential to be added or updated.
    39  // resourceGroupName - the resource group name
    40  // managerName - the manager name
    41  func (client StorageAccountCredentialsClient) CreateOrUpdate(ctx context.Context, storageAccountCredentialName string, parameters StorageAccountCredential, resourceGroupName string, managerName string) (result StorageAccountCredentialsCreateOrUpdateFuture, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/StorageAccountCredentialsClient.CreateOrUpdate")
    44  		defer func() {
    45  			sc := -1
    46  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    47  				sc = result.FutureAPI.Response().StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	if err := validation.Validate([]validation.Validation{
    53  		{TargetValue: parameters,
    54  			Constraints: []validation.Constraint{{Target: "parameters.StorageAccountCredentialProperties", Name: validation.Null, Rule: true,
    55  				Chain: []validation.Constraint{{Target: "parameters.StorageAccountCredentialProperties.EndPoint", Name: validation.Null, Rule: true, Chain: nil},
    56  					{Target: "parameters.StorageAccountCredentialProperties.AccessKey", Name: validation.Null, Rule: false,
    57  						Chain: []validation.Constraint{{Target: "parameters.StorageAccountCredentialProperties.AccessKey.Value", Name: validation.Null, Rule: true, Chain: nil}}},
    58  				}}}},
    59  		{TargetValue: managerName,
    60  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    61  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
    62  		return result, validation.NewError("storsimple.StorageAccountCredentialsClient", "CreateOrUpdate", err.Error())
    63  	}
    64  
    65  	req, err := client.CreateOrUpdatePreparer(ctx, storageAccountCredentialName, parameters, resourceGroupName, managerName)
    66  	if err != nil {
    67  		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "CreateOrUpdate", nil, "Failure preparing request")
    68  		return
    69  	}
    70  
    71  	result, err = client.CreateOrUpdateSender(req)
    72  	if err != nil {
    73  		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    74  		return
    75  	}
    76  
    77  	return
    78  }
    79  
    80  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    81  func (client StorageAccountCredentialsClient) CreateOrUpdatePreparer(ctx context.Context, storageAccountCredentialName string, parameters StorageAccountCredential, resourceGroupName string, managerName string) (*http.Request, error) {
    82  	pathParameters := map[string]interface{}{
    83  		"managerName":                  managerName,
    84  		"resourceGroupName":            resourceGroupName,
    85  		"storageAccountCredentialName": storageAccountCredentialName,
    86  		"subscriptionId":               client.SubscriptionID,
    87  	}
    88  
    89  	const APIVersion = "2017-06-01"
    90  	queryParameters := map[string]interface{}{
    91  		"api-version": APIVersion,
    92  	}
    93  
    94  	preparer := autorest.CreatePreparer(
    95  		autorest.AsContentType("application/json; charset=utf-8"),
    96  		autorest.AsPut(),
    97  		autorest.WithBaseURL(client.BaseURI),
    98  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/storageAccountCredentials/{storageAccountCredentialName}", pathParameters),
    99  		autorest.WithJSON(parameters),
   100  		autorest.WithQueryParameters(queryParameters))
   101  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   102  }
   103  
   104  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   105  // http.Response Body if it receives an error.
   106  func (client StorageAccountCredentialsClient) CreateOrUpdateSender(req *http.Request) (future StorageAccountCredentialsCreateOrUpdateFuture, err error) {
   107  	var resp *http.Response
   108  	future.FutureAPI = &azure.Future{}
   109  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   110  	if err != nil {
   111  		return
   112  	}
   113  	var azf azure.Future
   114  	azf, err = azure.NewFutureFromResponse(resp)
   115  	future.FutureAPI = &azf
   116  	future.Result = future.result
   117  	return
   118  }
   119  
   120  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   121  // closes the http.Response Body.
   122  func (client StorageAccountCredentialsClient) CreateOrUpdateResponder(resp *http.Response) (result StorageAccountCredential, err error) {
   123  	err = autorest.Respond(
   124  		resp,
   125  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   126  		autorest.ByUnmarshallingJSON(&result),
   127  		autorest.ByClosing())
   128  	result.Response = autorest.Response{Response: resp}
   129  	return
   130  }
   131  
   132  // Delete deletes the storage account credential.
   133  // Parameters:
   134  // storageAccountCredentialName - the name of the storage account credential.
   135  // resourceGroupName - the resource group name
   136  // managerName - the manager name
   137  func (client StorageAccountCredentialsClient) Delete(ctx context.Context, storageAccountCredentialName string, resourceGroupName string, managerName string) (result StorageAccountCredentialsDeleteFuture, err error) {
   138  	if tracing.IsEnabled() {
   139  		ctx = tracing.StartSpan(ctx, fqdn+"/StorageAccountCredentialsClient.Delete")
   140  		defer func() {
   141  			sc := -1
   142  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   143  				sc = result.FutureAPI.Response().StatusCode
   144  			}
   145  			tracing.EndSpan(ctx, sc, err)
   146  		}()
   147  	}
   148  	if err := validation.Validate([]validation.Validation{
   149  		{TargetValue: managerName,
   150  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   151  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   152  		return result, validation.NewError("storsimple.StorageAccountCredentialsClient", "Delete", err.Error())
   153  	}
   154  
   155  	req, err := client.DeletePreparer(ctx, storageAccountCredentialName, resourceGroupName, managerName)
   156  	if err != nil {
   157  		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "Delete", nil, "Failure preparing request")
   158  		return
   159  	}
   160  
   161  	result, err = client.DeleteSender(req)
   162  	if err != nil {
   163  		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "Delete", result.Response(), "Failure sending request")
   164  		return
   165  	}
   166  
   167  	return
   168  }
   169  
   170  // DeletePreparer prepares the Delete request.
   171  func (client StorageAccountCredentialsClient) DeletePreparer(ctx context.Context, storageAccountCredentialName string, resourceGroupName string, managerName string) (*http.Request, error) {
   172  	pathParameters := map[string]interface{}{
   173  		"managerName":                  managerName,
   174  		"resourceGroupName":            resourceGroupName,
   175  		"storageAccountCredentialName": storageAccountCredentialName,
   176  		"subscriptionId":               client.SubscriptionID,
   177  	}
   178  
   179  	const APIVersion = "2017-06-01"
   180  	queryParameters := map[string]interface{}{
   181  		"api-version": APIVersion,
   182  	}
   183  
   184  	preparer := autorest.CreatePreparer(
   185  		autorest.AsDelete(),
   186  		autorest.WithBaseURL(client.BaseURI),
   187  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/storageAccountCredentials/{storageAccountCredentialName}", pathParameters),
   188  		autorest.WithQueryParameters(queryParameters))
   189  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   190  }
   191  
   192  // DeleteSender sends the Delete request. The method will close the
   193  // http.Response Body if it receives an error.
   194  func (client StorageAccountCredentialsClient) DeleteSender(req *http.Request) (future StorageAccountCredentialsDeleteFuture, err error) {
   195  	var resp *http.Response
   196  	future.FutureAPI = &azure.Future{}
   197  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   198  	if err != nil {
   199  		return
   200  	}
   201  	var azf azure.Future
   202  	azf, err = azure.NewFutureFromResponse(resp)
   203  	future.FutureAPI = &azf
   204  	future.Result = future.result
   205  	return
   206  }
   207  
   208  // DeleteResponder handles the response to the Delete request. The method always
   209  // closes the http.Response Body.
   210  func (client StorageAccountCredentialsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   211  	err = autorest.Respond(
   212  		resp,
   213  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   214  		autorest.ByClosing())
   215  	result.Response = resp
   216  	return
   217  }
   218  
   219  // Get gets the properties of the specified storage account credential name.
   220  // Parameters:
   221  // storageAccountCredentialName - the name of storage account credential to be fetched.
   222  // resourceGroupName - the resource group name
   223  // managerName - the manager name
   224  func (client StorageAccountCredentialsClient) Get(ctx context.Context, storageAccountCredentialName string, resourceGroupName string, managerName string) (result StorageAccountCredential, err error) {
   225  	if tracing.IsEnabled() {
   226  		ctx = tracing.StartSpan(ctx, fqdn+"/StorageAccountCredentialsClient.Get")
   227  		defer func() {
   228  			sc := -1
   229  			if result.Response.Response != nil {
   230  				sc = result.Response.Response.StatusCode
   231  			}
   232  			tracing.EndSpan(ctx, sc, err)
   233  		}()
   234  	}
   235  	if err := validation.Validate([]validation.Validation{
   236  		{TargetValue: managerName,
   237  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   238  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   239  		return result, validation.NewError("storsimple.StorageAccountCredentialsClient", "Get", err.Error())
   240  	}
   241  
   242  	req, err := client.GetPreparer(ctx, storageAccountCredentialName, resourceGroupName, managerName)
   243  	if err != nil {
   244  		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "Get", nil, "Failure preparing request")
   245  		return
   246  	}
   247  
   248  	resp, err := client.GetSender(req)
   249  	if err != nil {
   250  		result.Response = autorest.Response{Response: resp}
   251  		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "Get", resp, "Failure sending request")
   252  		return
   253  	}
   254  
   255  	result, err = client.GetResponder(resp)
   256  	if err != nil {
   257  		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "Get", resp, "Failure responding to request")
   258  		return
   259  	}
   260  
   261  	return
   262  }
   263  
   264  // GetPreparer prepares the Get request.
   265  func (client StorageAccountCredentialsClient) GetPreparer(ctx context.Context, storageAccountCredentialName string, resourceGroupName string, managerName string) (*http.Request, error) {
   266  	pathParameters := map[string]interface{}{
   267  		"managerName":                  managerName,
   268  		"resourceGroupName":            resourceGroupName,
   269  		"storageAccountCredentialName": storageAccountCredentialName,
   270  		"subscriptionId":               client.SubscriptionID,
   271  	}
   272  
   273  	const APIVersion = "2017-06-01"
   274  	queryParameters := map[string]interface{}{
   275  		"api-version": APIVersion,
   276  	}
   277  
   278  	preparer := autorest.CreatePreparer(
   279  		autorest.AsGet(),
   280  		autorest.WithBaseURL(client.BaseURI),
   281  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/storageAccountCredentials/{storageAccountCredentialName}", pathParameters),
   282  		autorest.WithQueryParameters(queryParameters))
   283  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   284  }
   285  
   286  // GetSender sends the Get request. The method will close the
   287  // http.Response Body if it receives an error.
   288  func (client StorageAccountCredentialsClient) GetSender(req *http.Request) (*http.Response, error) {
   289  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   290  }
   291  
   292  // GetResponder handles the response to the Get request. The method always
   293  // closes the http.Response Body.
   294  func (client StorageAccountCredentialsClient) GetResponder(resp *http.Response) (result StorageAccountCredential, err error) {
   295  	err = autorest.Respond(
   296  		resp,
   297  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   298  		autorest.ByUnmarshallingJSON(&result),
   299  		autorest.ByClosing())
   300  	result.Response = autorest.Response{Response: resp}
   301  	return
   302  }
   303  
   304  // ListByManager gets all the storage account credentials in a manager.
   305  // Parameters:
   306  // resourceGroupName - the resource group name
   307  // managerName - the manager name
   308  func (client StorageAccountCredentialsClient) ListByManager(ctx context.Context, resourceGroupName string, managerName string) (result StorageAccountCredentialList, err error) {
   309  	if tracing.IsEnabled() {
   310  		ctx = tracing.StartSpan(ctx, fqdn+"/StorageAccountCredentialsClient.ListByManager")
   311  		defer func() {
   312  			sc := -1
   313  			if result.Response.Response != nil {
   314  				sc = result.Response.Response.StatusCode
   315  			}
   316  			tracing.EndSpan(ctx, sc, err)
   317  		}()
   318  	}
   319  	if err := validation.Validate([]validation.Validation{
   320  		{TargetValue: managerName,
   321  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   322  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   323  		return result, validation.NewError("storsimple.StorageAccountCredentialsClient", "ListByManager", err.Error())
   324  	}
   325  
   326  	req, err := client.ListByManagerPreparer(ctx, resourceGroupName, managerName)
   327  	if err != nil {
   328  		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "ListByManager", nil, "Failure preparing request")
   329  		return
   330  	}
   331  
   332  	resp, err := client.ListByManagerSender(req)
   333  	if err != nil {
   334  		result.Response = autorest.Response{Response: resp}
   335  		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "ListByManager", resp, "Failure sending request")
   336  		return
   337  	}
   338  
   339  	result, err = client.ListByManagerResponder(resp)
   340  	if err != nil {
   341  		err = autorest.NewErrorWithError(err, "storsimple.StorageAccountCredentialsClient", "ListByManager", resp, "Failure responding to request")
   342  		return
   343  	}
   344  
   345  	return
   346  }
   347  
   348  // ListByManagerPreparer prepares the ListByManager request.
   349  func (client StorageAccountCredentialsClient) ListByManagerPreparer(ctx context.Context, resourceGroupName string, managerName string) (*http.Request, error) {
   350  	pathParameters := map[string]interface{}{
   351  		"managerName":       managerName,
   352  		"resourceGroupName": resourceGroupName,
   353  		"subscriptionId":    client.SubscriptionID,
   354  	}
   355  
   356  	const APIVersion = "2017-06-01"
   357  	queryParameters := map[string]interface{}{
   358  		"api-version": APIVersion,
   359  	}
   360  
   361  	preparer := autorest.CreatePreparer(
   362  		autorest.AsGet(),
   363  		autorest.WithBaseURL(client.BaseURI),
   364  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/storageAccountCredentials", pathParameters),
   365  		autorest.WithQueryParameters(queryParameters))
   366  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   367  }
   368  
   369  // ListByManagerSender sends the ListByManager request. The method will close the
   370  // http.Response Body if it receives an error.
   371  func (client StorageAccountCredentialsClient) ListByManagerSender(req *http.Request) (*http.Response, error) {
   372  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   373  }
   374  
   375  // ListByManagerResponder handles the response to the ListByManager request. The method always
   376  // closes the http.Response Body.
   377  func (client StorageAccountCredentialsClient) ListByManagerResponder(resp *http.Response) (result StorageAccountCredentialList, err error) {
   378  	err = autorest.Respond(
   379  		resp,
   380  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   381  		autorest.ByUnmarshallingJSON(&result),
   382  		autorest.ByClosing())
   383  	result.Response = autorest.Response{Response: resp}
   384  	return
   385  }
   386  

View as plain text