...

Source file src/github.com/Azure/azure-sdk-for-go/services/storsimple1200series/mgmt/2016-10-01/storsimple/storageaccountcredentials.go

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

View as plain text