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