...

Source file src/github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-07-01/features/resourcegroups.go

Documentation: github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-07-01/features

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

View as plain text