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