...

Source file src/github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2018-09-15/dtl/secrets.go

Documentation: github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2018-09-15/dtl

     1  package dtl
     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  // SecretsClient is the the DevTest Labs Client.
    19  type SecretsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewSecretsClient creates an instance of the SecretsClient client.
    24  func NewSecretsClient(subscriptionID string) SecretsClient {
    25  	return NewSecretsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewSecretsClientWithBaseURI creates an instance of the SecretsClient client using a custom endpoint.  Use this when
    29  // interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewSecretsClientWithBaseURI(baseURI string, subscriptionID string) SecretsClient {
    31  	return SecretsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate create or replace an existing secret. This operation can take a while to complete.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group.
    37  // labName - the name of the lab.
    38  // userName - the name of the user profile.
    39  // name - the name of the secret.
    40  // secret - a secret.
    41  func (client SecretsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, labName string, userName string, name string, secret Secret) (result SecretsCreateOrUpdateFuture, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/SecretsClient.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: secret,
    54  			Constraints: []validation.Constraint{{Target: "secret.SecretProperties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
    55  		return result, validation.NewError("dtl.SecretsClient", "CreateOrUpdate", err.Error())
    56  	}
    57  
    58  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, labName, userName, name, secret)
    59  	if err != nil {
    60  		err = autorest.NewErrorWithError(err, "dtl.SecretsClient", "CreateOrUpdate", nil, "Failure preparing request")
    61  		return
    62  	}
    63  
    64  	result, err = client.CreateOrUpdateSender(req)
    65  	if err != nil {
    66  		err = autorest.NewErrorWithError(err, "dtl.SecretsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    67  		return
    68  	}
    69  
    70  	return
    71  }
    72  
    73  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    74  func (client SecretsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, labName string, userName string, name string, secret Secret) (*http.Request, error) {
    75  	pathParameters := map[string]interface{}{
    76  		"labName":           autorest.Encode("path", labName),
    77  		"name":              autorest.Encode("path", name),
    78  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    79  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    80  		"userName":          autorest.Encode("path", userName),
    81  	}
    82  
    83  	const APIVersion = "2018-09-15"
    84  	queryParameters := map[string]interface{}{
    85  		"api-version": APIVersion,
    86  	}
    87  
    88  	preparer := autorest.CreatePreparer(
    89  		autorest.AsContentType("application/json; charset=utf-8"),
    90  		autorest.AsPut(),
    91  		autorest.WithBaseURL(client.BaseURI),
    92  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets/{name}", pathParameters),
    93  		autorest.WithJSON(secret),
    94  		autorest.WithQueryParameters(queryParameters))
    95  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    96  }
    97  
    98  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
    99  // http.Response Body if it receives an error.
   100  func (client SecretsClient) CreateOrUpdateSender(req *http.Request) (future SecretsCreateOrUpdateFuture, err error) {
   101  	var resp *http.Response
   102  	future.FutureAPI = &azure.Future{}
   103  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   104  	if err != nil {
   105  		return
   106  	}
   107  	var azf azure.Future
   108  	azf, err = azure.NewFutureFromResponse(resp)
   109  	future.FutureAPI = &azf
   110  	future.Result = future.result
   111  	return
   112  }
   113  
   114  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   115  // closes the http.Response Body.
   116  func (client SecretsClient) CreateOrUpdateResponder(resp *http.Response) (result Secret, err error) {
   117  	err = autorest.Respond(
   118  		resp,
   119  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   120  		autorest.ByUnmarshallingJSON(&result),
   121  		autorest.ByClosing())
   122  	result.Response = autorest.Response{Response: resp}
   123  	return
   124  }
   125  
   126  // Delete delete secret.
   127  // Parameters:
   128  // resourceGroupName - the name of the resource group.
   129  // labName - the name of the lab.
   130  // userName - the name of the user profile.
   131  // name - the name of the secret.
   132  func (client SecretsClient) Delete(ctx context.Context, resourceGroupName string, labName string, userName string, name string) (result autorest.Response, err error) {
   133  	if tracing.IsEnabled() {
   134  		ctx = tracing.StartSpan(ctx, fqdn+"/SecretsClient.Delete")
   135  		defer func() {
   136  			sc := -1
   137  			if result.Response != nil {
   138  				sc = result.Response.StatusCode
   139  			}
   140  			tracing.EndSpan(ctx, sc, err)
   141  		}()
   142  	}
   143  	req, err := client.DeletePreparer(ctx, resourceGroupName, labName, userName, name)
   144  	if err != nil {
   145  		err = autorest.NewErrorWithError(err, "dtl.SecretsClient", "Delete", nil, "Failure preparing request")
   146  		return
   147  	}
   148  
   149  	resp, err := client.DeleteSender(req)
   150  	if err != nil {
   151  		result.Response = resp
   152  		err = autorest.NewErrorWithError(err, "dtl.SecretsClient", "Delete", resp, "Failure sending request")
   153  		return
   154  	}
   155  
   156  	result, err = client.DeleteResponder(resp)
   157  	if err != nil {
   158  		err = autorest.NewErrorWithError(err, "dtl.SecretsClient", "Delete", resp, "Failure responding to request")
   159  		return
   160  	}
   161  
   162  	return
   163  }
   164  
   165  // DeletePreparer prepares the Delete request.
   166  func (client SecretsClient) DeletePreparer(ctx context.Context, resourceGroupName string, labName string, userName string, name string) (*http.Request, error) {
   167  	pathParameters := map[string]interface{}{
   168  		"labName":           autorest.Encode("path", labName),
   169  		"name":              autorest.Encode("path", name),
   170  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   171  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   172  		"userName":          autorest.Encode("path", userName),
   173  	}
   174  
   175  	const APIVersion = "2018-09-15"
   176  	queryParameters := map[string]interface{}{
   177  		"api-version": APIVersion,
   178  	}
   179  
   180  	preparer := autorest.CreatePreparer(
   181  		autorest.AsDelete(),
   182  		autorest.WithBaseURL(client.BaseURI),
   183  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets/{name}", pathParameters),
   184  		autorest.WithQueryParameters(queryParameters))
   185  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   186  }
   187  
   188  // DeleteSender sends the Delete request. The method will close the
   189  // http.Response Body if it receives an error.
   190  func (client SecretsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   191  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   192  }
   193  
   194  // DeleteResponder handles the response to the Delete request. The method always
   195  // closes the http.Response Body.
   196  func (client SecretsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   197  	err = autorest.Respond(
   198  		resp,
   199  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   200  		autorest.ByClosing())
   201  	result.Response = resp
   202  	return
   203  }
   204  
   205  // Get get secret.
   206  // Parameters:
   207  // resourceGroupName - the name of the resource group.
   208  // labName - the name of the lab.
   209  // userName - the name of the user profile.
   210  // name - the name of the secret.
   211  // expand - specify the $expand query. Example: 'properties($select=value)'
   212  func (client SecretsClient) Get(ctx context.Context, resourceGroupName string, labName string, userName string, name string, expand string) (result Secret, err error) {
   213  	if tracing.IsEnabled() {
   214  		ctx = tracing.StartSpan(ctx, fqdn+"/SecretsClient.Get")
   215  		defer func() {
   216  			sc := -1
   217  			if result.Response.Response != nil {
   218  				sc = result.Response.Response.StatusCode
   219  			}
   220  			tracing.EndSpan(ctx, sc, err)
   221  		}()
   222  	}
   223  	req, err := client.GetPreparer(ctx, resourceGroupName, labName, userName, name, expand)
   224  	if err != nil {
   225  		err = autorest.NewErrorWithError(err, "dtl.SecretsClient", "Get", nil, "Failure preparing request")
   226  		return
   227  	}
   228  
   229  	resp, err := client.GetSender(req)
   230  	if err != nil {
   231  		result.Response = autorest.Response{Response: resp}
   232  		err = autorest.NewErrorWithError(err, "dtl.SecretsClient", "Get", resp, "Failure sending request")
   233  		return
   234  	}
   235  
   236  	result, err = client.GetResponder(resp)
   237  	if err != nil {
   238  		err = autorest.NewErrorWithError(err, "dtl.SecretsClient", "Get", resp, "Failure responding to request")
   239  		return
   240  	}
   241  
   242  	return
   243  }
   244  
   245  // GetPreparer prepares the Get request.
   246  func (client SecretsClient) GetPreparer(ctx context.Context, resourceGroupName string, labName string, userName string, name string, expand string) (*http.Request, error) {
   247  	pathParameters := map[string]interface{}{
   248  		"labName":           autorest.Encode("path", labName),
   249  		"name":              autorest.Encode("path", name),
   250  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   251  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   252  		"userName":          autorest.Encode("path", userName),
   253  	}
   254  
   255  	const APIVersion = "2018-09-15"
   256  	queryParameters := map[string]interface{}{
   257  		"api-version": APIVersion,
   258  	}
   259  	if len(expand) > 0 {
   260  		queryParameters["$expand"] = autorest.Encode("query", expand)
   261  	}
   262  
   263  	preparer := autorest.CreatePreparer(
   264  		autorest.AsGet(),
   265  		autorest.WithBaseURL(client.BaseURI),
   266  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets/{name}", pathParameters),
   267  		autorest.WithQueryParameters(queryParameters))
   268  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   269  }
   270  
   271  // GetSender sends the Get request. The method will close the
   272  // http.Response Body if it receives an error.
   273  func (client SecretsClient) GetSender(req *http.Request) (*http.Response, error) {
   274  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   275  }
   276  
   277  // GetResponder handles the response to the Get request. The method always
   278  // closes the http.Response Body.
   279  func (client SecretsClient) GetResponder(resp *http.Response) (result Secret, err error) {
   280  	err = autorest.Respond(
   281  		resp,
   282  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   283  		autorest.ByUnmarshallingJSON(&result),
   284  		autorest.ByClosing())
   285  	result.Response = autorest.Response{Response: resp}
   286  	return
   287  }
   288  
   289  // List list secrets in a given user profile.
   290  // Parameters:
   291  // resourceGroupName - the name of the resource group.
   292  // labName - the name of the lab.
   293  // userName - the name of the user profile.
   294  // expand - specify the $expand query. Example: 'properties($select=value)'
   295  // filter - the filter to apply to the operation. Example: '$filter=contains(name,'myName')
   296  // top - the maximum number of resources to return from the operation. Example: '$top=10'
   297  // orderby - the ordering expression for the results, using OData notation. Example: '$orderby=name desc'
   298  func (client SecretsClient) List(ctx context.Context, resourceGroupName string, labName string, userName string, expand string, filter string, top *int32, orderby string) (result SecretListPage, err error) {
   299  	if tracing.IsEnabled() {
   300  		ctx = tracing.StartSpan(ctx, fqdn+"/SecretsClient.List")
   301  		defer func() {
   302  			sc := -1
   303  			if result.sl.Response.Response != nil {
   304  				sc = result.sl.Response.Response.StatusCode
   305  			}
   306  			tracing.EndSpan(ctx, sc, err)
   307  		}()
   308  	}
   309  	result.fn = client.listNextResults
   310  	req, err := client.ListPreparer(ctx, resourceGroupName, labName, userName, expand, filter, top, orderby)
   311  	if err != nil {
   312  		err = autorest.NewErrorWithError(err, "dtl.SecretsClient", "List", nil, "Failure preparing request")
   313  		return
   314  	}
   315  
   316  	resp, err := client.ListSender(req)
   317  	if err != nil {
   318  		result.sl.Response = autorest.Response{Response: resp}
   319  		err = autorest.NewErrorWithError(err, "dtl.SecretsClient", "List", resp, "Failure sending request")
   320  		return
   321  	}
   322  
   323  	result.sl, err = client.ListResponder(resp)
   324  	if err != nil {
   325  		err = autorest.NewErrorWithError(err, "dtl.SecretsClient", "List", resp, "Failure responding to request")
   326  		return
   327  	}
   328  	if result.sl.hasNextLink() && result.sl.IsEmpty() {
   329  		err = result.NextWithContext(ctx)
   330  		return
   331  	}
   332  
   333  	return
   334  }
   335  
   336  // ListPreparer prepares the List request.
   337  func (client SecretsClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, userName string, expand string, filter string, top *int32, orderby string) (*http.Request, error) {
   338  	pathParameters := map[string]interface{}{
   339  		"labName":           autorest.Encode("path", labName),
   340  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   341  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   342  		"userName":          autorest.Encode("path", userName),
   343  	}
   344  
   345  	const APIVersion = "2018-09-15"
   346  	queryParameters := map[string]interface{}{
   347  		"api-version": APIVersion,
   348  	}
   349  	if len(expand) > 0 {
   350  		queryParameters["$expand"] = autorest.Encode("query", expand)
   351  	}
   352  	if len(filter) > 0 {
   353  		queryParameters["$filter"] = autorest.Encode("query", filter)
   354  	}
   355  	if top != nil {
   356  		queryParameters["$top"] = autorest.Encode("query", *top)
   357  	}
   358  	if len(orderby) > 0 {
   359  		queryParameters["$orderby"] = autorest.Encode("query", orderby)
   360  	}
   361  
   362  	preparer := autorest.CreatePreparer(
   363  		autorest.AsGet(),
   364  		autorest.WithBaseURL(client.BaseURI),
   365  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets", pathParameters),
   366  		autorest.WithQueryParameters(queryParameters))
   367  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   368  }
   369  
   370  // ListSender sends the List request. The method will close the
   371  // http.Response Body if it receives an error.
   372  func (client SecretsClient) ListSender(req *http.Request) (*http.Response, error) {
   373  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   374  }
   375  
   376  // ListResponder handles the response to the List request. The method always
   377  // closes the http.Response Body.
   378  func (client SecretsClient) ListResponder(resp *http.Response) (result SecretList, 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  
   388  // listNextResults retrieves the next set of results, if any.
   389  func (client SecretsClient) listNextResults(ctx context.Context, lastResults SecretList) (result SecretList, err error) {
   390  	req, err := lastResults.secretListPreparer(ctx)
   391  	if err != nil {
   392  		return result, autorest.NewErrorWithError(err, "dtl.SecretsClient", "listNextResults", nil, "Failure preparing next results request")
   393  	}
   394  	if req == nil {
   395  		return
   396  	}
   397  	resp, err := client.ListSender(req)
   398  	if err != nil {
   399  		result.Response = autorest.Response{Response: resp}
   400  		return result, autorest.NewErrorWithError(err, "dtl.SecretsClient", "listNextResults", resp, "Failure sending next results request")
   401  	}
   402  	result, err = client.ListResponder(resp)
   403  	if err != nil {
   404  		err = autorest.NewErrorWithError(err, "dtl.SecretsClient", "listNextResults", resp, "Failure responding to next results request")
   405  	}
   406  	return
   407  }
   408  
   409  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   410  func (client SecretsClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, userName string, expand string, filter string, top *int32, orderby string) (result SecretListIterator, err error) {
   411  	if tracing.IsEnabled() {
   412  		ctx = tracing.StartSpan(ctx, fqdn+"/SecretsClient.List")
   413  		defer func() {
   414  			sc := -1
   415  			if result.Response().Response.Response != nil {
   416  				sc = result.page.Response().Response.Response.StatusCode
   417  			}
   418  			tracing.EndSpan(ctx, sc, err)
   419  		}()
   420  	}
   421  	result.page, err = client.List(ctx, resourceGroupName, labName, userName, expand, filter, top, orderby)
   422  	return
   423  }
   424  
   425  // Update allows modifying tags of secrets. All other properties will be ignored.
   426  // Parameters:
   427  // resourceGroupName - the name of the resource group.
   428  // labName - the name of the lab.
   429  // userName - the name of the user profile.
   430  // name - the name of the secret.
   431  // secret - a secret.
   432  func (client SecretsClient) Update(ctx context.Context, resourceGroupName string, labName string, userName string, name string, secret SecretFragment) (result Secret, err error) {
   433  	if tracing.IsEnabled() {
   434  		ctx = tracing.StartSpan(ctx, fqdn+"/SecretsClient.Update")
   435  		defer func() {
   436  			sc := -1
   437  			if result.Response.Response != nil {
   438  				sc = result.Response.Response.StatusCode
   439  			}
   440  			tracing.EndSpan(ctx, sc, err)
   441  		}()
   442  	}
   443  	req, err := client.UpdatePreparer(ctx, resourceGroupName, labName, userName, name, secret)
   444  	if err != nil {
   445  		err = autorest.NewErrorWithError(err, "dtl.SecretsClient", "Update", nil, "Failure preparing request")
   446  		return
   447  	}
   448  
   449  	resp, err := client.UpdateSender(req)
   450  	if err != nil {
   451  		result.Response = autorest.Response{Response: resp}
   452  		err = autorest.NewErrorWithError(err, "dtl.SecretsClient", "Update", resp, "Failure sending request")
   453  		return
   454  	}
   455  
   456  	result, err = client.UpdateResponder(resp)
   457  	if err != nil {
   458  		err = autorest.NewErrorWithError(err, "dtl.SecretsClient", "Update", resp, "Failure responding to request")
   459  		return
   460  	}
   461  
   462  	return
   463  }
   464  
   465  // UpdatePreparer prepares the Update request.
   466  func (client SecretsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, labName string, userName string, name string, secret SecretFragment) (*http.Request, error) {
   467  	pathParameters := map[string]interface{}{
   468  		"labName":           autorest.Encode("path", labName),
   469  		"name":              autorest.Encode("path", name),
   470  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   471  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   472  		"userName":          autorest.Encode("path", userName),
   473  	}
   474  
   475  	const APIVersion = "2018-09-15"
   476  	queryParameters := map[string]interface{}{
   477  		"api-version": APIVersion,
   478  	}
   479  
   480  	preparer := autorest.CreatePreparer(
   481  		autorest.AsContentType("application/json; charset=utf-8"),
   482  		autorest.AsPatch(),
   483  		autorest.WithBaseURL(client.BaseURI),
   484  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets/{name}", pathParameters),
   485  		autorest.WithJSON(secret),
   486  		autorest.WithQueryParameters(queryParameters))
   487  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   488  }
   489  
   490  // UpdateSender sends the Update request. The method will close the
   491  // http.Response Body if it receives an error.
   492  func (client SecretsClient) UpdateSender(req *http.Request) (*http.Response, error) {
   493  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   494  }
   495  
   496  // UpdateResponder handles the response to the Update request. The method always
   497  // closes the http.Response Body.
   498  func (client SecretsClient) UpdateResponder(resp *http.Response) (result Secret, err error) {
   499  	err = autorest.Respond(
   500  		resp,
   501  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   502  		autorest.ByUnmarshallingJSON(&result),
   503  		autorest.ByClosing())
   504  	result.Response = autorest.Response{Response: resp}
   505  	return
   506  }
   507  

View as plain text