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// Client is the provides operations for working with resources and resource groups. 30type Client struct { 31 BaseClient 32} 33 34// NewClient creates an instance of the Client client. 35func NewClient(subscriptionID string) Client { 36 return NewClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewClientWithBaseURI creates an instance of the Client client. 40func NewClientWithBaseURI(baseURI string, subscriptionID string) Client { 41 return Client{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// CheckExistence checks whether a resource exists. 45// Parameters: 46// resourceGroupName - the name of the resource group containing the resource to check. The name is case 47// insensitive. 48// resourceProviderNamespace - the resource provider of the resource to check. 49// parentResourcePath - the parent resource identity. 50// resourceType - the resource type. 51// resourceName - the name of the resource to check whether it exists. 52func (client Client) CheckExistence(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (result autorest.Response, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/Client.CheckExistence") 55 defer func() { 56 sc := -1 57 if result.Response != nil { 58 sc = result.Response.StatusCode 59 } 60 tracing.EndSpan(ctx, sc, err) 61 }() 62 } 63 if err := validation.Validate([]validation.Validation{ 64 {TargetValue: resourceGroupName, 65 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 66 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 67 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\p{L}\._\(\)\w]+$`, Chain: nil}}}}); err != nil { 68 return result, validation.NewError("resources.Client", "CheckExistence", err.Error()) 69 } 70 71 req, err := client.CheckExistencePreparer(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "resources.Client", "CheckExistence", nil, "Failure preparing request") 74 return 75 } 76 77 resp, err := client.CheckExistenceSender(req) 78 if err != nil { 79 result.Response = resp 80 err = autorest.NewErrorWithError(err, "resources.Client", "CheckExistence", resp, "Failure sending request") 81 return 82 } 83 84 result, err = client.CheckExistenceResponder(resp) 85 if err != nil { 86 err = autorest.NewErrorWithError(err, "resources.Client", "CheckExistence", resp, "Failure responding to request") 87 } 88 89 return 90} 91 92// CheckExistencePreparer prepares the CheckExistence request. 93func (client Client) CheckExistencePreparer(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (*http.Request, error) { 94 pathParameters := map[string]interface{}{ 95 "parentResourcePath": parentResourcePath, 96 "resourceGroupName": autorest.Encode("path", resourceGroupName), 97 "resourceName": autorest.Encode("path", resourceName), 98 "resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace), 99 "resourceType": resourceType, 100 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 101 } 102 103 const APIVersion = "2018-05-01" 104 queryParameters := map[string]interface{}{ 105 "api-version": APIVersion, 106 } 107 108 preparer := autorest.CreatePreparer( 109 autorest.AsHead(), 110 autorest.WithBaseURL(client.BaseURI), 111 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}", pathParameters), 112 autorest.WithQueryParameters(queryParameters)) 113 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 114} 115 116// CheckExistenceSender sends the CheckExistence request. The method will close the 117// http.Response Body if it receives an error. 118func (client Client) CheckExistenceSender(req *http.Request) (*http.Response, error) { 119 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 120 return autorest.SendWithSender(client, req, sd...) 121} 122 123// CheckExistenceResponder handles the response to the CheckExistence request. The method always 124// closes the http.Response Body. 125func (client Client) CheckExistenceResponder(resp *http.Response) (result autorest.Response, err error) { 126 err = autorest.Respond( 127 resp, 128 client.ByInspecting(), 129 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent, http.StatusNotFound), 130 autorest.ByClosing()) 131 result.Response = resp 132 return 133} 134 135// CheckExistenceByID checks by ID whether a resource exists. 136// Parameters: 137// resourceID - the fully qualified ID of the resource, including the resource name and resource type. Use the 138// format, 139// /subscriptions/{guid}/resourceGroups/{resource-group-name}/{resource-provider-namespace}/{resource-type}/{resource-name} 140func (client Client) CheckExistenceByID(ctx context.Context, resourceID string) (result autorest.Response, err error) { 141 if tracing.IsEnabled() { 142 ctx = tracing.StartSpan(ctx, fqdn+"/Client.CheckExistenceByID") 143 defer func() { 144 sc := -1 145 if result.Response != nil { 146 sc = result.Response.StatusCode 147 } 148 tracing.EndSpan(ctx, sc, err) 149 }() 150 } 151 req, err := client.CheckExistenceByIDPreparer(ctx, resourceID) 152 if err != nil { 153 err = autorest.NewErrorWithError(err, "resources.Client", "CheckExistenceByID", nil, "Failure preparing request") 154 return 155 } 156 157 resp, err := client.CheckExistenceByIDSender(req) 158 if err != nil { 159 result.Response = resp 160 err = autorest.NewErrorWithError(err, "resources.Client", "CheckExistenceByID", resp, "Failure sending request") 161 return 162 } 163 164 result, err = client.CheckExistenceByIDResponder(resp) 165 if err != nil { 166 err = autorest.NewErrorWithError(err, "resources.Client", "CheckExistenceByID", resp, "Failure responding to request") 167 } 168 169 return 170} 171 172// CheckExistenceByIDPreparer prepares the CheckExistenceByID request. 173func (client Client) CheckExistenceByIDPreparer(ctx context.Context, resourceID string) (*http.Request, error) { 174 pathParameters := map[string]interface{}{ 175 "resourceId": resourceID, 176 } 177 178 const APIVersion = "2018-05-01" 179 queryParameters := map[string]interface{}{ 180 "api-version": APIVersion, 181 } 182 183 preparer := autorest.CreatePreparer( 184 autorest.AsHead(), 185 autorest.WithBaseURL(client.BaseURI), 186 autorest.WithPathParameters("/{resourceId}", pathParameters), 187 autorest.WithQueryParameters(queryParameters)) 188 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 189} 190 191// CheckExistenceByIDSender sends the CheckExistenceByID request. The method will close the 192// http.Response Body if it receives an error. 193func (client Client) CheckExistenceByIDSender(req *http.Request) (*http.Response, error) { 194 sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 195 return autorest.SendWithSender(client, req, sd...) 196} 197 198// CheckExistenceByIDResponder handles the response to the CheckExistenceByID request. The method always 199// closes the http.Response Body. 200func (client Client) CheckExistenceByIDResponder(resp *http.Response) (result autorest.Response, err error) { 201 err = autorest.Respond( 202 resp, 203 client.ByInspecting(), 204 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent, http.StatusNotFound), 205 autorest.ByClosing()) 206 result.Response = resp 207 return 208} 209 210// CreateOrUpdate creates a resource. 211// Parameters: 212// resourceGroupName - the name of the resource group for the resource. The name is case insensitive. 213// resourceProviderNamespace - the namespace of the resource provider. 214// parentResourcePath - the parent resource identity. 215// resourceType - the resource type of the resource to create. 216// resourceName - the name of the resource to create. 217// parameters - parameters for creating or updating the resource. 218func (client Client) CreateOrUpdate(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, parameters GenericResource) (result CreateOrUpdateFuture, err error) { 219 if tracing.IsEnabled() { 220 ctx = tracing.StartSpan(ctx, fqdn+"/Client.CreateOrUpdate") 221 defer func() { 222 sc := -1 223 if result.Response() != nil { 224 sc = result.Response().StatusCode 225 } 226 tracing.EndSpan(ctx, sc, err) 227 }() 228 } 229 if err := validation.Validate([]validation.Validation{ 230 {TargetValue: resourceGroupName, 231 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 232 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 233 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\p{L}\._\(\)\w]+$`, Chain: nil}}}, 234 {TargetValue: parameters, 235 Constraints: []validation.Constraint{{Target: "parameters.Kind", Name: validation.Null, Rule: false, 236 Chain: []validation.Constraint{{Target: "parameters.Kind", Name: validation.Pattern, Rule: `^[-\w\._,\(\)]+$`, Chain: nil}}}}}}); err != nil { 237 return result, validation.NewError("resources.Client", "CreateOrUpdate", err.Error()) 238 } 239 240 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, parameters) 241 if err != nil { 242 err = autorest.NewErrorWithError(err, "resources.Client", "CreateOrUpdate", nil, "Failure preparing request") 243 return 244 } 245 246 result, err = client.CreateOrUpdateSender(req) 247 if err != nil { 248 err = autorest.NewErrorWithError(err, "resources.Client", "CreateOrUpdate", result.Response(), "Failure sending request") 249 return 250 } 251 252 return 253} 254 255// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 256func (client Client) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, parameters GenericResource) (*http.Request, error) { 257 pathParameters := map[string]interface{}{ 258 "parentResourcePath": parentResourcePath, 259 "resourceGroupName": autorest.Encode("path", resourceGroupName), 260 "resourceName": autorest.Encode("path", resourceName), 261 "resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace), 262 "resourceType": resourceType, 263 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 264 } 265 266 const APIVersion = "2018-05-01" 267 queryParameters := map[string]interface{}{ 268 "api-version": APIVersion, 269 } 270 271 preparer := autorest.CreatePreparer( 272 autorest.AsContentType("application/json; charset=utf-8"), 273 autorest.AsPut(), 274 autorest.WithBaseURL(client.BaseURI), 275 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}", pathParameters), 276 autorest.WithJSON(parameters), 277 autorest.WithQueryParameters(queryParameters)) 278 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 279} 280 281// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 282// http.Response Body if it receives an error. 283func (client Client) CreateOrUpdateSender(req *http.Request) (future CreateOrUpdateFuture, err error) { 284 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 285 var resp *http.Response 286 resp, err = autorest.SendWithSender(client, req, sd...) 287 if err != nil { 288 return 289 } 290 future.Future, err = azure.NewFutureFromResponse(resp) 291 return 292} 293 294// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 295// closes the http.Response Body. 296func (client Client) CreateOrUpdateResponder(resp *http.Response) (result GenericResource, err error) { 297 err = autorest.Respond( 298 resp, 299 client.ByInspecting(), 300 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted), 301 autorest.ByUnmarshallingJSON(&result), 302 autorest.ByClosing()) 303 result.Response = autorest.Response{Response: resp} 304 return 305} 306 307// CreateOrUpdateByID create a resource by ID. 308// Parameters: 309// resourceID - the fully qualified ID of the resource, including the resource name and resource type. Use the 310// format, 311// /subscriptions/{guid}/resourceGroups/{resource-group-name}/{resource-provider-namespace}/{resource-type}/{resource-name} 312// parameters - create or update resource parameters. 313func (client Client) CreateOrUpdateByID(ctx context.Context, resourceID string, parameters GenericResource) (result CreateOrUpdateByIDFuture, err error) { 314 if tracing.IsEnabled() { 315 ctx = tracing.StartSpan(ctx, fqdn+"/Client.CreateOrUpdateByID") 316 defer func() { 317 sc := -1 318 if result.Response() != nil { 319 sc = result.Response().StatusCode 320 } 321 tracing.EndSpan(ctx, sc, err) 322 }() 323 } 324 if err := validation.Validate([]validation.Validation{ 325 {TargetValue: parameters, 326 Constraints: []validation.Constraint{{Target: "parameters.Kind", Name: validation.Null, Rule: false, 327 Chain: []validation.Constraint{{Target: "parameters.Kind", Name: validation.Pattern, Rule: `^[-\w\._,\(\)]+$`, Chain: nil}}}}}}); err != nil { 328 return result, validation.NewError("resources.Client", "CreateOrUpdateByID", err.Error()) 329 } 330 331 req, err := client.CreateOrUpdateByIDPreparer(ctx, resourceID, parameters) 332 if err != nil { 333 err = autorest.NewErrorWithError(err, "resources.Client", "CreateOrUpdateByID", nil, "Failure preparing request") 334 return 335 } 336 337 result, err = client.CreateOrUpdateByIDSender(req) 338 if err != nil { 339 err = autorest.NewErrorWithError(err, "resources.Client", "CreateOrUpdateByID", result.Response(), "Failure sending request") 340 return 341 } 342 343 return 344} 345 346// CreateOrUpdateByIDPreparer prepares the CreateOrUpdateByID request. 347func (client Client) CreateOrUpdateByIDPreparer(ctx context.Context, resourceID string, parameters GenericResource) (*http.Request, error) { 348 pathParameters := map[string]interface{}{ 349 "resourceId": resourceID, 350 } 351 352 const APIVersion = "2018-05-01" 353 queryParameters := map[string]interface{}{ 354 "api-version": APIVersion, 355 } 356 357 preparer := autorest.CreatePreparer( 358 autorest.AsContentType("application/json; charset=utf-8"), 359 autorest.AsPut(), 360 autorest.WithBaseURL(client.BaseURI), 361 autorest.WithPathParameters("/{resourceId}", pathParameters), 362 autorest.WithJSON(parameters), 363 autorest.WithQueryParameters(queryParameters)) 364 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 365} 366 367// CreateOrUpdateByIDSender sends the CreateOrUpdateByID request. The method will close the 368// http.Response Body if it receives an error. 369func (client Client) CreateOrUpdateByIDSender(req *http.Request) (future CreateOrUpdateByIDFuture, err error) { 370 sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 371 var resp *http.Response 372 resp, err = autorest.SendWithSender(client, req, sd...) 373 if err != nil { 374 return 375 } 376 future.Future, err = azure.NewFutureFromResponse(resp) 377 return 378} 379 380// CreateOrUpdateByIDResponder handles the response to the CreateOrUpdateByID request. The method always 381// closes the http.Response Body. 382func (client Client) CreateOrUpdateByIDResponder(resp *http.Response) (result GenericResource, err error) { 383 err = autorest.Respond( 384 resp, 385 client.ByInspecting(), 386 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted), 387 autorest.ByUnmarshallingJSON(&result), 388 autorest.ByClosing()) 389 result.Response = autorest.Response{Response: resp} 390 return 391} 392 393// Delete deletes a resource. 394// Parameters: 395// resourceGroupName - the name of the resource group that contains the resource to delete. The name is case 396// insensitive. 397// resourceProviderNamespace - the namespace of the resource provider. 398// parentResourcePath - the parent resource identity. 399// resourceType - the resource type. 400// resourceName - the name of the resource to delete. 401func (client Client) Delete(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (result DeleteFuture, err error) { 402 if tracing.IsEnabled() { 403 ctx = tracing.StartSpan(ctx, fqdn+"/Client.Delete") 404 defer func() { 405 sc := -1 406 if result.Response() != nil { 407 sc = result.Response().StatusCode 408 } 409 tracing.EndSpan(ctx, sc, err) 410 }() 411 } 412 if err := validation.Validate([]validation.Validation{ 413 {TargetValue: resourceGroupName, 414 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 415 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 416 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\p{L}\._\(\)\w]+$`, Chain: nil}}}}); err != nil { 417 return result, validation.NewError("resources.Client", "Delete", err.Error()) 418 } 419 420 req, err := client.DeletePreparer(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName) 421 if err != nil { 422 err = autorest.NewErrorWithError(err, "resources.Client", "Delete", nil, "Failure preparing request") 423 return 424 } 425 426 result, err = client.DeleteSender(req) 427 if err != nil { 428 err = autorest.NewErrorWithError(err, "resources.Client", "Delete", result.Response(), "Failure sending request") 429 return 430 } 431 432 return 433} 434 435// DeletePreparer prepares the Delete request. 436func (client Client) DeletePreparer(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (*http.Request, error) { 437 pathParameters := map[string]interface{}{ 438 "parentResourcePath": parentResourcePath, 439 "resourceGroupName": autorest.Encode("path", resourceGroupName), 440 "resourceName": autorest.Encode("path", resourceName), 441 "resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace), 442 "resourceType": resourceType, 443 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 444 } 445 446 const APIVersion = "2018-05-01" 447 queryParameters := map[string]interface{}{ 448 "api-version": APIVersion, 449 } 450 451 preparer := autorest.CreatePreparer( 452 autorest.AsDelete(), 453 autorest.WithBaseURL(client.BaseURI), 454 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}", pathParameters), 455 autorest.WithQueryParameters(queryParameters)) 456 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 457} 458 459// DeleteSender sends the Delete request. The method will close the 460// http.Response Body if it receives an error. 461func (client Client) DeleteSender(req *http.Request) (future DeleteFuture, err error) { 462 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 463 var resp *http.Response 464 resp, err = autorest.SendWithSender(client, req, sd...) 465 if err != nil { 466 return 467 } 468 future.Future, err = azure.NewFutureFromResponse(resp) 469 return 470} 471 472// DeleteResponder handles the response to the Delete request. The method always 473// closes the http.Response Body. 474func (client Client) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 475 err = autorest.Respond( 476 resp, 477 client.ByInspecting(), 478 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 479 autorest.ByClosing()) 480 result.Response = resp 481 return 482} 483 484// DeleteByID deletes a resource by ID. 485// Parameters: 486// resourceID - the fully qualified ID of the resource, including the resource name and resource type. Use the 487// format, 488// /subscriptions/{guid}/resourceGroups/{resource-group-name}/{resource-provider-namespace}/{resource-type}/{resource-name} 489func (client Client) DeleteByID(ctx context.Context, resourceID string) (result DeleteByIDFuture, err error) { 490 if tracing.IsEnabled() { 491 ctx = tracing.StartSpan(ctx, fqdn+"/Client.DeleteByID") 492 defer func() { 493 sc := -1 494 if result.Response() != nil { 495 sc = result.Response().StatusCode 496 } 497 tracing.EndSpan(ctx, sc, err) 498 }() 499 } 500 req, err := client.DeleteByIDPreparer(ctx, resourceID) 501 if err != nil { 502 err = autorest.NewErrorWithError(err, "resources.Client", "DeleteByID", nil, "Failure preparing request") 503 return 504 } 505 506 result, err = client.DeleteByIDSender(req) 507 if err != nil { 508 err = autorest.NewErrorWithError(err, "resources.Client", "DeleteByID", result.Response(), "Failure sending request") 509 return 510 } 511 512 return 513} 514 515// DeleteByIDPreparer prepares the DeleteByID request. 516func (client Client) DeleteByIDPreparer(ctx context.Context, resourceID string) (*http.Request, error) { 517 pathParameters := map[string]interface{}{ 518 "resourceId": resourceID, 519 } 520 521 const APIVersion = "2018-05-01" 522 queryParameters := map[string]interface{}{ 523 "api-version": APIVersion, 524 } 525 526 preparer := autorest.CreatePreparer( 527 autorest.AsDelete(), 528 autorest.WithBaseURL(client.BaseURI), 529 autorest.WithPathParameters("/{resourceId}", pathParameters), 530 autorest.WithQueryParameters(queryParameters)) 531 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 532} 533 534// DeleteByIDSender sends the DeleteByID request. The method will close the 535// http.Response Body if it receives an error. 536func (client Client) DeleteByIDSender(req *http.Request) (future DeleteByIDFuture, err error) { 537 sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 538 var resp *http.Response 539 resp, err = autorest.SendWithSender(client, req, sd...) 540 if err != nil { 541 return 542 } 543 future.Future, err = azure.NewFutureFromResponse(resp) 544 return 545} 546 547// DeleteByIDResponder handles the response to the DeleteByID request. The method always 548// closes the http.Response Body. 549func (client Client) DeleteByIDResponder(resp *http.Response) (result autorest.Response, err error) { 550 err = autorest.Respond( 551 resp, 552 client.ByInspecting(), 553 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 554 autorest.ByClosing()) 555 result.Response = resp 556 return 557} 558 559// Get gets a resource. 560// Parameters: 561// resourceGroupName - the name of the resource group containing the resource to get. The name is case 562// insensitive. 563// resourceProviderNamespace - the namespace of the resource provider. 564// parentResourcePath - the parent resource identity. 565// resourceType - the resource type of the resource. 566// resourceName - the name of the resource to get. 567func (client Client) Get(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (result GenericResource, err error) { 568 if tracing.IsEnabled() { 569 ctx = tracing.StartSpan(ctx, fqdn+"/Client.Get") 570 defer func() { 571 sc := -1 572 if result.Response.Response != nil { 573 sc = result.Response.Response.StatusCode 574 } 575 tracing.EndSpan(ctx, sc, err) 576 }() 577 } 578 if err := validation.Validate([]validation.Validation{ 579 {TargetValue: resourceGroupName, 580 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 581 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 582 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\p{L}\._\(\)\w]+$`, Chain: nil}}}}); err != nil { 583 return result, validation.NewError("resources.Client", "Get", err.Error()) 584 } 585 586 req, err := client.GetPreparer(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName) 587 if err != nil { 588 err = autorest.NewErrorWithError(err, "resources.Client", "Get", nil, "Failure preparing request") 589 return 590 } 591 592 resp, err := client.GetSender(req) 593 if err != nil { 594 result.Response = autorest.Response{Response: resp} 595 err = autorest.NewErrorWithError(err, "resources.Client", "Get", resp, "Failure sending request") 596 return 597 } 598 599 result, err = client.GetResponder(resp) 600 if err != nil { 601 err = autorest.NewErrorWithError(err, "resources.Client", "Get", resp, "Failure responding to request") 602 } 603 604 return 605} 606 607// GetPreparer prepares the Get request. 608func (client Client) GetPreparer(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (*http.Request, error) { 609 pathParameters := map[string]interface{}{ 610 "parentResourcePath": parentResourcePath, 611 "resourceGroupName": autorest.Encode("path", resourceGroupName), 612 "resourceName": autorest.Encode("path", resourceName), 613 "resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace), 614 "resourceType": resourceType, 615 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 616 } 617 618 const APIVersion = "2018-05-01" 619 queryParameters := map[string]interface{}{ 620 "api-version": APIVersion, 621 } 622 623 preparer := autorest.CreatePreparer( 624 autorest.AsGet(), 625 autorest.WithBaseURL(client.BaseURI), 626 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}", pathParameters), 627 autorest.WithQueryParameters(queryParameters)) 628 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 629} 630 631// GetSender sends the Get request. The method will close the 632// http.Response Body if it receives an error. 633func (client Client) GetSender(req *http.Request) (*http.Response, error) { 634 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 635 return autorest.SendWithSender(client, req, sd...) 636} 637 638// GetResponder handles the response to the Get request. The method always 639// closes the http.Response Body. 640func (client Client) GetResponder(resp *http.Response) (result GenericResource, err error) { 641 err = autorest.Respond( 642 resp, 643 client.ByInspecting(), 644 azure.WithErrorUnlessStatusCode(http.StatusOK), 645 autorest.ByUnmarshallingJSON(&result), 646 autorest.ByClosing()) 647 result.Response = autorest.Response{Response: resp} 648 return 649} 650 651// GetByID gets a resource by ID. 652// Parameters: 653// resourceID - the fully qualified ID of the resource, including the resource name and resource type. Use the 654// format, 655// /subscriptions/{guid}/resourceGroups/{resource-group-name}/{resource-provider-namespace}/{resource-type}/{resource-name} 656func (client Client) GetByID(ctx context.Context, resourceID string) (result GenericResource, err error) { 657 if tracing.IsEnabled() { 658 ctx = tracing.StartSpan(ctx, fqdn+"/Client.GetByID") 659 defer func() { 660 sc := -1 661 if result.Response.Response != nil { 662 sc = result.Response.Response.StatusCode 663 } 664 tracing.EndSpan(ctx, sc, err) 665 }() 666 } 667 req, err := client.GetByIDPreparer(ctx, resourceID) 668 if err != nil { 669 err = autorest.NewErrorWithError(err, "resources.Client", "GetByID", nil, "Failure preparing request") 670 return 671 } 672 673 resp, err := client.GetByIDSender(req) 674 if err != nil { 675 result.Response = autorest.Response{Response: resp} 676 err = autorest.NewErrorWithError(err, "resources.Client", "GetByID", resp, "Failure sending request") 677 return 678 } 679 680 result, err = client.GetByIDResponder(resp) 681 if err != nil { 682 err = autorest.NewErrorWithError(err, "resources.Client", "GetByID", resp, "Failure responding to request") 683 } 684 685 return 686} 687 688// GetByIDPreparer prepares the GetByID request. 689func (client Client) GetByIDPreparer(ctx context.Context, resourceID string) (*http.Request, error) { 690 pathParameters := map[string]interface{}{ 691 "resourceId": resourceID, 692 } 693 694 const APIVersion = "2018-05-01" 695 queryParameters := map[string]interface{}{ 696 "api-version": APIVersion, 697 } 698 699 preparer := autorest.CreatePreparer( 700 autorest.AsGet(), 701 autorest.WithBaseURL(client.BaseURI), 702 autorest.WithPathParameters("/{resourceId}", pathParameters), 703 autorest.WithQueryParameters(queryParameters)) 704 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 705} 706 707// GetByIDSender sends the GetByID request. The method will close the 708// http.Response Body if it receives an error. 709func (client Client) GetByIDSender(req *http.Request) (*http.Response, error) { 710 sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 711 return autorest.SendWithSender(client, req, sd...) 712} 713 714// GetByIDResponder handles the response to the GetByID request. The method always 715// closes the http.Response Body. 716func (client Client) GetByIDResponder(resp *http.Response) (result GenericResource, err error) { 717 err = autorest.Respond( 718 resp, 719 client.ByInspecting(), 720 azure.WithErrorUnlessStatusCode(http.StatusOK), 721 autorest.ByUnmarshallingJSON(&result), 722 autorest.ByClosing()) 723 result.Response = autorest.Response{Response: resp} 724 return 725} 726 727// List get all the resources in a subscription. 728// Parameters: 729// filter - the filter to apply on the operation.<br><br>The properties you can use for eq (equals) or ne (not 730// equals) are: location, resourceType, name, resourceGroup, identity, identity/principalId, plan, 731// plan/publisher, plan/product, plan/name, plan/version, and plan/promotionCode.<br><br>For example, to filter 732// by a resource type, use: $filter=resourceType eq 'Microsoft.Network/virtualNetworks'<br><br>You can use 733// substringof(value, property) in the filter. The properties you can use for substring are: name and 734// resourceGroup.<br><br>For example, to get all resources with 'demo' anywhere in the name, use: 735// $filter=substringof('demo', name)<br><br>You can link more than one substringof together by adding and/or 736// operators.<br><br>You can filter by tag names and values. For example, to filter for a tag name and value, 737// use $filter=tagName eq 'tag1' and tagValue eq 'Value1'<br><br>You can use some properties together when 738// filtering. The combinations you can use are: substringof and/or resourceType, plan and plan/publisher and 739// plan/name, identity and identity/principalId. 740// expand - the $expand query parameter. You can expand createdTime and changedTime. For example, to expand 741// both properties, use $expand=changedTime,createdTime 742// top - the number of results to return. If null is passed, returns all resource groups. 743func (client Client) List(ctx context.Context, filter string, expand string, top *int32) (result ListResultPage, err error) { 744 if tracing.IsEnabled() { 745 ctx = tracing.StartSpan(ctx, fqdn+"/Client.List") 746 defer func() { 747 sc := -1 748 if result.lr.Response.Response != nil { 749 sc = result.lr.Response.Response.StatusCode 750 } 751 tracing.EndSpan(ctx, sc, err) 752 }() 753 } 754 result.fn = client.listNextResults 755 req, err := client.ListPreparer(ctx, filter, expand, top) 756 if err != nil { 757 err = autorest.NewErrorWithError(err, "resources.Client", "List", nil, "Failure preparing request") 758 return 759 } 760 761 resp, err := client.ListSender(req) 762 if err != nil { 763 result.lr.Response = autorest.Response{Response: resp} 764 err = autorest.NewErrorWithError(err, "resources.Client", "List", resp, "Failure sending request") 765 return 766 } 767 768 result.lr, err = client.ListResponder(resp) 769 if err != nil { 770 err = autorest.NewErrorWithError(err, "resources.Client", "List", resp, "Failure responding to request") 771 } 772 773 return 774} 775 776// ListPreparer prepares the List request. 777func (client Client) ListPreparer(ctx context.Context, filter string, expand string, top *int32) (*http.Request, error) { 778 pathParameters := map[string]interface{}{ 779 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 780 } 781 782 const APIVersion = "2018-05-01" 783 queryParameters := map[string]interface{}{ 784 "api-version": APIVersion, 785 } 786 if len(filter) > 0 { 787 queryParameters["$filter"] = autorest.Encode("query", filter) 788 } 789 if len(expand) > 0 { 790 queryParameters["$expand"] = autorest.Encode("query", expand) 791 } 792 if top != nil { 793 queryParameters["$top"] = autorest.Encode("query", *top) 794 } 795 796 preparer := autorest.CreatePreparer( 797 autorest.AsGet(), 798 autorest.WithBaseURL(client.BaseURI), 799 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resources", pathParameters), 800 autorest.WithQueryParameters(queryParameters)) 801 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 802} 803 804// ListSender sends the List request. The method will close the 805// http.Response Body if it receives an error. 806func (client Client) ListSender(req *http.Request) (*http.Response, error) { 807 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 808 return autorest.SendWithSender(client, req, sd...) 809} 810 811// ListResponder handles the response to the List request. The method always 812// closes the http.Response Body. 813func (client Client) ListResponder(resp *http.Response) (result ListResult, err error) { 814 err = autorest.Respond( 815 resp, 816 client.ByInspecting(), 817 azure.WithErrorUnlessStatusCode(http.StatusOK), 818 autorest.ByUnmarshallingJSON(&result), 819 autorest.ByClosing()) 820 result.Response = autorest.Response{Response: resp} 821 return 822} 823 824// listNextResults retrieves the next set of results, if any. 825func (client Client) listNextResults(ctx context.Context, lastResults ListResult) (result ListResult, err error) { 826 req, err := lastResults.listResultPreparer(ctx) 827 if err != nil { 828 return result, autorest.NewErrorWithError(err, "resources.Client", "listNextResults", nil, "Failure preparing next results request") 829 } 830 if req == nil { 831 return 832 } 833 resp, err := client.ListSender(req) 834 if err != nil { 835 result.Response = autorest.Response{Response: resp} 836 return result, autorest.NewErrorWithError(err, "resources.Client", "listNextResults", resp, "Failure sending next results request") 837 } 838 result, err = client.ListResponder(resp) 839 if err != nil { 840 err = autorest.NewErrorWithError(err, "resources.Client", "listNextResults", resp, "Failure responding to next results request") 841 } 842 return 843} 844 845// ListComplete enumerates all values, automatically crossing page boundaries as required. 846func (client Client) ListComplete(ctx context.Context, filter string, expand string, top *int32) (result ListResultIterator, err error) { 847 if tracing.IsEnabled() { 848 ctx = tracing.StartSpan(ctx, fqdn+"/Client.List") 849 defer func() { 850 sc := -1 851 if result.Response().Response.Response != nil { 852 sc = result.page.Response().Response.Response.StatusCode 853 } 854 tracing.EndSpan(ctx, sc, err) 855 }() 856 } 857 result.page, err = client.List(ctx, filter, expand, top) 858 return 859} 860 861// ListByResourceGroup get all the resources for a resource group. 862// Parameters: 863// resourceGroupName - the resource group with the resources to get. 864// filter - the filter to apply on the operation.<br><br>The properties you can use for eq (equals) or ne (not 865// equals) are: location, resourceType, name, resourceGroup, identity, identity/principalId, plan, 866// plan/publisher, plan/product, plan/name, plan/version, and plan/promotionCode.<br><br>For example, to filter 867// by a resource type, use: $filter=resourceType eq 'Microsoft.Network/virtualNetworks'<br><br>You can use 868// substringof(value, property) in the filter. The properties you can use for substring are: name and 869// resourceGroup.<br><br>For example, to get all resources with 'demo' anywhere in the name, use: 870// $filter=substringof('demo', name)<br><br>You can link more than one substringof together by adding and/or 871// operators.<br><br>You can filter by tag names and values. For example, to filter for a tag name and value, 872// use $filter=tagName eq 'tag1' and tagValue eq 'Value1'<br><br>You can use some properties together when 873// filtering. The combinations you can use are: substringof and/or resourceType, plan and plan/publisher and 874// plan/name, identity and identity/principalId. 875// expand - the $expand query parameter. You can expand createdTime and changedTime. For example, to expand 876// both properties, use $expand=changedTime,createdTime 877// top - the number of results to return. If null is passed, returns all resources. 878func (client Client) ListByResourceGroup(ctx context.Context, resourceGroupName string, filter string, expand string, top *int32) (result ListResultPage, err error) { 879 if tracing.IsEnabled() { 880 ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListByResourceGroup") 881 defer func() { 882 sc := -1 883 if result.lr.Response.Response != nil { 884 sc = result.lr.Response.Response.StatusCode 885 } 886 tracing.EndSpan(ctx, sc, err) 887 }() 888 } 889 if err := validation.Validate([]validation.Validation{ 890 {TargetValue: resourceGroupName, 891 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 892 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 893 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\p{L}\._\(\)\w]+$`, Chain: nil}}}}); err != nil { 894 return result, validation.NewError("resources.Client", "ListByResourceGroup", err.Error()) 895 } 896 897 result.fn = client.listByResourceGroupNextResults 898 req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName, filter, expand, top) 899 if err != nil { 900 err = autorest.NewErrorWithError(err, "resources.Client", "ListByResourceGroup", nil, "Failure preparing request") 901 return 902 } 903 904 resp, err := client.ListByResourceGroupSender(req) 905 if err != nil { 906 result.lr.Response = autorest.Response{Response: resp} 907 err = autorest.NewErrorWithError(err, "resources.Client", "ListByResourceGroup", resp, "Failure sending request") 908 return 909 } 910 911 result.lr, err = client.ListByResourceGroupResponder(resp) 912 if err != nil { 913 err = autorest.NewErrorWithError(err, "resources.Client", "ListByResourceGroup", resp, "Failure responding to request") 914 } 915 916 return 917} 918 919// ListByResourceGroupPreparer prepares the ListByResourceGroup request. 920func (client Client) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string, filter string, expand string, top *int32) (*http.Request, error) { 921 pathParameters := map[string]interface{}{ 922 "resourceGroupName": autorest.Encode("path", resourceGroupName), 923 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 924 } 925 926 const APIVersion = "2018-05-01" 927 queryParameters := map[string]interface{}{ 928 "api-version": APIVersion, 929 } 930 if len(filter) > 0 { 931 queryParameters["$filter"] = autorest.Encode("query", filter) 932 } 933 if len(expand) > 0 { 934 queryParameters["$expand"] = autorest.Encode("query", expand) 935 } 936 if top != nil { 937 queryParameters["$top"] = autorest.Encode("query", *top) 938 } 939 940 preparer := autorest.CreatePreparer( 941 autorest.AsGet(), 942 autorest.WithBaseURL(client.BaseURI), 943 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/resources", pathParameters), 944 autorest.WithQueryParameters(queryParameters)) 945 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 946} 947 948// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the 949// http.Response Body if it receives an error. 950func (client Client) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { 951 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 952 return autorest.SendWithSender(client, req, sd...) 953} 954 955// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always 956// closes the http.Response Body. 957func (client Client) ListByResourceGroupResponder(resp *http.Response) (result ListResult, err error) { 958 err = autorest.Respond( 959 resp, 960 client.ByInspecting(), 961 azure.WithErrorUnlessStatusCode(http.StatusOK), 962 autorest.ByUnmarshallingJSON(&result), 963 autorest.ByClosing()) 964 result.Response = autorest.Response{Response: resp} 965 return 966} 967 968// listByResourceGroupNextResults retrieves the next set of results, if any. 969func (client Client) listByResourceGroupNextResults(ctx context.Context, lastResults ListResult) (result ListResult, err error) { 970 req, err := lastResults.listResultPreparer(ctx) 971 if err != nil { 972 return result, autorest.NewErrorWithError(err, "resources.Client", "listByResourceGroupNextResults", nil, "Failure preparing next results request") 973 } 974 if req == nil { 975 return 976 } 977 resp, err := client.ListByResourceGroupSender(req) 978 if err != nil { 979 result.Response = autorest.Response{Response: resp} 980 return result, autorest.NewErrorWithError(err, "resources.Client", "listByResourceGroupNextResults", resp, "Failure sending next results request") 981 } 982 result, err = client.ListByResourceGroupResponder(resp) 983 if err != nil { 984 err = autorest.NewErrorWithError(err, "resources.Client", "listByResourceGroupNextResults", resp, "Failure responding to next results request") 985 } 986 return 987} 988 989// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. 990func (client Client) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string, filter string, expand string, top *int32) (result ListResultIterator, err error) { 991 if tracing.IsEnabled() { 992 ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListByResourceGroup") 993 defer func() { 994 sc := -1 995 if result.Response().Response.Response != nil { 996 sc = result.page.Response().Response.Response.StatusCode 997 } 998 tracing.EndSpan(ctx, sc, err) 999 }() 1000 } 1001 result.page, err = client.ListByResourceGroup(ctx, resourceGroupName, filter, expand, top) 1002 return 1003} 1004 1005// MoveResources the resources to move must be in the same source resource group. The target resource group may be in a 1006// different subscription. When moving resources, both the source group and the target group are locked for the 1007// duration of the operation. Write and delete operations are blocked on the groups until the move completes. 1008// Parameters: 1009// sourceResourceGroupName - the name of the resource group containing the resources to move. 1010// parameters - parameters for moving resources. 1011func (client Client) MoveResources(ctx context.Context, sourceResourceGroupName string, parameters MoveInfo) (result MoveResourcesFuture, err error) { 1012 if tracing.IsEnabled() { 1013 ctx = tracing.StartSpan(ctx, fqdn+"/Client.MoveResources") 1014 defer func() { 1015 sc := -1 1016 if result.Response() != nil { 1017 sc = result.Response().StatusCode 1018 } 1019 tracing.EndSpan(ctx, sc, err) 1020 }() 1021 } 1022 if err := validation.Validate([]validation.Validation{ 1023 {TargetValue: sourceResourceGroupName, 1024 Constraints: []validation.Constraint{{Target: "sourceResourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 1025 {Target: "sourceResourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 1026 {Target: "sourceResourceGroupName", Name: validation.Pattern, Rule: `^[-\p{L}\._\(\)\w]+$`, Chain: nil}}}}); err != nil { 1027 return result, validation.NewError("resources.Client", "MoveResources", err.Error()) 1028 } 1029 1030 req, err := client.MoveResourcesPreparer(ctx, sourceResourceGroupName, parameters) 1031 if err != nil { 1032 err = autorest.NewErrorWithError(err, "resources.Client", "MoveResources", nil, "Failure preparing request") 1033 return 1034 } 1035 1036 result, err = client.MoveResourcesSender(req) 1037 if err != nil { 1038 err = autorest.NewErrorWithError(err, "resources.Client", "MoveResources", result.Response(), "Failure sending request") 1039 return 1040 } 1041 1042 return 1043} 1044 1045// MoveResourcesPreparer prepares the MoveResources request. 1046func (client Client) MoveResourcesPreparer(ctx context.Context, sourceResourceGroupName string, parameters MoveInfo) (*http.Request, error) { 1047 pathParameters := map[string]interface{}{ 1048 "sourceResourceGroupName": autorest.Encode("path", sourceResourceGroupName), 1049 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 1050 } 1051 1052 const APIVersion = "2018-05-01" 1053 queryParameters := map[string]interface{}{ 1054 "api-version": APIVersion, 1055 } 1056 1057 preparer := autorest.CreatePreparer( 1058 autorest.AsContentType("application/json; charset=utf-8"), 1059 autorest.AsPost(), 1060 autorest.WithBaseURL(client.BaseURI), 1061 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{sourceResourceGroupName}/moveResources", pathParameters), 1062 autorest.WithJSON(parameters), 1063 autorest.WithQueryParameters(queryParameters)) 1064 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 1065} 1066 1067// MoveResourcesSender sends the MoveResources request. The method will close the 1068// http.Response Body if it receives an error. 1069func (client Client) MoveResourcesSender(req *http.Request) (future MoveResourcesFuture, err error) { 1070 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 1071 var resp *http.Response 1072 resp, err = autorest.SendWithSender(client, req, sd...) 1073 if err != nil { 1074 return 1075 } 1076 future.Future, err = azure.NewFutureFromResponse(resp) 1077 return 1078} 1079 1080// MoveResourcesResponder handles the response to the MoveResources request. The method always 1081// closes the http.Response Body. 1082func (client Client) MoveResourcesResponder(resp *http.Response) (result autorest.Response, err error) { 1083 err = autorest.Respond( 1084 resp, 1085 client.ByInspecting(), 1086 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 1087 autorest.ByClosing()) 1088 result.Response = resp 1089 return 1090} 1091 1092// Update updates a resource. 1093// Parameters: 1094// resourceGroupName - the name of the resource group for the resource. The name is case insensitive. 1095// resourceProviderNamespace - the namespace of the resource provider. 1096// parentResourcePath - the parent resource identity. 1097// resourceType - the resource type of the resource to update. 1098// resourceName - the name of the resource to update. 1099// parameters - parameters for updating the resource. 1100func (client Client) Update(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, parameters GenericResource) (result UpdateFuture, err error) { 1101 if tracing.IsEnabled() { 1102 ctx = tracing.StartSpan(ctx, fqdn+"/Client.Update") 1103 defer func() { 1104 sc := -1 1105 if result.Response() != nil { 1106 sc = result.Response().StatusCode 1107 } 1108 tracing.EndSpan(ctx, sc, err) 1109 }() 1110 } 1111 if err := validation.Validate([]validation.Validation{ 1112 {TargetValue: resourceGroupName, 1113 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 1114 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 1115 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\p{L}\._\(\)\w]+$`, Chain: nil}}}}); err != nil { 1116 return result, validation.NewError("resources.Client", "Update", err.Error()) 1117 } 1118 1119 req, err := client.UpdatePreparer(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, parameters) 1120 if err != nil { 1121 err = autorest.NewErrorWithError(err, "resources.Client", "Update", nil, "Failure preparing request") 1122 return 1123 } 1124 1125 result, err = client.UpdateSender(req) 1126 if err != nil { 1127 err = autorest.NewErrorWithError(err, "resources.Client", "Update", result.Response(), "Failure sending request") 1128 return 1129 } 1130 1131 return 1132} 1133 1134// UpdatePreparer prepares the Update request. 1135func (client Client) UpdatePreparer(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, parameters GenericResource) (*http.Request, error) { 1136 pathParameters := map[string]interface{}{ 1137 "parentResourcePath": parentResourcePath, 1138 "resourceGroupName": autorest.Encode("path", resourceGroupName), 1139 "resourceName": autorest.Encode("path", resourceName), 1140 "resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace), 1141 "resourceType": resourceType, 1142 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 1143 } 1144 1145 const APIVersion = "2018-05-01" 1146 queryParameters := map[string]interface{}{ 1147 "api-version": APIVersion, 1148 } 1149 1150 preparer := autorest.CreatePreparer( 1151 autorest.AsContentType("application/json; charset=utf-8"), 1152 autorest.AsPatch(), 1153 autorest.WithBaseURL(client.BaseURI), 1154 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}", pathParameters), 1155 autorest.WithJSON(parameters), 1156 autorest.WithQueryParameters(queryParameters)) 1157 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 1158} 1159 1160// UpdateSender sends the Update request. The method will close the 1161// http.Response Body if it receives an error. 1162func (client Client) UpdateSender(req *http.Request) (future UpdateFuture, err error) { 1163 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 1164 var resp *http.Response 1165 resp, err = autorest.SendWithSender(client, req, sd...) 1166 if err != nil { 1167 return 1168 } 1169 future.Future, err = azure.NewFutureFromResponse(resp) 1170 return 1171} 1172 1173// UpdateResponder handles the response to the Update request. The method always 1174// closes the http.Response Body. 1175func (client Client) UpdateResponder(resp *http.Response) (result GenericResource, err error) { 1176 err = autorest.Respond( 1177 resp, 1178 client.ByInspecting(), 1179 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 1180 autorest.ByUnmarshallingJSON(&result), 1181 autorest.ByClosing()) 1182 result.Response = autorest.Response{Response: resp} 1183 return 1184} 1185 1186// UpdateByID updates a resource by ID. 1187// Parameters: 1188// resourceID - the fully qualified ID of the resource, including the resource name and resource type. Use the 1189// format, 1190// /subscriptions/{guid}/resourceGroups/{resource-group-name}/{resource-provider-namespace}/{resource-type}/{resource-name} 1191// parameters - update resource parameters. 1192func (client Client) UpdateByID(ctx context.Context, resourceID string, parameters GenericResource) (result UpdateByIDFuture, err error) { 1193 if tracing.IsEnabled() { 1194 ctx = tracing.StartSpan(ctx, fqdn+"/Client.UpdateByID") 1195 defer func() { 1196 sc := -1 1197 if result.Response() != nil { 1198 sc = result.Response().StatusCode 1199 } 1200 tracing.EndSpan(ctx, sc, err) 1201 }() 1202 } 1203 req, err := client.UpdateByIDPreparer(ctx, resourceID, parameters) 1204 if err != nil { 1205 err = autorest.NewErrorWithError(err, "resources.Client", "UpdateByID", nil, "Failure preparing request") 1206 return 1207 } 1208 1209 result, err = client.UpdateByIDSender(req) 1210 if err != nil { 1211 err = autorest.NewErrorWithError(err, "resources.Client", "UpdateByID", result.Response(), "Failure sending request") 1212 return 1213 } 1214 1215 return 1216} 1217 1218// UpdateByIDPreparer prepares the UpdateByID request. 1219func (client Client) UpdateByIDPreparer(ctx context.Context, resourceID string, parameters GenericResource) (*http.Request, error) { 1220 pathParameters := map[string]interface{}{ 1221 "resourceId": resourceID, 1222 } 1223 1224 const APIVersion = "2018-05-01" 1225 queryParameters := map[string]interface{}{ 1226 "api-version": APIVersion, 1227 } 1228 1229 preparer := autorest.CreatePreparer( 1230 autorest.AsContentType("application/json; charset=utf-8"), 1231 autorest.AsPatch(), 1232 autorest.WithBaseURL(client.BaseURI), 1233 autorest.WithPathParameters("/{resourceId}", pathParameters), 1234 autorest.WithJSON(parameters), 1235 autorest.WithQueryParameters(queryParameters)) 1236 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 1237} 1238 1239// UpdateByIDSender sends the UpdateByID request. The method will close the 1240// http.Response Body if it receives an error. 1241func (client Client) UpdateByIDSender(req *http.Request) (future UpdateByIDFuture, err error) { 1242 sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 1243 var resp *http.Response 1244 resp, err = autorest.SendWithSender(client, req, sd...) 1245 if err != nil { 1246 return 1247 } 1248 future.Future, err = azure.NewFutureFromResponse(resp) 1249 return 1250} 1251 1252// UpdateByIDResponder handles the response to the UpdateByID request. The method always 1253// closes the http.Response Body. 1254func (client Client) UpdateByIDResponder(resp *http.Response) (result GenericResource, err error) { 1255 err = autorest.Respond( 1256 resp, 1257 client.ByInspecting(), 1258 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 1259 autorest.ByUnmarshallingJSON(&result), 1260 autorest.ByClosing()) 1261 result.Response = autorest.Response{Response: resp} 1262 return 1263} 1264 1265// ValidateMoveResources this operation checks whether the specified resources can be moved to the target. The 1266// resources to move must be in the same source resource group. The target resource group may be in a different 1267// subscription. If validation succeeds, it returns HTTP response code 204 (no content). If validation fails, it 1268// returns HTTP response code 409 (Conflict) with an error message. Retrieve the URL in the Location header value to 1269// check the result of the long-running operation. 1270// Parameters: 1271// sourceResourceGroupName - the name of the resource group containing the resources to validate for move. 1272// parameters - parameters for moving resources. 1273func (client Client) ValidateMoveResources(ctx context.Context, sourceResourceGroupName string, parameters MoveInfo) (result ValidateMoveResourcesFuture, err error) { 1274 if tracing.IsEnabled() { 1275 ctx = tracing.StartSpan(ctx, fqdn+"/Client.ValidateMoveResources") 1276 defer func() { 1277 sc := -1 1278 if result.Response() != nil { 1279 sc = result.Response().StatusCode 1280 } 1281 tracing.EndSpan(ctx, sc, err) 1282 }() 1283 } 1284 if err := validation.Validate([]validation.Validation{ 1285 {TargetValue: sourceResourceGroupName, 1286 Constraints: []validation.Constraint{{Target: "sourceResourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 1287 {Target: "sourceResourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 1288 {Target: "sourceResourceGroupName", Name: validation.Pattern, Rule: `^[-\p{L}\._\(\)\w]+$`, Chain: nil}}}}); err != nil { 1289 return result, validation.NewError("resources.Client", "ValidateMoveResources", err.Error()) 1290 } 1291 1292 req, err := client.ValidateMoveResourcesPreparer(ctx, sourceResourceGroupName, parameters) 1293 if err != nil { 1294 err = autorest.NewErrorWithError(err, "resources.Client", "ValidateMoveResources", nil, "Failure preparing request") 1295 return 1296 } 1297 1298 result, err = client.ValidateMoveResourcesSender(req) 1299 if err != nil { 1300 err = autorest.NewErrorWithError(err, "resources.Client", "ValidateMoveResources", result.Response(), "Failure sending request") 1301 return 1302 } 1303 1304 return 1305} 1306 1307// ValidateMoveResourcesPreparer prepares the ValidateMoveResources request. 1308func (client Client) ValidateMoveResourcesPreparer(ctx context.Context, sourceResourceGroupName string, parameters MoveInfo) (*http.Request, error) { 1309 pathParameters := map[string]interface{}{ 1310 "sourceResourceGroupName": autorest.Encode("path", sourceResourceGroupName), 1311 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 1312 } 1313 1314 const APIVersion = "2018-05-01" 1315 queryParameters := map[string]interface{}{ 1316 "api-version": APIVersion, 1317 } 1318 1319 preparer := autorest.CreatePreparer( 1320 autorest.AsContentType("application/json; charset=utf-8"), 1321 autorest.AsPost(), 1322 autorest.WithBaseURL(client.BaseURI), 1323 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{sourceResourceGroupName}/validateMoveResources", pathParameters), 1324 autorest.WithJSON(parameters), 1325 autorest.WithQueryParameters(queryParameters)) 1326 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 1327} 1328 1329// ValidateMoveResourcesSender sends the ValidateMoveResources request. The method will close the 1330// http.Response Body if it receives an error. 1331func (client Client) ValidateMoveResourcesSender(req *http.Request) (future ValidateMoveResourcesFuture, err error) { 1332 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 1333 var resp *http.Response 1334 resp, err = autorest.SendWithSender(client, req, sd...) 1335 if err != nil { 1336 return 1337 } 1338 future.Future, err = azure.NewFutureFromResponse(resp) 1339 return 1340} 1341 1342// ValidateMoveResourcesResponder handles the response to the ValidateMoveResources request. The method always 1343// closes the http.Response Body. 1344func (client Client) ValidateMoveResourcesResponder(resp *http.Response) (result autorest.Response, err error) { 1345 err = autorest.Respond( 1346 resp, 1347 client.ByInspecting(), 1348 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent, http.StatusConflict), 1349 autorest.ByClosing()) 1350 result.Response = resp 1351 return 1352} 1353