1package cognitiveservices 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// AccountsClient is the cognitive Services Management Client 30type AccountsClient struct { 31 BaseClient 32} 33 34// NewAccountsClient creates an instance of the AccountsClient client. 35func NewAccountsClient(subscriptionID string) AccountsClient { 36 return NewAccountsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewAccountsClientWithBaseURI creates an instance of the AccountsClient client using a custom endpoint. Use this 40// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewAccountsClientWithBaseURI(baseURI string, subscriptionID string) AccountsClient { 42 return AccountsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// Create create Cognitive Services Account. Accounts is a resource group wide resource type. It holds the keys for 46// developer to access intelligent APIs. It's also the resource type for billing. 47// Parameters: 48// resourceGroupName - the name of the resource group within the user's subscription. 49// accountName - the name of the cognitive services account within the specified resource group. Cognitive 50// Services account names must be between 3 and 24 characters in length and use numbers and lower-case letters 51// only. 52// parameters - the parameters to provide for the created account. 53func (client AccountsClient) Create(ctx context.Context, resourceGroupName string, accountName string, parameters AccountCreateParameters) (result Account, err error) { 54 if tracing.IsEnabled() { 55 ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.Create") 56 defer func() { 57 sc := -1 58 if result.Response.Response != nil { 59 sc = result.Response.Response.StatusCode 60 } 61 tracing.EndSpan(ctx, sc, err) 62 }() 63 } 64 if err := validation.Validate([]validation.Validation{ 65 {TargetValue: accountName, 66 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 67 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}, 68 {Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}, 69 {TargetValue: parameters, 70 Constraints: []validation.Constraint{{Target: "parameters.Sku", Name: validation.Null, Rule: true, Chain: nil}, 71 {Target: "parameters.Location", Name: validation.Null, Rule: true, Chain: nil}, 72 {Target: "parameters.Properties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 73 return result, validation.NewError("cognitiveservices.AccountsClient", "Create", err.Error()) 74 } 75 76 req, err := client.CreatePreparer(ctx, resourceGroupName, accountName, parameters) 77 if err != nil { 78 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Create", nil, "Failure preparing request") 79 return 80 } 81 82 resp, err := client.CreateSender(req) 83 if err != nil { 84 result.Response = autorest.Response{Response: resp} 85 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Create", resp, "Failure sending request") 86 return 87 } 88 89 result, err = client.CreateResponder(resp) 90 if err != nil { 91 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Create", resp, "Failure responding to request") 92 } 93 94 return 95} 96 97// CreatePreparer prepares the Create request. 98func (client AccountsClient) CreatePreparer(ctx context.Context, resourceGroupName string, accountName string, parameters AccountCreateParameters) (*http.Request, error) { 99 pathParameters := map[string]interface{}{ 100 "accountName": autorest.Encode("path", accountName), 101 "resourceGroupName": autorest.Encode("path", resourceGroupName), 102 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 103 } 104 105 const APIVersion = "2016-02-01-preview" 106 queryParameters := map[string]interface{}{ 107 "api-version": APIVersion, 108 } 109 110 preparer := autorest.CreatePreparer( 111 autorest.AsContentType("application/json; charset=utf-8"), 112 autorest.AsPut(), 113 autorest.WithBaseURL(client.BaseURI), 114 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}", pathParameters), 115 autorest.WithJSON(parameters), 116 autorest.WithQueryParameters(queryParameters)) 117 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 118} 119 120// CreateSender sends the Create request. The method will close the 121// http.Response Body if it receives an error. 122func (client AccountsClient) CreateSender(req *http.Request) (*http.Response, error) { 123 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 124} 125 126// CreateResponder handles the response to the Create request. The method always 127// closes the http.Response Body. 128func (client AccountsClient) CreateResponder(resp *http.Response) (result Account, err error) { 129 err = autorest.Respond( 130 resp, 131 client.ByInspecting(), 132 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 133 autorest.ByUnmarshallingJSON(&result), 134 autorest.ByClosing()) 135 result.Response = autorest.Response{Response: resp} 136 return 137} 138 139// Delete deletes a Cognitive Services account from the resource group. 140// Parameters: 141// resourceGroupName - the name of the resource group within the user's subscription. 142// accountName - the name of the cognitive services account within the specified resource group. Cognitive 143// Services account names must be between 3 and 24 characters in length and use numbers and lower-case letters 144// only. 145func (client AccountsClient) Delete(ctx context.Context, resourceGroupName string, accountName string) (result autorest.Response, err error) { 146 if tracing.IsEnabled() { 147 ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.Delete") 148 defer func() { 149 sc := -1 150 if result.Response != nil { 151 sc = result.Response.StatusCode 152 } 153 tracing.EndSpan(ctx, sc, err) 154 }() 155 } 156 if err := validation.Validate([]validation.Validation{ 157 {TargetValue: accountName, 158 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 159 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}, 160 {Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil { 161 return result, validation.NewError("cognitiveservices.AccountsClient", "Delete", err.Error()) 162 } 163 164 req, err := client.DeletePreparer(ctx, resourceGroupName, accountName) 165 if err != nil { 166 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Delete", nil, "Failure preparing request") 167 return 168 } 169 170 resp, err := client.DeleteSender(req) 171 if err != nil { 172 result.Response = resp 173 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Delete", resp, "Failure sending request") 174 return 175 } 176 177 result, err = client.DeleteResponder(resp) 178 if err != nil { 179 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Delete", resp, "Failure responding to request") 180 } 181 182 return 183} 184 185// DeletePreparer prepares the Delete request. 186func (client AccountsClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) { 187 pathParameters := map[string]interface{}{ 188 "accountName": autorest.Encode("path", accountName), 189 "resourceGroupName": autorest.Encode("path", resourceGroupName), 190 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 191 } 192 193 const APIVersion = "2016-02-01-preview" 194 queryParameters := map[string]interface{}{ 195 "api-version": APIVersion, 196 } 197 198 preparer := autorest.CreatePreparer( 199 autorest.AsDelete(), 200 autorest.WithBaseURL(client.BaseURI), 201 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}", pathParameters), 202 autorest.WithQueryParameters(queryParameters)) 203 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 204} 205 206// DeleteSender sends the Delete request. The method will close the 207// http.Response Body if it receives an error. 208func (client AccountsClient) DeleteSender(req *http.Request) (*http.Response, error) { 209 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 210} 211 212// DeleteResponder handles the response to the Delete request. The method always 213// closes the http.Response Body. 214func (client AccountsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 215 err = autorest.Respond( 216 resp, 217 client.ByInspecting(), 218 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 219 autorest.ByClosing()) 220 result.Response = resp 221 return 222} 223 224// GetProperties returns a Cognitive Services account specified by the parameters. 225// Parameters: 226// resourceGroupName - the name of the resource group within the user's subscription. 227// accountName - the name of the cognitive services account within the specified resource group. Cognitive 228// Services account names must be between 3 and 24 characters in length and use numbers and lower-case letters 229// only. 230func (client AccountsClient) GetProperties(ctx context.Context, resourceGroupName string, accountName string) (result Account, err error) { 231 if tracing.IsEnabled() { 232 ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.GetProperties") 233 defer func() { 234 sc := -1 235 if result.Response.Response != nil { 236 sc = result.Response.Response.StatusCode 237 } 238 tracing.EndSpan(ctx, sc, err) 239 }() 240 } 241 if err := validation.Validate([]validation.Validation{ 242 {TargetValue: accountName, 243 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 244 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}, 245 {Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil { 246 return result, validation.NewError("cognitiveservices.AccountsClient", "GetProperties", err.Error()) 247 } 248 249 req, err := client.GetPropertiesPreparer(ctx, resourceGroupName, accountName) 250 if err != nil { 251 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "GetProperties", nil, "Failure preparing request") 252 return 253 } 254 255 resp, err := client.GetPropertiesSender(req) 256 if err != nil { 257 result.Response = autorest.Response{Response: resp} 258 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "GetProperties", resp, "Failure sending request") 259 return 260 } 261 262 result, err = client.GetPropertiesResponder(resp) 263 if err != nil { 264 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "GetProperties", resp, "Failure responding to request") 265 } 266 267 return 268} 269 270// GetPropertiesPreparer prepares the GetProperties request. 271func (client AccountsClient) GetPropertiesPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) { 272 pathParameters := map[string]interface{}{ 273 "accountName": autorest.Encode("path", accountName), 274 "resourceGroupName": autorest.Encode("path", resourceGroupName), 275 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 276 } 277 278 const APIVersion = "2016-02-01-preview" 279 queryParameters := map[string]interface{}{ 280 "api-version": APIVersion, 281 } 282 283 preparer := autorest.CreatePreparer( 284 autorest.AsGet(), 285 autorest.WithBaseURL(client.BaseURI), 286 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}", pathParameters), 287 autorest.WithQueryParameters(queryParameters)) 288 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 289} 290 291// GetPropertiesSender sends the GetProperties request. The method will close the 292// http.Response Body if it receives an error. 293func (client AccountsClient) GetPropertiesSender(req *http.Request) (*http.Response, error) { 294 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 295} 296 297// GetPropertiesResponder handles the response to the GetProperties request. The method always 298// closes the http.Response Body. 299func (client AccountsClient) GetPropertiesResponder(resp *http.Response) (result Account, err error) { 300 err = autorest.Respond( 301 resp, 302 client.ByInspecting(), 303 azure.WithErrorUnlessStatusCode(http.StatusOK), 304 autorest.ByUnmarshallingJSON(&result), 305 autorest.ByClosing()) 306 result.Response = autorest.Response{Response: resp} 307 return 308} 309 310// List returns all the resources of a particular type belonging to a subscription. 311func (client AccountsClient) List(ctx context.Context) (result AccountListResult, err error) { 312 if tracing.IsEnabled() { 313 ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.List") 314 defer func() { 315 sc := -1 316 if result.Response.Response != nil { 317 sc = result.Response.Response.StatusCode 318 } 319 tracing.EndSpan(ctx, sc, err) 320 }() 321 } 322 req, err := client.ListPreparer(ctx) 323 if err != nil { 324 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "List", nil, "Failure preparing request") 325 return 326 } 327 328 resp, err := client.ListSender(req) 329 if err != nil { 330 result.Response = autorest.Response{Response: resp} 331 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "List", resp, "Failure sending request") 332 return 333 } 334 335 result, err = client.ListResponder(resp) 336 if err != nil { 337 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "List", resp, "Failure responding to request") 338 } 339 340 return 341} 342 343// ListPreparer prepares the List request. 344func (client AccountsClient) ListPreparer(ctx context.Context) (*http.Request, error) { 345 pathParameters := map[string]interface{}{ 346 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 347 } 348 349 const APIVersion = "2016-02-01-preview" 350 queryParameters := map[string]interface{}{ 351 "api-version": APIVersion, 352 } 353 354 preparer := autorest.CreatePreparer( 355 autorest.AsGet(), 356 autorest.WithBaseURL(client.BaseURI), 357 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.CognitiveServices/accounts", pathParameters), 358 autorest.WithQueryParameters(queryParameters)) 359 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 360} 361 362// ListSender sends the List request. The method will close the 363// http.Response Body if it receives an error. 364func (client AccountsClient) ListSender(req *http.Request) (*http.Response, error) { 365 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 366} 367 368// ListResponder handles the response to the List request. The method always 369// closes the http.Response Body. 370func (client AccountsClient) ListResponder(resp *http.Response) (result AccountListResult, err error) { 371 err = autorest.Respond( 372 resp, 373 client.ByInspecting(), 374 azure.WithErrorUnlessStatusCode(http.StatusOK), 375 autorest.ByUnmarshallingJSON(&result), 376 autorest.ByClosing()) 377 result.Response = autorest.Response{Response: resp} 378 return 379} 380 381// ListByResourceGroup returns all the resources of a particular type belonging to a resource group 382// Parameters: 383// resourceGroupName - the name of the resource group within the user's subscription. 384func (client AccountsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result AccountListResult, err error) { 385 if tracing.IsEnabled() { 386 ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.ListByResourceGroup") 387 defer func() { 388 sc := -1 389 if result.Response.Response != nil { 390 sc = result.Response.Response.StatusCode 391 } 392 tracing.EndSpan(ctx, sc, err) 393 }() 394 } 395 req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName) 396 if err != nil { 397 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListByResourceGroup", nil, "Failure preparing request") 398 return 399 } 400 401 resp, err := client.ListByResourceGroupSender(req) 402 if err != nil { 403 result.Response = autorest.Response{Response: resp} 404 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListByResourceGroup", resp, "Failure sending request") 405 return 406 } 407 408 result, err = client.ListByResourceGroupResponder(resp) 409 if err != nil { 410 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListByResourceGroup", resp, "Failure responding to request") 411 } 412 413 return 414} 415 416// ListByResourceGroupPreparer prepares the ListByResourceGroup request. 417func (client AccountsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { 418 pathParameters := map[string]interface{}{ 419 "resourceGroupName": autorest.Encode("path", resourceGroupName), 420 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 421 } 422 423 const APIVersion = "2016-02-01-preview" 424 queryParameters := map[string]interface{}{ 425 "api-version": APIVersion, 426 } 427 428 preparer := autorest.CreatePreparer( 429 autorest.AsGet(), 430 autorest.WithBaseURL(client.BaseURI), 431 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts", pathParameters), 432 autorest.WithQueryParameters(queryParameters)) 433 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 434} 435 436// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the 437// http.Response Body if it receives an error. 438func (client AccountsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { 439 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 440} 441 442// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always 443// closes the http.Response Body. 444func (client AccountsClient) ListByResourceGroupResponder(resp *http.Response) (result AccountListResult, err error) { 445 err = autorest.Respond( 446 resp, 447 client.ByInspecting(), 448 azure.WithErrorUnlessStatusCode(http.StatusOK), 449 autorest.ByUnmarshallingJSON(&result), 450 autorest.ByClosing()) 451 result.Response = autorest.Response{Response: resp} 452 return 453} 454 455// ListKeys lists the account keys for the specified Cognitive Services account. 456// Parameters: 457// resourceGroupName - the name of the resource group within the user's subscription. 458// accountName - the name of the cognitive services account within the specified resource group. Cognitive 459// Services account names must be between 3 and 24 characters in length and use numbers and lower-case letters 460// only. 461func (client AccountsClient) ListKeys(ctx context.Context, resourceGroupName string, accountName string) (result AccountKeys, err error) { 462 if tracing.IsEnabled() { 463 ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.ListKeys") 464 defer func() { 465 sc := -1 466 if result.Response.Response != nil { 467 sc = result.Response.Response.StatusCode 468 } 469 tracing.EndSpan(ctx, sc, err) 470 }() 471 } 472 if err := validation.Validate([]validation.Validation{ 473 {TargetValue: accountName, 474 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 475 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}, 476 {Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil { 477 return result, validation.NewError("cognitiveservices.AccountsClient", "ListKeys", err.Error()) 478 } 479 480 req, err := client.ListKeysPreparer(ctx, resourceGroupName, accountName) 481 if err != nil { 482 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListKeys", nil, "Failure preparing request") 483 return 484 } 485 486 resp, err := client.ListKeysSender(req) 487 if err != nil { 488 result.Response = autorest.Response{Response: resp} 489 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListKeys", resp, "Failure sending request") 490 return 491 } 492 493 result, err = client.ListKeysResponder(resp) 494 if err != nil { 495 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListKeys", resp, "Failure responding to request") 496 } 497 498 return 499} 500 501// ListKeysPreparer prepares the ListKeys request. 502func (client AccountsClient) ListKeysPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) { 503 pathParameters := map[string]interface{}{ 504 "accountName": autorest.Encode("path", accountName), 505 "resourceGroupName": autorest.Encode("path", resourceGroupName), 506 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 507 } 508 509 const APIVersion = "2016-02-01-preview" 510 queryParameters := map[string]interface{}{ 511 "api-version": APIVersion, 512 } 513 514 preparer := autorest.CreatePreparer( 515 autorest.AsPost(), 516 autorest.WithBaseURL(client.BaseURI), 517 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}/listKeys", pathParameters), 518 autorest.WithQueryParameters(queryParameters)) 519 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 520} 521 522// ListKeysSender sends the ListKeys request. The method will close the 523// http.Response Body if it receives an error. 524func (client AccountsClient) ListKeysSender(req *http.Request) (*http.Response, error) { 525 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 526} 527 528// ListKeysResponder handles the response to the ListKeys request. The method always 529// closes the http.Response Body. 530func (client AccountsClient) ListKeysResponder(resp *http.Response) (result AccountKeys, err error) { 531 err = autorest.Respond( 532 resp, 533 client.ByInspecting(), 534 azure.WithErrorUnlessStatusCode(http.StatusOK), 535 autorest.ByUnmarshallingJSON(&result), 536 autorest.ByClosing()) 537 result.Response = autorest.Response{Response: resp} 538 return 539} 540 541// ListSkus list available SKUs for the requested Cognitive Services account 542// Parameters: 543// resourceGroupName - the name of the resource group within the user's subscription. 544// accountName - the name of the cognitive services account within the specified resource group. Cognitive 545// Services account names must be between 3 and 24 characters in length and use numbers and lower-case letters 546// only. 547func (client AccountsClient) ListSkus(ctx context.Context, resourceGroupName string, accountName string) (result AccountEnumerateSkusResult, err error) { 548 if tracing.IsEnabled() { 549 ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.ListSkus") 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: accountName, 560 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 561 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}, 562 {Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil { 563 return result, validation.NewError("cognitiveservices.AccountsClient", "ListSkus", err.Error()) 564 } 565 566 req, err := client.ListSkusPreparer(ctx, resourceGroupName, accountName) 567 if err != nil { 568 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListSkus", nil, "Failure preparing request") 569 return 570 } 571 572 resp, err := client.ListSkusSender(req) 573 if err != nil { 574 result.Response = autorest.Response{Response: resp} 575 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListSkus", resp, "Failure sending request") 576 return 577 } 578 579 result, err = client.ListSkusResponder(resp) 580 if err != nil { 581 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListSkus", resp, "Failure responding to request") 582 } 583 584 return 585} 586 587// ListSkusPreparer prepares the ListSkus request. 588func (client AccountsClient) ListSkusPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) { 589 pathParameters := map[string]interface{}{ 590 "accountName": autorest.Encode("path", accountName), 591 "resourceGroupName": autorest.Encode("path", resourceGroupName), 592 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 593 } 594 595 const APIVersion = "2016-02-01-preview" 596 queryParameters := map[string]interface{}{ 597 "api-version": APIVersion, 598 } 599 600 preparer := autorest.CreatePreparer( 601 autorest.AsGet(), 602 autorest.WithBaseURL(client.BaseURI), 603 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}/skus", pathParameters), 604 autorest.WithQueryParameters(queryParameters)) 605 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 606} 607 608// ListSkusSender sends the ListSkus request. The method will close the 609// http.Response Body if it receives an error. 610func (client AccountsClient) ListSkusSender(req *http.Request) (*http.Response, error) { 611 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 612} 613 614// ListSkusResponder handles the response to the ListSkus request. The method always 615// closes the http.Response Body. 616func (client AccountsClient) ListSkusResponder(resp *http.Response) (result AccountEnumerateSkusResult, err error) { 617 err = autorest.Respond( 618 resp, 619 client.ByInspecting(), 620 azure.WithErrorUnlessStatusCode(http.StatusOK), 621 autorest.ByUnmarshallingJSON(&result), 622 autorest.ByClosing()) 623 result.Response = autorest.Response{Response: resp} 624 return 625} 626 627// RegenerateKey regenerates the specified account key for the specified Cognitive Services account. 628// Parameters: 629// resourceGroupName - the name of the resource group within the user's subscription. 630// accountName - the name of the cognitive services account within the specified resource group. Cognitive 631// Services account names must be between 3 and 24 characters in length and use numbers and lower-case letters 632// only. 633// body - regenerate key parameters. 634func (client AccountsClient) RegenerateKey(ctx context.Context, resourceGroupName string, accountName string, body RegenerateKeyParameters) (result AccountKeys, err error) { 635 if tracing.IsEnabled() { 636 ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.RegenerateKey") 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 if err := validation.Validate([]validation.Validation{ 646 {TargetValue: accountName, 647 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 648 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}, 649 {Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil { 650 return result, validation.NewError("cognitiveservices.AccountsClient", "RegenerateKey", err.Error()) 651 } 652 653 req, err := client.RegenerateKeyPreparer(ctx, resourceGroupName, accountName, body) 654 if err != nil { 655 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "RegenerateKey", nil, "Failure preparing request") 656 return 657 } 658 659 resp, err := client.RegenerateKeySender(req) 660 if err != nil { 661 result.Response = autorest.Response{Response: resp} 662 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "RegenerateKey", resp, "Failure sending request") 663 return 664 } 665 666 result, err = client.RegenerateKeyResponder(resp) 667 if err != nil { 668 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "RegenerateKey", resp, "Failure responding to request") 669 } 670 671 return 672} 673 674// RegenerateKeyPreparer prepares the RegenerateKey request. 675func (client AccountsClient) RegenerateKeyPreparer(ctx context.Context, resourceGroupName string, accountName string, body RegenerateKeyParameters) (*http.Request, error) { 676 pathParameters := map[string]interface{}{ 677 "accountName": autorest.Encode("path", accountName), 678 "resourceGroupName": autorest.Encode("path", resourceGroupName), 679 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 680 } 681 682 const APIVersion = "2016-02-01-preview" 683 queryParameters := map[string]interface{}{ 684 "api-version": APIVersion, 685 } 686 687 preparer := autorest.CreatePreparer( 688 autorest.AsContentType("application/json; charset=utf-8"), 689 autorest.AsPost(), 690 autorest.WithBaseURL(client.BaseURI), 691 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}/regenerateKey", pathParameters), 692 autorest.WithJSON(body), 693 autorest.WithQueryParameters(queryParameters)) 694 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 695} 696 697// RegenerateKeySender sends the RegenerateKey request. The method will close the 698// http.Response Body if it receives an error. 699func (client AccountsClient) RegenerateKeySender(req *http.Request) (*http.Response, error) { 700 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 701} 702 703// RegenerateKeyResponder handles the response to the RegenerateKey request. The method always 704// closes the http.Response Body. 705func (client AccountsClient) RegenerateKeyResponder(resp *http.Response) (result AccountKeys, err error) { 706 err = autorest.Respond( 707 resp, 708 client.ByInspecting(), 709 azure.WithErrorUnlessStatusCode(http.StatusOK), 710 autorest.ByUnmarshallingJSON(&result), 711 autorest.ByClosing()) 712 result.Response = autorest.Response{Response: resp} 713 return 714} 715 716// Update updates a Cognitive Services account 717// Parameters: 718// resourceGroupName - the name of the resource group within the user's subscription. 719// accountName - the name of the cognitive services account within the specified resource group. Cognitive 720// Services account names must be between 3 and 24 characters in length and use numbers and lower-case letters 721// only. 722// body - the parameters to provide for the created account. 723func (client AccountsClient) Update(ctx context.Context, resourceGroupName string, accountName string, body AccountUpdateParameters) (result Account, err error) { 724 if tracing.IsEnabled() { 725 ctx = tracing.StartSpan(ctx, fqdn+"/AccountsClient.Update") 726 defer func() { 727 sc := -1 728 if result.Response.Response != nil { 729 sc = result.Response.Response.StatusCode 730 } 731 tracing.EndSpan(ctx, sc, err) 732 }() 733 } 734 if err := validation.Validate([]validation.Validation{ 735 {TargetValue: accountName, 736 Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil}, 737 {Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil}, 738 {Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil { 739 return result, validation.NewError("cognitiveservices.AccountsClient", "Update", err.Error()) 740 } 741 742 req, err := client.UpdatePreparer(ctx, resourceGroupName, accountName, body) 743 if err != nil { 744 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Update", nil, "Failure preparing request") 745 return 746 } 747 748 resp, err := client.UpdateSender(req) 749 if err != nil { 750 result.Response = autorest.Response{Response: resp} 751 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Update", resp, "Failure sending request") 752 return 753 } 754 755 result, err = client.UpdateResponder(resp) 756 if err != nil { 757 err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Update", resp, "Failure responding to request") 758 } 759 760 return 761} 762 763// UpdatePreparer prepares the Update request. 764func (client AccountsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, body AccountUpdateParameters) (*http.Request, error) { 765 pathParameters := map[string]interface{}{ 766 "accountName": autorest.Encode("path", accountName), 767 "resourceGroupName": autorest.Encode("path", resourceGroupName), 768 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 769 } 770 771 const APIVersion = "2016-02-01-preview" 772 queryParameters := map[string]interface{}{ 773 "api-version": APIVersion, 774 } 775 776 preparer := autorest.CreatePreparer( 777 autorest.AsContentType("application/json; charset=utf-8"), 778 autorest.AsPatch(), 779 autorest.WithBaseURL(client.BaseURI), 780 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}", pathParameters), 781 autorest.WithJSON(body), 782 autorest.WithQueryParameters(queryParameters)) 783 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 784} 785 786// UpdateSender sends the Update request. The method will close the 787// http.Response Body if it receives an error. 788func (client AccountsClient) UpdateSender(req *http.Request) (*http.Response, error) { 789 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 790} 791 792// UpdateResponder handles the response to the Update request. The method always 793// closes the http.Response Body. 794func (client AccountsClient) UpdateResponder(resp *http.Response) (result Account, err error) { 795 err = autorest.Respond( 796 resp, 797 client.ByInspecting(), 798 azure.WithErrorUnlessStatusCode(http.StatusOK), 799 autorest.ByUnmarshallingJSON(&result), 800 autorest.ByClosing()) 801 result.Response = autorest.Response{Response: resp} 802 return 803} 804