...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2019-06-01-preview/templatespecs/versions.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2019-06-01-preview/templatespecs

     1  package templatespecs
     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  // VersionsClient is the the APIs listed in this specification can be used to manage Template Spec resources through
    19  // the Azure Resource Manager.
    20  type VersionsClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewVersionsClient creates an instance of the VersionsClient client.
    25  func NewVersionsClient(subscriptionID string) VersionsClient {
    26  	return NewVersionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    27  }
    28  
    29  // NewVersionsClientWithBaseURI creates an instance of the VersionsClient client using a custom endpoint.  Use this
    30  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    31  func NewVersionsClientWithBaseURI(baseURI string, subscriptionID string) VersionsClient {
    32  	return VersionsClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // CreateOrUpdate creates or updates a Template Spec version.
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group. The name is case insensitive.
    38  // templateSpecName - name of the Template Spec.
    39  // templateSpecVersion - the version of the Template Spec.
    40  // templateSpecVersionModel - template Spec Version supplied to the operation.
    41  func (client VersionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpecVersion string, templateSpecVersionModel VersionTemplatespecs) (result VersionTemplatespecs, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/VersionsClient.CreateOrUpdate")
    44  		defer func() {
    45  			sc := -1
    46  			if result.Response.Response != nil {
    47  				sc = result.Response.Response.StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	if err := validation.Validate([]validation.Validation{
    53  		{TargetValue: resourceGroupName,
    54  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    55  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
    56  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
    57  		{TargetValue: templateSpecName,
    58  			Constraints: []validation.Constraint{{Target: "templateSpecName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    59  				{Target: "templateSpecName", Name: validation.MinLength, Rule: 1, Chain: nil},
    60  				{Target: "templateSpecName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
    61  		{TargetValue: templateSpecVersion,
    62  			Constraints: []validation.Constraint{{Target: "templateSpecVersion", Name: validation.MaxLength, Rule: 90, Chain: nil},
    63  				{Target: "templateSpecVersion", Name: validation.MinLength, Rule: 1, Chain: nil},
    64  				{Target: "templateSpecVersion", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
    65  		{TargetValue: templateSpecVersionModel,
    66  			Constraints: []validation.Constraint{{Target: "templateSpecVersionModel.Location", Name: validation.Null, Rule: true, Chain: nil},
    67  				{Target: "templateSpecVersionModel.VersionProperties", Name: validation.Null, Rule: true,
    68  					Chain: []validation.Constraint{{Target: "templateSpecVersionModel.VersionProperties.Description", Name: validation.Null, Rule: false,
    69  						Chain: []validation.Constraint{{Target: "templateSpecVersionModel.VersionProperties.Description", Name: validation.MaxLength, Rule: 4096, Chain: nil}}},
    70  					}}}}}); err != nil {
    71  		return result, validation.NewError("templatespecs.VersionsClient", "CreateOrUpdate", err.Error())
    72  	}
    73  
    74  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, templateSpecName, templateSpecVersion, templateSpecVersionModel)
    75  	if err != nil {
    76  		err = autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "CreateOrUpdate", nil, "Failure preparing request")
    77  		return
    78  	}
    79  
    80  	resp, err := client.CreateOrUpdateSender(req)
    81  	if err != nil {
    82  		result.Response = autorest.Response{Response: resp}
    83  		err = autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "CreateOrUpdate", resp, "Failure sending request")
    84  		return
    85  	}
    86  
    87  	result, err = client.CreateOrUpdateResponder(resp)
    88  	if err != nil {
    89  		err = autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "CreateOrUpdate", resp, "Failure responding to request")
    90  		return
    91  	}
    92  
    93  	return
    94  }
    95  
    96  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    97  func (client VersionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpecVersion string, templateSpecVersionModel VersionTemplatespecs) (*http.Request, error) {
    98  	pathParameters := map[string]interface{}{
    99  		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
   100  		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
   101  		"templateSpecName":    autorest.Encode("path", templateSpecName),
   102  		"templateSpecVersion": autorest.Encode("path", templateSpecVersion),
   103  	}
   104  
   105  	const APIVersion = "2019-06-01-preview"
   106  	queryParameters := map[string]interface{}{
   107  		"api-version": APIVersion,
   108  	}
   109  
   110  	preparer := autorest.CreatePreparer(
   111  		autorest.AsContentType("application/json; charset=utf-8"),
   112  		autorest.AsPut(),
   113  		autorest.WithBaseURL(client.BaseURI),
   114  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Resources/templateSpecs/{templateSpecName}/versions/{templateSpecVersion}", pathParameters),
   115  		autorest.WithJSON(templateSpecVersionModel),
   116  		autorest.WithQueryParameters(queryParameters))
   117  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   118  }
   119  
   120  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   121  // http.Response Body if it receives an error.
   122  func (client VersionsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   123  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   124  }
   125  
   126  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   127  // closes the http.Response Body.
   128  func (client VersionsClient) CreateOrUpdateResponder(resp *http.Response) (result VersionTemplatespecs, err error) {
   129  	err = autorest.Respond(
   130  		resp,
   131  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   132  		autorest.ByUnmarshallingJSON(&result),
   133  		autorest.ByClosing())
   134  	result.Response = autorest.Response{Response: resp}
   135  	return
   136  }
   137  
   138  // Delete deletes a specific version from a Template Spec. When operation completes, status code 200 returned without
   139  // content.
   140  // Parameters:
   141  // resourceGroupName - the name of the resource group. The name is case insensitive.
   142  // templateSpecName - name of the Template Spec.
   143  // templateSpecVersion - the version of the Template Spec.
   144  func (client VersionsClient) Delete(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpecVersion string) (result autorest.Response, err error) {
   145  	if tracing.IsEnabled() {
   146  		ctx = tracing.StartSpan(ctx, fqdn+"/VersionsClient.Delete")
   147  		defer func() {
   148  			sc := -1
   149  			if result.Response != nil {
   150  				sc = result.Response.StatusCode
   151  			}
   152  			tracing.EndSpan(ctx, sc, err)
   153  		}()
   154  	}
   155  	if err := validation.Validate([]validation.Validation{
   156  		{TargetValue: resourceGroupName,
   157  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   158  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   159  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   160  		{TargetValue: templateSpecName,
   161  			Constraints: []validation.Constraint{{Target: "templateSpecName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   162  				{Target: "templateSpecName", Name: validation.MinLength, Rule: 1, Chain: nil},
   163  				{Target: "templateSpecName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   164  		{TargetValue: templateSpecVersion,
   165  			Constraints: []validation.Constraint{{Target: "templateSpecVersion", Name: validation.MaxLength, Rule: 90, Chain: nil},
   166  				{Target: "templateSpecVersion", Name: validation.MinLength, Rule: 1, Chain: nil},
   167  				{Target: "templateSpecVersion", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   168  		return result, validation.NewError("templatespecs.VersionsClient", "Delete", err.Error())
   169  	}
   170  
   171  	req, err := client.DeletePreparer(ctx, resourceGroupName, templateSpecName, templateSpecVersion)
   172  	if err != nil {
   173  		err = autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "Delete", nil, "Failure preparing request")
   174  		return
   175  	}
   176  
   177  	resp, err := client.DeleteSender(req)
   178  	if err != nil {
   179  		result.Response = resp
   180  		err = autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "Delete", resp, "Failure sending request")
   181  		return
   182  	}
   183  
   184  	result, err = client.DeleteResponder(resp)
   185  	if err != nil {
   186  		err = autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "Delete", resp, "Failure responding to request")
   187  		return
   188  	}
   189  
   190  	return
   191  }
   192  
   193  // DeletePreparer prepares the Delete request.
   194  func (client VersionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpecVersion string) (*http.Request, error) {
   195  	pathParameters := map[string]interface{}{
   196  		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
   197  		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
   198  		"templateSpecName":    autorest.Encode("path", templateSpecName),
   199  		"templateSpecVersion": autorest.Encode("path", templateSpecVersion),
   200  	}
   201  
   202  	const APIVersion = "2019-06-01-preview"
   203  	queryParameters := map[string]interface{}{
   204  		"api-version": APIVersion,
   205  	}
   206  
   207  	preparer := autorest.CreatePreparer(
   208  		autorest.AsDelete(),
   209  		autorest.WithBaseURL(client.BaseURI),
   210  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Resources/templateSpecs/{templateSpecName}/versions/{templateSpecVersion}", pathParameters),
   211  		autorest.WithQueryParameters(queryParameters))
   212  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   213  }
   214  
   215  // DeleteSender sends the Delete request. The method will close the
   216  // http.Response Body if it receives an error.
   217  func (client VersionsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   218  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   219  }
   220  
   221  // DeleteResponder handles the response to the Delete request. The method always
   222  // closes the http.Response Body.
   223  func (client VersionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   224  	err = autorest.Respond(
   225  		resp,
   226  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   227  		autorest.ByClosing())
   228  	result.Response = resp
   229  	return
   230  }
   231  
   232  // Get gets a Template Spec version from a specific Template Spec.
   233  // Parameters:
   234  // resourceGroupName - the name of the resource group. The name is case insensitive.
   235  // templateSpecName - name of the Template Spec.
   236  // templateSpecVersion - the version of the Template Spec.
   237  func (client VersionsClient) Get(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpecVersion string) (result VersionTemplatespecs, err error) {
   238  	if tracing.IsEnabled() {
   239  		ctx = tracing.StartSpan(ctx, fqdn+"/VersionsClient.Get")
   240  		defer func() {
   241  			sc := -1
   242  			if result.Response.Response != nil {
   243  				sc = result.Response.Response.StatusCode
   244  			}
   245  			tracing.EndSpan(ctx, sc, err)
   246  		}()
   247  	}
   248  	if err := validation.Validate([]validation.Validation{
   249  		{TargetValue: resourceGroupName,
   250  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   251  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   252  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   253  		{TargetValue: templateSpecName,
   254  			Constraints: []validation.Constraint{{Target: "templateSpecName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   255  				{Target: "templateSpecName", Name: validation.MinLength, Rule: 1, Chain: nil},
   256  				{Target: "templateSpecName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   257  		{TargetValue: templateSpecVersion,
   258  			Constraints: []validation.Constraint{{Target: "templateSpecVersion", Name: validation.MaxLength, Rule: 90, Chain: nil},
   259  				{Target: "templateSpecVersion", Name: validation.MinLength, Rule: 1, Chain: nil},
   260  				{Target: "templateSpecVersion", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   261  		return result, validation.NewError("templatespecs.VersionsClient", "Get", err.Error())
   262  	}
   263  
   264  	req, err := client.GetPreparer(ctx, resourceGroupName, templateSpecName, templateSpecVersion)
   265  	if err != nil {
   266  		err = autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "Get", nil, "Failure preparing request")
   267  		return
   268  	}
   269  
   270  	resp, err := client.GetSender(req)
   271  	if err != nil {
   272  		result.Response = autorest.Response{Response: resp}
   273  		err = autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "Get", resp, "Failure sending request")
   274  		return
   275  	}
   276  
   277  	result, err = client.GetResponder(resp)
   278  	if err != nil {
   279  		err = autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "Get", resp, "Failure responding to request")
   280  		return
   281  	}
   282  
   283  	return
   284  }
   285  
   286  // GetPreparer prepares the Get request.
   287  func (client VersionsClient) GetPreparer(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpecVersion string) (*http.Request, error) {
   288  	pathParameters := map[string]interface{}{
   289  		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
   290  		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
   291  		"templateSpecName":    autorest.Encode("path", templateSpecName),
   292  		"templateSpecVersion": autorest.Encode("path", templateSpecVersion),
   293  	}
   294  
   295  	const APIVersion = "2019-06-01-preview"
   296  	queryParameters := map[string]interface{}{
   297  		"api-version": APIVersion,
   298  	}
   299  
   300  	preparer := autorest.CreatePreparer(
   301  		autorest.AsGet(),
   302  		autorest.WithBaseURL(client.BaseURI),
   303  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Resources/templateSpecs/{templateSpecName}/versions/{templateSpecVersion}", pathParameters),
   304  		autorest.WithQueryParameters(queryParameters))
   305  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   306  }
   307  
   308  // GetSender sends the Get request. The method will close the
   309  // http.Response Body if it receives an error.
   310  func (client VersionsClient) GetSender(req *http.Request) (*http.Response, error) {
   311  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   312  }
   313  
   314  // GetResponder handles the response to the Get request. The method always
   315  // closes the http.Response Body.
   316  func (client VersionsClient) GetResponder(resp *http.Response) (result VersionTemplatespecs, err error) {
   317  	err = autorest.Respond(
   318  		resp,
   319  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   320  		autorest.ByUnmarshallingJSON(&result),
   321  		autorest.ByClosing())
   322  	result.Response = autorest.Response{Response: resp}
   323  	return
   324  }
   325  
   326  // List lists all the Template Spec versions in the specified Template Spec.
   327  // Parameters:
   328  // resourceGroupName - the name of the resource group. The name is case insensitive.
   329  // templateSpecName - name of the Template Spec.
   330  func (client VersionsClient) List(ctx context.Context, resourceGroupName string, templateSpecName string) (result VersionsListResultPage, err error) {
   331  	if tracing.IsEnabled() {
   332  		ctx = tracing.StartSpan(ctx, fqdn+"/VersionsClient.List")
   333  		defer func() {
   334  			sc := -1
   335  			if result.vlr.Response.Response != nil {
   336  				sc = result.vlr.Response.Response.StatusCode
   337  			}
   338  			tracing.EndSpan(ctx, sc, err)
   339  		}()
   340  	}
   341  	if err := validation.Validate([]validation.Validation{
   342  		{TargetValue: resourceGroupName,
   343  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   344  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   345  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   346  		{TargetValue: templateSpecName,
   347  			Constraints: []validation.Constraint{{Target: "templateSpecName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   348  				{Target: "templateSpecName", Name: validation.MinLength, Rule: 1, Chain: nil},
   349  				{Target: "templateSpecName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   350  		return result, validation.NewError("templatespecs.VersionsClient", "List", err.Error())
   351  	}
   352  
   353  	result.fn = client.listNextResults
   354  	req, err := client.ListPreparer(ctx, resourceGroupName, templateSpecName)
   355  	if err != nil {
   356  		err = autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "List", nil, "Failure preparing request")
   357  		return
   358  	}
   359  
   360  	resp, err := client.ListSender(req)
   361  	if err != nil {
   362  		result.vlr.Response = autorest.Response{Response: resp}
   363  		err = autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "List", resp, "Failure sending request")
   364  		return
   365  	}
   366  
   367  	result.vlr, err = client.ListResponder(resp)
   368  	if err != nil {
   369  		err = autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "List", resp, "Failure responding to request")
   370  		return
   371  	}
   372  	if result.vlr.hasNextLink() && result.vlr.IsEmpty() {
   373  		err = result.NextWithContext(ctx)
   374  		return
   375  	}
   376  
   377  	return
   378  }
   379  
   380  // ListPreparer prepares the List request.
   381  func (client VersionsClient) ListPreparer(ctx context.Context, resourceGroupName string, templateSpecName string) (*http.Request, error) {
   382  	pathParameters := map[string]interface{}{
   383  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   384  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   385  		"templateSpecName":  autorest.Encode("path", templateSpecName),
   386  	}
   387  
   388  	const APIVersion = "2019-06-01-preview"
   389  	queryParameters := map[string]interface{}{
   390  		"api-version": APIVersion,
   391  	}
   392  
   393  	preparer := autorest.CreatePreparer(
   394  		autorest.AsGet(),
   395  		autorest.WithBaseURL(client.BaseURI),
   396  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Resources/templateSpecs/{templateSpecName}/versions", pathParameters),
   397  		autorest.WithQueryParameters(queryParameters))
   398  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   399  }
   400  
   401  // ListSender sends the List request. The method will close the
   402  // http.Response Body if it receives an error.
   403  func (client VersionsClient) ListSender(req *http.Request) (*http.Response, error) {
   404  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   405  }
   406  
   407  // ListResponder handles the response to the List request. The method always
   408  // closes the http.Response Body.
   409  func (client VersionsClient) ListResponder(resp *http.Response) (result VersionsListResult, err error) {
   410  	err = autorest.Respond(
   411  		resp,
   412  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   413  		autorest.ByUnmarshallingJSON(&result),
   414  		autorest.ByClosing())
   415  	result.Response = autorest.Response{Response: resp}
   416  	return
   417  }
   418  
   419  // listNextResults retrieves the next set of results, if any.
   420  func (client VersionsClient) listNextResults(ctx context.Context, lastResults VersionsListResult) (result VersionsListResult, err error) {
   421  	req, err := lastResults.versionsListResultPreparer(ctx)
   422  	if err != nil {
   423  		return result, autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "listNextResults", nil, "Failure preparing next results request")
   424  	}
   425  	if req == nil {
   426  		return
   427  	}
   428  	resp, err := client.ListSender(req)
   429  	if err != nil {
   430  		result.Response = autorest.Response{Response: resp}
   431  		return result, autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "listNextResults", resp, "Failure sending next results request")
   432  	}
   433  	result, err = client.ListResponder(resp)
   434  	if err != nil {
   435  		err = autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "listNextResults", resp, "Failure responding to next results request")
   436  	}
   437  	return
   438  }
   439  
   440  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   441  func (client VersionsClient) ListComplete(ctx context.Context, resourceGroupName string, templateSpecName string) (result VersionsListResultIterator, err error) {
   442  	if tracing.IsEnabled() {
   443  		ctx = tracing.StartSpan(ctx, fqdn+"/VersionsClient.List")
   444  		defer func() {
   445  			sc := -1
   446  			if result.Response().Response.Response != nil {
   447  				sc = result.page.Response().Response.Response.StatusCode
   448  			}
   449  			tracing.EndSpan(ctx, sc, err)
   450  		}()
   451  	}
   452  	result.page, err = client.List(ctx, resourceGroupName, templateSpecName)
   453  	return
   454  }
   455  
   456  // Update updates Template Spec Version tags with specified values.
   457  // Parameters:
   458  // resourceGroupName - the name of the resource group. The name is case insensitive.
   459  // templateSpecName - name of the Template Spec.
   460  // templateSpecVersion - the version of the Template Spec.
   461  // templateSpecVersionUpdateModel - template Spec Version resource with the tags to be updated.
   462  func (client VersionsClient) Update(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpecVersion string, templateSpecVersionUpdateModel *VersionUpdateModel) (result VersionTemplatespecs, err error) {
   463  	if tracing.IsEnabled() {
   464  		ctx = tracing.StartSpan(ctx, fqdn+"/VersionsClient.Update")
   465  		defer func() {
   466  			sc := -1
   467  			if result.Response.Response != nil {
   468  				sc = result.Response.Response.StatusCode
   469  			}
   470  			tracing.EndSpan(ctx, sc, err)
   471  		}()
   472  	}
   473  	if err := validation.Validate([]validation.Validation{
   474  		{TargetValue: resourceGroupName,
   475  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   476  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   477  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   478  		{TargetValue: templateSpecName,
   479  			Constraints: []validation.Constraint{{Target: "templateSpecName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   480  				{Target: "templateSpecName", Name: validation.MinLength, Rule: 1, Chain: nil},
   481  				{Target: "templateSpecName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   482  		{TargetValue: templateSpecVersion,
   483  			Constraints: []validation.Constraint{{Target: "templateSpecVersion", Name: validation.MaxLength, Rule: 90, Chain: nil},
   484  				{Target: "templateSpecVersion", Name: validation.MinLength, Rule: 1, Chain: nil},
   485  				{Target: "templateSpecVersion", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   486  		return result, validation.NewError("templatespecs.VersionsClient", "Update", err.Error())
   487  	}
   488  
   489  	req, err := client.UpdatePreparer(ctx, resourceGroupName, templateSpecName, templateSpecVersion, templateSpecVersionUpdateModel)
   490  	if err != nil {
   491  		err = autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "Update", nil, "Failure preparing request")
   492  		return
   493  	}
   494  
   495  	resp, err := client.UpdateSender(req)
   496  	if err != nil {
   497  		result.Response = autorest.Response{Response: resp}
   498  		err = autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "Update", resp, "Failure sending request")
   499  		return
   500  	}
   501  
   502  	result, err = client.UpdateResponder(resp)
   503  	if err != nil {
   504  		err = autorest.NewErrorWithError(err, "templatespecs.VersionsClient", "Update", resp, "Failure responding to request")
   505  		return
   506  	}
   507  
   508  	return
   509  }
   510  
   511  // UpdatePreparer prepares the Update request.
   512  func (client VersionsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, templateSpecName string, templateSpecVersion string, templateSpecVersionUpdateModel *VersionUpdateModel) (*http.Request, error) {
   513  	pathParameters := map[string]interface{}{
   514  		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
   515  		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
   516  		"templateSpecName":    autorest.Encode("path", templateSpecName),
   517  		"templateSpecVersion": autorest.Encode("path", templateSpecVersion),
   518  	}
   519  
   520  	const APIVersion = "2019-06-01-preview"
   521  	queryParameters := map[string]interface{}{
   522  		"api-version": APIVersion,
   523  	}
   524  
   525  	preparer := autorest.CreatePreparer(
   526  		autorest.AsContentType("application/json; charset=utf-8"),
   527  		autorest.AsPatch(),
   528  		autorest.WithBaseURL(client.BaseURI),
   529  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Resources/templateSpecs/{templateSpecName}/versions/{templateSpecVersion}", pathParameters),
   530  		autorest.WithQueryParameters(queryParameters))
   531  	if templateSpecVersionUpdateModel != nil {
   532  		preparer = autorest.DecoratePreparer(preparer,
   533  			autorest.WithJSON(templateSpecVersionUpdateModel))
   534  	}
   535  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   536  }
   537  
   538  // UpdateSender sends the Update request. The method will close the
   539  // http.Response Body if it receives an error.
   540  func (client VersionsClient) UpdateSender(req *http.Request) (*http.Response, error) {
   541  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   542  }
   543  
   544  // UpdateResponder handles the response to the Update request. The method always
   545  // closes the http.Response Body.
   546  func (client VersionsClient) UpdateResponder(resp *http.Response) (result VersionTemplatespecs, err error) {
   547  	err = autorest.Respond(
   548  		resp,
   549  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   550  		autorest.ByUnmarshallingJSON(&result),
   551  		autorest.ByClosing())
   552  	result.Response = autorest.Response{Response: resp}
   553  	return
   554  }
   555  

View as plain text