1package digitaltwins 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// Client is the azure Digital Twins Client for managing DigitalTwinsInstance 30type Client struct { 31 BaseClient 32} 33 34// NewClient creates an instance of the Client client. 35func NewClient(subscriptionID string) Client { 36 return NewClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewClientWithBaseURI creates an instance of the Client client using a custom endpoint. Use this when interacting 40// with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewClientWithBaseURI(baseURI string, subscriptionID string) Client { 42 return Client{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// CheckNameAvailability check if a DigitalTwinsInstance name is available. 46// Parameters: 47// location - location of DigitalTwinsInstance. 48// digitalTwinsInstanceCheckName - set the name parameter in the DigitalTwinsInstanceCheckName structure to the 49// name of the DigitalTwinsInstance to check. 50func (client Client) CheckNameAvailability(ctx context.Context, location string, digitalTwinsInstanceCheckName CheckNameRequest) (result CheckNameResult, err error) { 51 if tracing.IsEnabled() { 52 ctx = tracing.StartSpan(ctx, fqdn+"/Client.CheckNameAvailability") 53 defer func() { 54 sc := -1 55 if result.Response.Response != nil { 56 sc = result.Response.Response.StatusCode 57 } 58 tracing.EndSpan(ctx, sc, err) 59 }() 60 } 61 if err := validation.Validate([]validation.Validation{ 62 {TargetValue: location, 63 Constraints: []validation.Constraint{{Target: "location", Name: validation.MinLength, Rule: 3, Chain: nil}}}, 64 {TargetValue: digitalTwinsInstanceCheckName, 65 Constraints: []validation.Constraint{{Target: "digitalTwinsInstanceCheckName.Name", Name: validation.Null, Rule: true, Chain: nil}, 66 {Target: "digitalTwinsInstanceCheckName.Type", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 67 return result, validation.NewError("digitaltwins.Client", "CheckNameAvailability", err.Error()) 68 } 69 70 req, err := client.CheckNameAvailabilityPreparer(ctx, location, digitalTwinsInstanceCheckName) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "CheckNameAvailability", nil, "Failure preparing request") 73 return 74 } 75 76 resp, err := client.CheckNameAvailabilitySender(req) 77 if err != nil { 78 result.Response = autorest.Response{Response: resp} 79 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "CheckNameAvailability", resp, "Failure sending request") 80 return 81 } 82 83 result, err = client.CheckNameAvailabilityResponder(resp) 84 if err != nil { 85 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "CheckNameAvailability", resp, "Failure responding to request") 86 return 87 } 88 89 return 90} 91 92// CheckNameAvailabilityPreparer prepares the CheckNameAvailability request. 93func (client Client) CheckNameAvailabilityPreparer(ctx context.Context, location string, digitalTwinsInstanceCheckName CheckNameRequest) (*http.Request, error) { 94 pathParameters := map[string]interface{}{ 95 "location": autorest.Encode("path", location), 96 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 97 } 98 99 const APIVersion = "2020-10-31" 100 queryParameters := map[string]interface{}{ 101 "api-version": APIVersion, 102 } 103 104 preparer := autorest.CreatePreparer( 105 autorest.AsContentType("application/json; charset=utf-8"), 106 autorest.AsPost(), 107 autorest.WithBaseURL(client.BaseURI), 108 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DigitalTwins/locations/{location}/checkNameAvailability", pathParameters), 109 autorest.WithJSON(digitalTwinsInstanceCheckName), 110 autorest.WithQueryParameters(queryParameters)) 111 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 112} 113 114// CheckNameAvailabilitySender sends the CheckNameAvailability request. The method will close the 115// http.Response Body if it receives an error. 116func (client Client) CheckNameAvailabilitySender(req *http.Request) (*http.Response, error) { 117 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 118} 119 120// CheckNameAvailabilityResponder handles the response to the CheckNameAvailability request. The method always 121// closes the http.Response Body. 122func (client Client) CheckNameAvailabilityResponder(resp *http.Response) (result CheckNameResult, err error) { 123 err = autorest.Respond( 124 resp, 125 azure.WithErrorUnlessStatusCode(http.StatusOK), 126 autorest.ByUnmarshallingJSON(&result), 127 autorest.ByClosing()) 128 result.Response = autorest.Response{Response: resp} 129 return 130} 131 132// CreateOrUpdate create or update the metadata of a DigitalTwinsInstance. The usual pattern to modify a property is to 133// retrieve the DigitalTwinsInstance and security metadata, and then combine them with the modified values in a new 134// body to update the DigitalTwinsInstance. 135// Parameters: 136// resourceGroupName - the name of the resource group that contains the DigitalTwinsInstance. 137// resourceName - the name of the DigitalTwinsInstance. 138// digitalTwinsCreate - the DigitalTwinsInstance and security metadata. 139func (client Client) CreateOrUpdate(ctx context.Context, resourceGroupName string, resourceName string, digitalTwinsCreate Description) (result CreateOrUpdateFuture, err error) { 140 if tracing.IsEnabled() { 141 ctx = tracing.StartSpan(ctx, fqdn+"/Client.CreateOrUpdate") 142 defer func() { 143 sc := -1 144 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 145 sc = result.FutureAPI.Response().StatusCode 146 } 147 tracing.EndSpan(ctx, sc, err) 148 }() 149 } 150 if err := validation.Validate([]validation.Validation{ 151 {TargetValue: resourceGroupName, 152 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil}, 153 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 154 {TargetValue: resourceName, 155 Constraints: []validation.Constraint{{Target: "resourceName", Name: validation.MaxLength, Rule: 63, Chain: nil}, 156 {Target: "resourceName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil { 157 return result, validation.NewError("digitaltwins.Client", "CreateOrUpdate", err.Error()) 158 } 159 160 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, resourceName, digitalTwinsCreate) 161 if err != nil { 162 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "CreateOrUpdate", nil, "Failure preparing request") 163 return 164 } 165 166 result, err = client.CreateOrUpdateSender(req) 167 if err != nil { 168 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "CreateOrUpdate", nil, "Failure sending request") 169 return 170 } 171 172 return 173} 174 175// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 176func (client Client) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, digitalTwinsCreate Description) (*http.Request, error) { 177 pathParameters := map[string]interface{}{ 178 "resourceGroupName": autorest.Encode("path", resourceGroupName), 179 "resourceName": autorest.Encode("path", resourceName), 180 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 181 } 182 183 const APIVersion = "2020-10-31" 184 queryParameters := map[string]interface{}{ 185 "api-version": APIVersion, 186 } 187 188 preparer := autorest.CreatePreparer( 189 autorest.AsContentType("application/json; charset=utf-8"), 190 autorest.AsPut(), 191 autorest.WithBaseURL(client.BaseURI), 192 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DigitalTwins/digitalTwinsInstances/{resourceName}", pathParameters), 193 autorest.WithJSON(digitalTwinsCreate), 194 autorest.WithQueryParameters(queryParameters)) 195 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 196} 197 198// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 199// http.Response Body if it receives an error. 200func (client Client) CreateOrUpdateSender(req *http.Request) (future CreateOrUpdateFuture, err error) { 201 var resp *http.Response 202 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 203 if err != nil { 204 return 205 } 206 var azf azure.Future 207 azf, err = azure.NewFutureFromResponse(resp) 208 future.FutureAPI = &azf 209 future.Result = func(client Client) (d Description, err error) { 210 var done bool 211 done, err = future.DoneWithContext(context.Background(), client) 212 if err != nil { 213 err = autorest.NewErrorWithError(err, "digitaltwins.CreateOrUpdateFuture", "Result", future.Response(), "Polling failure") 214 return 215 } 216 if !done { 217 err = azure.NewAsyncOpIncompleteError("digitaltwins.CreateOrUpdateFuture") 218 return 219 } 220 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 221 d.Response.Response, err = future.GetResult(sender) 222 if d.Response.Response == nil && err == nil { 223 err = autorest.NewErrorWithError(err, "digitaltwins.CreateOrUpdateFuture", "Result", nil, "received nil response and error") 224 } 225 if err == nil && d.Response.Response.StatusCode != http.StatusNoContent { 226 d, err = client.CreateOrUpdateResponder(d.Response.Response) 227 if err != nil { 228 err = autorest.NewErrorWithError(err, "digitaltwins.CreateOrUpdateFuture", "Result", d.Response.Response, "Failure responding to request") 229 } 230 } 231 return 232 } 233 return 234} 235 236// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 237// closes the http.Response Body. 238func (client Client) CreateOrUpdateResponder(resp *http.Response) (result Description, err error) { 239 err = autorest.Respond( 240 resp, 241 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 242 autorest.ByUnmarshallingJSON(&result), 243 autorest.ByClosing()) 244 result.Response = autorest.Response{Response: resp} 245 return 246} 247 248// Delete delete a DigitalTwinsInstance. 249// Parameters: 250// resourceGroupName - the name of the resource group that contains the DigitalTwinsInstance. 251// resourceName - the name of the DigitalTwinsInstance. 252func (client Client) Delete(ctx context.Context, resourceGroupName string, resourceName string) (result DeleteFuture, err error) { 253 if tracing.IsEnabled() { 254 ctx = tracing.StartSpan(ctx, fqdn+"/Client.Delete") 255 defer func() { 256 sc := -1 257 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 258 sc = result.FutureAPI.Response().StatusCode 259 } 260 tracing.EndSpan(ctx, sc, err) 261 }() 262 } 263 if err := validation.Validate([]validation.Validation{ 264 {TargetValue: resourceGroupName, 265 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil}, 266 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 267 {TargetValue: resourceName, 268 Constraints: []validation.Constraint{{Target: "resourceName", Name: validation.MaxLength, Rule: 63, Chain: nil}, 269 {Target: "resourceName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil { 270 return result, validation.NewError("digitaltwins.Client", "Delete", err.Error()) 271 } 272 273 req, err := client.DeletePreparer(ctx, resourceGroupName, resourceName) 274 if err != nil { 275 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Delete", nil, "Failure preparing request") 276 return 277 } 278 279 result, err = client.DeleteSender(req) 280 if err != nil { 281 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Delete", nil, "Failure sending request") 282 return 283 } 284 285 return 286} 287 288// DeletePreparer prepares the Delete request. 289func (client Client) DeletePreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) { 290 pathParameters := map[string]interface{}{ 291 "resourceGroupName": autorest.Encode("path", resourceGroupName), 292 "resourceName": autorest.Encode("path", resourceName), 293 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 294 } 295 296 const APIVersion = "2020-10-31" 297 queryParameters := map[string]interface{}{ 298 "api-version": APIVersion, 299 } 300 301 preparer := autorest.CreatePreparer( 302 autorest.AsDelete(), 303 autorest.WithBaseURL(client.BaseURI), 304 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DigitalTwins/digitalTwinsInstances/{resourceName}", pathParameters), 305 autorest.WithQueryParameters(queryParameters)) 306 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 307} 308 309// DeleteSender sends the Delete request. The method will close the 310// http.Response Body if it receives an error. 311func (client Client) DeleteSender(req *http.Request) (future DeleteFuture, err error) { 312 var resp *http.Response 313 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 314 if err != nil { 315 return 316 } 317 var azf azure.Future 318 azf, err = azure.NewFutureFromResponse(resp) 319 future.FutureAPI = &azf 320 future.Result = func(client Client) (d Description, err error) { 321 var done bool 322 done, err = future.DoneWithContext(context.Background(), client) 323 if err != nil { 324 err = autorest.NewErrorWithError(err, "digitaltwins.DeleteFuture", "Result", future.Response(), "Polling failure") 325 return 326 } 327 if !done { 328 err = azure.NewAsyncOpIncompleteError("digitaltwins.DeleteFuture") 329 return 330 } 331 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 332 d.Response.Response, err = future.GetResult(sender) 333 if d.Response.Response == nil && err == nil { 334 err = autorest.NewErrorWithError(err, "digitaltwins.DeleteFuture", "Result", nil, "received nil response and error") 335 } 336 if err == nil && d.Response.Response.StatusCode != http.StatusNoContent { 337 d, err = client.DeleteResponder(d.Response.Response) 338 if err != nil { 339 err = autorest.NewErrorWithError(err, "digitaltwins.DeleteFuture", "Result", d.Response.Response, "Failure responding to request") 340 } 341 } 342 return 343 } 344 return 345} 346 347// DeleteResponder handles the response to the Delete request. The method always 348// closes the http.Response Body. 349func (client Client) DeleteResponder(resp *http.Response) (result Description, err error) { 350 err = autorest.Respond( 351 resp, 352 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 353 autorest.ByUnmarshallingJSON(&result), 354 autorest.ByClosing()) 355 result.Response = autorest.Response{Response: resp} 356 return 357} 358 359// Get get DigitalTwinsInstances resource. 360// Parameters: 361// resourceGroupName - the name of the resource group that contains the DigitalTwinsInstance. 362// resourceName - the name of the DigitalTwinsInstance. 363func (client Client) Get(ctx context.Context, resourceGroupName string, resourceName string) (result Description, err error) { 364 if tracing.IsEnabled() { 365 ctx = tracing.StartSpan(ctx, fqdn+"/Client.Get") 366 defer func() { 367 sc := -1 368 if result.Response.Response != nil { 369 sc = result.Response.Response.StatusCode 370 } 371 tracing.EndSpan(ctx, sc, err) 372 }() 373 } 374 if err := validation.Validate([]validation.Validation{ 375 {TargetValue: resourceGroupName, 376 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil}, 377 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 378 {TargetValue: resourceName, 379 Constraints: []validation.Constraint{{Target: "resourceName", Name: validation.MaxLength, Rule: 63, Chain: nil}, 380 {Target: "resourceName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil { 381 return result, validation.NewError("digitaltwins.Client", "Get", err.Error()) 382 } 383 384 req, err := client.GetPreparer(ctx, resourceGroupName, resourceName) 385 if err != nil { 386 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Get", nil, "Failure preparing request") 387 return 388 } 389 390 resp, err := client.GetSender(req) 391 if err != nil { 392 result.Response = autorest.Response{Response: resp} 393 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Get", resp, "Failure sending request") 394 return 395 } 396 397 result, err = client.GetResponder(resp) 398 if err != nil { 399 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Get", resp, "Failure responding to request") 400 return 401 } 402 403 return 404} 405 406// GetPreparer prepares the Get request. 407func (client Client) GetPreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) { 408 pathParameters := map[string]interface{}{ 409 "resourceGroupName": autorest.Encode("path", resourceGroupName), 410 "resourceName": autorest.Encode("path", resourceName), 411 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 412 } 413 414 const APIVersion = "2020-10-31" 415 queryParameters := map[string]interface{}{ 416 "api-version": APIVersion, 417 } 418 419 preparer := autorest.CreatePreparer( 420 autorest.AsGet(), 421 autorest.WithBaseURL(client.BaseURI), 422 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DigitalTwins/digitalTwinsInstances/{resourceName}", pathParameters), 423 autorest.WithQueryParameters(queryParameters)) 424 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 425} 426 427// GetSender sends the Get request. The method will close the 428// http.Response Body if it receives an error. 429func (client Client) GetSender(req *http.Request) (*http.Response, error) { 430 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 431} 432 433// GetResponder handles the response to the Get request. The method always 434// closes the http.Response Body. 435func (client Client) GetResponder(resp *http.Response) (result Description, err error) { 436 err = autorest.Respond( 437 resp, 438 azure.WithErrorUnlessStatusCode(http.StatusOK), 439 autorest.ByUnmarshallingJSON(&result), 440 autorest.ByClosing()) 441 result.Response = autorest.Response{Response: resp} 442 return 443} 444 445// List get all the DigitalTwinsInstances in a subscription. 446func (client Client) List(ctx context.Context) (result DescriptionListResultPage, err error) { 447 if tracing.IsEnabled() { 448 ctx = tracing.StartSpan(ctx, fqdn+"/Client.List") 449 defer func() { 450 sc := -1 451 if result.dlr.Response.Response != nil { 452 sc = result.dlr.Response.Response.StatusCode 453 } 454 tracing.EndSpan(ctx, sc, err) 455 }() 456 } 457 result.fn = client.listNextResults 458 req, err := client.ListPreparer(ctx) 459 if err != nil { 460 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "List", nil, "Failure preparing request") 461 return 462 } 463 464 resp, err := client.ListSender(req) 465 if err != nil { 466 result.dlr.Response = autorest.Response{Response: resp} 467 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "List", resp, "Failure sending request") 468 return 469 } 470 471 result.dlr, err = client.ListResponder(resp) 472 if err != nil { 473 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "List", resp, "Failure responding to request") 474 return 475 } 476 if result.dlr.hasNextLink() && result.dlr.IsEmpty() { 477 err = result.NextWithContext(ctx) 478 return 479 } 480 481 return 482} 483 484// ListPreparer prepares the List request. 485func (client Client) ListPreparer(ctx context.Context) (*http.Request, error) { 486 pathParameters := map[string]interface{}{ 487 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 488 } 489 490 const APIVersion = "2020-10-31" 491 queryParameters := map[string]interface{}{ 492 "api-version": APIVersion, 493 } 494 495 preparer := autorest.CreatePreparer( 496 autorest.AsGet(), 497 autorest.WithBaseURL(client.BaseURI), 498 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DigitalTwins/digitalTwinsInstances", pathParameters), 499 autorest.WithQueryParameters(queryParameters)) 500 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 501} 502 503// ListSender sends the List request. The method will close the 504// http.Response Body if it receives an error. 505func (client Client) ListSender(req *http.Request) (*http.Response, error) { 506 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 507} 508 509// ListResponder handles the response to the List request. The method always 510// closes the http.Response Body. 511func (client Client) ListResponder(resp *http.Response) (result DescriptionListResult, err error) { 512 err = autorest.Respond( 513 resp, 514 azure.WithErrorUnlessStatusCode(http.StatusOK), 515 autorest.ByUnmarshallingJSON(&result), 516 autorest.ByClosing()) 517 result.Response = autorest.Response{Response: resp} 518 return 519} 520 521// listNextResults retrieves the next set of results, if any. 522func (client Client) listNextResults(ctx context.Context, lastResults DescriptionListResult) (result DescriptionListResult, err error) { 523 req, err := lastResults.descriptionListResultPreparer(ctx) 524 if err != nil { 525 return result, autorest.NewErrorWithError(err, "digitaltwins.Client", "listNextResults", nil, "Failure preparing next results request") 526 } 527 if req == nil { 528 return 529 } 530 resp, err := client.ListSender(req) 531 if err != nil { 532 result.Response = autorest.Response{Response: resp} 533 return result, autorest.NewErrorWithError(err, "digitaltwins.Client", "listNextResults", resp, "Failure sending next results request") 534 } 535 result, err = client.ListResponder(resp) 536 if err != nil { 537 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "listNextResults", resp, "Failure responding to next results request") 538 } 539 return 540} 541 542// ListComplete enumerates all values, automatically crossing page boundaries as required. 543func (client Client) ListComplete(ctx context.Context) (result DescriptionListResultIterator, err error) { 544 if tracing.IsEnabled() { 545 ctx = tracing.StartSpan(ctx, fqdn+"/Client.List") 546 defer func() { 547 sc := -1 548 if result.Response().Response.Response != nil { 549 sc = result.page.Response().Response.Response.StatusCode 550 } 551 tracing.EndSpan(ctx, sc, err) 552 }() 553 } 554 result.page, err = client.List(ctx) 555 return 556} 557 558// ListByResourceGroup get all the DigitalTwinsInstances in a resource group. 559// Parameters: 560// resourceGroupName - the name of the resource group that contains the DigitalTwinsInstance. 561func (client Client) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result DescriptionListResultPage, err error) { 562 if tracing.IsEnabled() { 563 ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListByResourceGroup") 564 defer func() { 565 sc := -1 566 if result.dlr.Response.Response != nil { 567 sc = result.dlr.Response.Response.StatusCode 568 } 569 tracing.EndSpan(ctx, sc, err) 570 }() 571 } 572 if err := validation.Validate([]validation.Validation{ 573 {TargetValue: resourceGroupName, 574 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil}, 575 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 576 return result, validation.NewError("digitaltwins.Client", "ListByResourceGroup", err.Error()) 577 } 578 579 result.fn = client.listByResourceGroupNextResults 580 req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName) 581 if err != nil { 582 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "ListByResourceGroup", nil, "Failure preparing request") 583 return 584 } 585 586 resp, err := client.ListByResourceGroupSender(req) 587 if err != nil { 588 result.dlr.Response = autorest.Response{Response: resp} 589 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "ListByResourceGroup", resp, "Failure sending request") 590 return 591 } 592 593 result.dlr, err = client.ListByResourceGroupResponder(resp) 594 if err != nil { 595 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "ListByResourceGroup", resp, "Failure responding to request") 596 return 597 } 598 if result.dlr.hasNextLink() && result.dlr.IsEmpty() { 599 err = result.NextWithContext(ctx) 600 return 601 } 602 603 return 604} 605 606// ListByResourceGroupPreparer prepares the ListByResourceGroup request. 607func (client Client) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { 608 pathParameters := map[string]interface{}{ 609 "resourceGroupName": autorest.Encode("path", resourceGroupName), 610 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 611 } 612 613 const APIVersion = "2020-10-31" 614 queryParameters := map[string]interface{}{ 615 "api-version": APIVersion, 616 } 617 618 preparer := autorest.CreatePreparer( 619 autorest.AsGet(), 620 autorest.WithBaseURL(client.BaseURI), 621 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DigitalTwins/digitalTwinsInstances", pathParameters), 622 autorest.WithQueryParameters(queryParameters)) 623 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 624} 625 626// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the 627// http.Response Body if it receives an error. 628func (client Client) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { 629 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 630} 631 632// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always 633// closes the http.Response Body. 634func (client Client) ListByResourceGroupResponder(resp *http.Response) (result DescriptionListResult, err error) { 635 err = autorest.Respond( 636 resp, 637 azure.WithErrorUnlessStatusCode(http.StatusOK), 638 autorest.ByUnmarshallingJSON(&result), 639 autorest.ByClosing()) 640 result.Response = autorest.Response{Response: resp} 641 return 642} 643 644// listByResourceGroupNextResults retrieves the next set of results, if any. 645func (client Client) listByResourceGroupNextResults(ctx context.Context, lastResults DescriptionListResult) (result DescriptionListResult, err error) { 646 req, err := lastResults.descriptionListResultPreparer(ctx) 647 if err != nil { 648 return result, autorest.NewErrorWithError(err, "digitaltwins.Client", "listByResourceGroupNextResults", nil, "Failure preparing next results request") 649 } 650 if req == nil { 651 return 652 } 653 resp, err := client.ListByResourceGroupSender(req) 654 if err != nil { 655 result.Response = autorest.Response{Response: resp} 656 return result, autorest.NewErrorWithError(err, "digitaltwins.Client", "listByResourceGroupNextResults", resp, "Failure sending next results request") 657 } 658 result, err = client.ListByResourceGroupResponder(resp) 659 if err != nil { 660 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "listByResourceGroupNextResults", resp, "Failure responding to next results request") 661 } 662 return 663} 664 665// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. 666func (client Client) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result DescriptionListResultIterator, err error) { 667 if tracing.IsEnabled() { 668 ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListByResourceGroup") 669 defer func() { 670 sc := -1 671 if result.Response().Response.Response != nil { 672 sc = result.page.Response().Response.Response.StatusCode 673 } 674 tracing.EndSpan(ctx, sc, err) 675 }() 676 } 677 result.page, err = client.ListByResourceGroup(ctx, resourceGroupName) 678 return 679} 680 681// Update update metadata of DigitalTwinsInstance. 682// Parameters: 683// resourceGroupName - the name of the resource group that contains the DigitalTwinsInstance. 684// resourceName - the name of the DigitalTwinsInstance. 685// digitalTwinsPatchDescription - the DigitalTwinsInstance and security metadata. 686func (client Client) Update(ctx context.Context, resourceGroupName string, resourceName string, digitalTwinsPatchDescription PatchDescription) (result Description, err error) { 687 if tracing.IsEnabled() { 688 ctx = tracing.StartSpan(ctx, fqdn+"/Client.Update") 689 defer func() { 690 sc := -1 691 if result.Response.Response != nil { 692 sc = result.Response.Response.StatusCode 693 } 694 tracing.EndSpan(ctx, sc, err) 695 }() 696 } 697 if err := validation.Validate([]validation.Validation{ 698 {TargetValue: resourceGroupName, 699 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil}, 700 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 701 {TargetValue: resourceName, 702 Constraints: []validation.Constraint{{Target: "resourceName", Name: validation.MaxLength, Rule: 63, Chain: nil}, 703 {Target: "resourceName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil { 704 return result, validation.NewError("digitaltwins.Client", "Update", err.Error()) 705 } 706 707 req, err := client.UpdatePreparer(ctx, resourceGroupName, resourceName, digitalTwinsPatchDescription) 708 if err != nil { 709 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Update", nil, "Failure preparing request") 710 return 711 } 712 713 resp, err := client.UpdateSender(req) 714 if err != nil { 715 result.Response = autorest.Response{Response: resp} 716 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Update", resp, "Failure sending request") 717 return 718 } 719 720 result, err = client.UpdateResponder(resp) 721 if err != nil { 722 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Update", resp, "Failure responding to request") 723 return 724 } 725 726 return 727} 728 729// UpdatePreparer prepares the Update request. 730func (client Client) UpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, digitalTwinsPatchDescription PatchDescription) (*http.Request, error) { 731 pathParameters := map[string]interface{}{ 732 "resourceGroupName": autorest.Encode("path", resourceGroupName), 733 "resourceName": autorest.Encode("path", resourceName), 734 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 735 } 736 737 const APIVersion = "2020-10-31" 738 queryParameters := map[string]interface{}{ 739 "api-version": APIVersion, 740 } 741 742 preparer := autorest.CreatePreparer( 743 autorest.AsContentType("application/json; charset=utf-8"), 744 autorest.AsPatch(), 745 autorest.WithBaseURL(client.BaseURI), 746 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DigitalTwins/digitalTwinsInstances/{resourceName}", pathParameters), 747 autorest.WithJSON(digitalTwinsPatchDescription), 748 autorest.WithQueryParameters(queryParameters)) 749 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 750} 751 752// UpdateSender sends the Update request. The method will close the 753// http.Response Body if it receives an error. 754func (client Client) UpdateSender(req *http.Request) (*http.Response, error) { 755 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 756} 757 758// UpdateResponder handles the response to the Update request. The method always 759// closes the http.Response Body. 760func (client Client) UpdateResponder(resp *http.Response) (result Description, err error) { 761 err = autorest.Respond( 762 resp, 763 azure.WithErrorUnlessStatusCode(http.StatusOK), 764 autorest.ByUnmarshallingJSON(&result), 765 autorest.ByClosing()) 766 result.Response = autorest.Response{Response: resp} 767 return 768} 769