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