...

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

View as plain text