From dcc7c6b95c430ebc4eb2ec3279ccf43d08498d44 Mon Sep 17 00:00:00 2001 From: Gabriel Nepomuceno Date: Sat, 3 Mar 2018 10:48:27 +0000 Subject: [PATCH 1/2] New Resource: `azurerm_cognitive_account` --- azurerm/config.go | 11 + azurerm/helpers/validate/cognitiveservices.go | 15 + .../validate/cognitiveservices_test.go | 78 ++ azurerm/provider.go | 2 + azurerm/resource_arm_cognitive_account.go | 263 +++++ .../resource_arm_cognitive_account_test.go | 197 ++++ .../2017-04-18/cognitiveservices/accounts.go | 842 ++++++++++++++++ .../cognitiveservices/checkskuavailability.go | 116 +++ .../2017-04-18/cognitiveservices/client.go | 51 + .../2017-04-18/cognitiveservices/models.go | 936 ++++++++++++++++++ .../cognitiveservices/operations.go | 126 +++ .../cognitiveservices/resourceskus.go | 130 +++ .../2017-04-18/cognitiveservices/version.go | 30 + vendor/vendor.json | 8 + website/azurerm.erb | 11 + .../docs/r/cognitive_account.html.markdown | 76 ++ 16 files changed, 2892 insertions(+) create mode 100644 azurerm/helpers/validate/cognitiveservices.go create mode 100644 azurerm/helpers/validate/cognitiveservices_test.go create mode 100644 azurerm/resource_arm_cognitive_account.go create mode 100644 azurerm/resource_arm_cognitive_account_test.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/accounts.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/checkskuavailability.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/client.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/models.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/operations.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/resourceskus.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/version.go create mode 100644 website/docs/r/cognitive_account.html.markdown diff --git a/azurerm/config.go b/azurerm/config.go index dfe6b05132b8..ee049598a63c 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -13,6 +13,7 @@ import ( appinsights "github.com/Azure/azure-sdk-for-go/services/appinsights/mgmt/2015-05-01/insights" "github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation" "github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2017-10-12/cdn" + "github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-06-01/compute" "github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-04-01/containerinstance" "github.com/Azure/azure-sdk-for-go/services/containerregistry/mgmt/2017-10-01/containerregistry" @@ -123,6 +124,9 @@ type ArmClient struct { cdnEndpointsClient cdn.EndpointsClient cdnProfilesClient cdn.ProfilesClient + // Cognitive Services + cognitiveAccountsClient cognitiveservices.AccountsClient + // Compute availSetClient compute.AvailabilitySetsClient diskClient compute.DisksClient @@ -452,6 +456,7 @@ func getArmClient(c *authentication.Config) (*ArmClient, error) { client.registerAutomationClients(endpoint, c.SubscriptionID, auth, sender) client.registerAuthentication(endpoint, graphEndpoint, c.SubscriptionID, c.TenantID, auth, graphAuth, sender) client.registerCDNClients(endpoint, c.SubscriptionID, auth, sender) + client.registerCognitiveServiceClients(endpoint, c.SubscriptionID, auth, sender) client.registerComputeClients(endpoint, c.SubscriptionID, auth, sender) client.registerContainerInstanceClients(endpoint, c.SubscriptionID, auth, sender) client.registerContainerRegistryClients(endpoint, c.SubscriptionID, auth, sender) @@ -547,6 +552,12 @@ func (c *ArmClient) registerCDNClients(endpoint, subscriptionId string, auth aut c.cdnProfilesClient = profilesClient } +func (c *ArmClient) registerCognitiveServiceClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) { + accountsClient := cognitiveservices.NewAccountsClientWithBaseURI(endpoint, subscriptionId) + c.configureClient(&accountsClient.Client, auth) + c.cognitiveAccountsClient = accountsClient +} + func (c *ArmClient) registerCosmosDBClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) { cdb := documentdb.NewDatabaseAccountsClientWithBaseURI(endpoint, subscriptionId) c.configureClient(&cdb.Client, auth) diff --git a/azurerm/helpers/validate/cognitiveservices.go b/azurerm/helpers/validate/cognitiveservices.go new file mode 100644 index 000000000000..cc997358c152 --- /dev/null +++ b/azurerm/helpers/validate/cognitiveservices.go @@ -0,0 +1,15 @@ +package validate + +import ( + "regexp" + + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" +) + +func CognitiveServicesAccountName() schema.SchemaValidateFunc { + return validation.StringMatch( + regexp.MustCompile("^([a-zA-Z0-9]{1}[a-zA-Z0-9_.-]{1,})$"), + "The Cognitive Services Account Name can only start with an alphanumeric character, and must only contain alphanumeric characters, periods, dashes or underscores.", + ) +} diff --git a/azurerm/helpers/validate/cognitiveservices_test.go b/azurerm/helpers/validate/cognitiveservices_test.go new file mode 100644 index 000000000000..099a6c57e5be --- /dev/null +++ b/azurerm/helpers/validate/cognitiveservices_test.go @@ -0,0 +1,78 @@ +package validate + +import ( + "testing" +) + +func TestValidateCognitiveServicesAccountName(t *testing.T) { + tests := []struct { + name string + input string + valid bool + }{ + { + name: "empty name", + input: "", + valid: false, + }, + { + name: "Valid short name", + input: "abc", + valid: true, + }, + { + name: "Invalid short name", + input: "a", + valid: false, + }, + { + name: "Valid short name", + input: "ab", + valid: true, + }, + { + name: "Valid long name", + input: "abc_-.123", + valid: true, + }, + { + name: "Valid with a digit at the end", + input: "hello1", + valid: true, + }, + { + name: "Valid with a digit in the middle", + input: "hello1", + valid: true, + }, + { + name: "Invalid with a digit at the start", + input: "1hello", + valid: true, + }, + { + name: "Invalid with a period at the start", + input: ".heyo", + valid: false, + }, + { + name: "Valid name with period in the middle", + input: "a.bc", + valid: true, + }, + { + name: "Valid name with period at end", + input: "a.", + valid: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + _, err := CognitiveServicesAccountName()(tt.input, "") + valid := err == nil + if valid != tt.valid { + t.Errorf("Expected valid status %t but got %t for input %s", tt.valid, valid, tt.input) + } + }) + } +} diff --git a/azurerm/provider.go b/azurerm/provider.go index 645eecf5d33b..667350562234 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -147,6 +147,7 @@ func Provider() terraform.ResourceProvider { "azurerm_availability_set": resourceArmAvailabilitySet(), "azurerm_cdn_endpoint": resourceArmCdnEndpoint(), "azurerm_cdn_profile": resourceArmCdnProfile(), + "azurerm_cognitive_account": resourceArmCognitiveAccount(), "azurerm_container_registry": resourceArmContainerRegistry(), "azurerm_container_service": resourceArmContainerService(), "azurerm_container_group": resourceArmContainerGroup(), @@ -382,6 +383,7 @@ func determineAzureResourceProvidersToRegister(providerList []resources.Provider "Microsoft.Automation": {}, "Microsoft.Cache": {}, "Microsoft.Cdn": {}, + "Microsoft.CognitiveServices": {}, "Microsoft.Compute": {}, "Microsoft.ContainerInstance": {}, "Microsoft.ContainerRegistry": {}, diff --git a/azurerm/resource_arm_cognitive_account.go b/azurerm/resource_arm_cognitive_account.go new file mode 100644 index 000000000000..4f1975c17824 --- /dev/null +++ b/azurerm/resource_arm_cognitive_account.go @@ -0,0 +1,263 @@ +package azurerm + +import ( + "fmt" + "log" + + "github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices" + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +type cognitiveServicesPropertiesStruct struct{} + +func resourceArmCognitiveAccount() *schema.Resource { + return &schema.Resource{ + Create: resourceArmCognitiveAccountCreate, + Read: resourceArmCognitiveAccountRead, + Update: resourceArmCognitiveAccountUpdate, + Delete: resourceArmCognitiveAccountDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.CognitiveServicesAccountName(), + }, + + "location": locationSchema(), + + "resource_group_name": resourceGroupNameSchema(), + + "kind": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + "Academic", + "Bing.Autosuggest", + "Bing.Autosuggest.v7", + "Bing.CustomSearch", + "Bing.Search", + "Bing.Search.v7", + "Bing.Speech", + "Bing.SpellCheck", + "Bing.SpellCheck.v7", + "ComputerVision", + "ContentModerator", + "CustomSpeech", + "Emotion", + "Face", + "LUIS", + "Recommendations", + "SpeakerRecognition", + "Speech", + "SpeechTranslation", + "TextAnalytics", + "TextTranslation", + "WebLM", + }, false), + }, + + "sku": { + Type: schema.TypeList, + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(cognitiveservices.F0), + string(cognitiveservices.S0), + string(cognitiveservices.S1), + string(cognitiveservices.S2), + string(cognitiveservices.S3), + string(cognitiveservices.S4), + string(cognitiveservices.S5), + string(cognitiveservices.S6), + string(cognitiveservices.P0), + string(cognitiveservices.P1), + string(cognitiveservices.P2), + }, false), + }, + + "tier": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(cognitiveservices.Free), + string(cognitiveservices.Standard), + string(cognitiveservices.Premium), + }, false), + }, + }, + }, + }, + + "tags": tagsSchema(), + + "endpoint": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func resourceArmCognitiveAccountCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cognitiveAccountsClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + location := azureRMNormalizeLocation(d.Get("location").(string)) + resourceGroup := d.Get("resource_group_name").(string) + kind := d.Get("kind").(string) + tags := d.Get("tags").(map[string]interface{}) + sku := expandCognitiveAccountSku(d) + + properties := cognitiveservices.AccountCreateParameters{ + Kind: cognitiveservices.Kind(kind), + Location: utils.String(location), + Sku: sku, + Properties: &cognitiveServicesPropertiesStruct{}, + Tags: expandTags(tags), + } + + _, err := client.Create(ctx, resourceGroup, name, properties) + if err != nil { + return fmt.Errorf("Error creating Cognitive Services Account %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + read, err := client.GetProperties(ctx, resourceGroup, name) + if err != nil { + return fmt.Errorf("Error retrieving Cognitive Services Account %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + d.SetId(*read.ID) + + return resourceArmCognitiveAccountRead(d, meta) +} + +func resourceArmCognitiveAccountUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cognitiveAccountsClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + + resourceGroup := id.ResourceGroup + name := id.Path["accounts"] + + tags := d.Get("tags").(map[string]interface{}) + sku := expandCognitiveAccountSku(d) + + properties := cognitiveservices.AccountUpdateParameters{ + Sku: sku, + Tags: expandTags(tags), + } + + _, err = client.Update(ctx, resourceGroup, name, properties) + if err != nil { + return fmt.Errorf("Error updating Cognitive Services Account %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + return resourceArmCognitiveAccountRead(d, meta) +} + +func resourceArmCognitiveAccountRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cognitiveAccountsClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + + resourceGroup := id.ResourceGroup + name := id.Path["accounts"] + + resp, err := client.GetProperties(ctx, resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[DEBUG] Cognitive Services Account %q was not found in Resource Group %q - removing from state!", name, resourceGroup) + d.SetId("") + return nil + } + return err + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", resourceGroup) + d.Set("kind", resp.Kind) + + if location := resp.Location; location != nil { + d.Set("location", azureRMNormalizeLocation(*location)) + } + + if err := d.Set("sku", flattenCognitiveAccountSku(resp.Sku)); err != nil { + return fmt.Errorf("Error flattening `sku`: %+v", err) + } + + if props := resp.AccountProperties; props != nil { + d.Set("endpoint", props.Endpoint) + } + + flattenAndSetTags(d, resp.Tags) + + return nil +} + +func resourceArmCognitiveAccountDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cognitiveAccountsClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + + resourceGroup := id.ResourceGroup + name := id.Path["accounts"] + + resp, err := client.Delete(ctx, resourceGroup, name) + if err != nil { + if !response.WasNotFound(resp.Response) { + return fmt.Errorf("Error deleting Cognitive Services Account %q (Resource Group %q): %+v", name, resourceGroup, err) + } + } + + return nil +} + +func expandCognitiveAccountSku(d *schema.ResourceData) *cognitiveservices.Sku { + skus := d.Get("sku").([]interface{}) + sku := skus[0].(map[string]interface{}) + + return &cognitiveservices.Sku{ + Name: cognitiveservices.SkuName(sku["name"].(string)), + Tier: cognitiveservices.SkuTier(sku["tier"].(string)), + } +} + +func flattenCognitiveAccountSku(input *cognitiveservices.Sku) []interface{} { + if input == nil { + return []interface{}{} + } + + return []interface{}{ + map[string]interface{}{ + "name": string(input.Name), + "tier": string(input.Tier), + }, + } +} diff --git a/azurerm/resource_arm_cognitive_account_test.go b/azurerm/resource_arm_cognitive_account_test.go new file mode 100644 index 000000000000..a97481a0143d --- /dev/null +++ b/azurerm/resource_arm_cognitive_account_test.go @@ -0,0 +1,197 @@ +package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMCognitiveAccount_basic(t *testing.T) { + resourceName := "azurerm_cognitive_account.test" + ri := acctest.RandInt() + config := testAccAzureRMCognitiveAccount_basic(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppCognitiveAccountDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMCognitiveAccountExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "kind", "Face"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMCognitiveAccount_complete(t *testing.T) { + resourceName := "azurerm_cognitive_account.test" + ri := acctest.RandInt() + config := testAccAzureRMCognitiveAccount_complete(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppCognitiveAccountDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMCognitiveAccountExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "kind", "Face"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.Acceptance", "Test"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMCognitiveAccount_update(t *testing.T) { + resourceName := "azurerm_cognitive_account.test" + ri := acctest.RandInt() + location := testLocation() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppCognitiveAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCognitiveAccount_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMCognitiveAccountExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "kind", "Face"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + ), + }, + { + Config: testAccAzureRMCognitiveAccount_complete(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMCognitiveAccountExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "kind", "Face"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.Acceptance", "Test"), + ), + }, + }, + }) +} + +func testCheckAzureRMAppCognitiveAccountDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).cognitiveAccountsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_cognitive_account" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.GetProperties(ctx, resourceGroup, name) + if err != nil { + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Cognitive Services Account still exists:\n%#v", resp) + } + + return nil + } + + } + + return nil +} + +func testCheckAzureRMCognitiveAccountExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + conn := testAccProvider.Meta().(*ArmClient).cognitiveAccountsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + resp, err := conn.GetProperties(ctx, resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Cognitive Services Account %q (Resource Group: %q) does not exist", name, resourceGroup) + } + + return fmt.Errorf("Bad: Get on cognitiveAccountsClient: %+v", err) + } + + return nil + } +} + +func testAccAzureRMCognitiveAccount_basic(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestrg-%d" + location = "%s" +} + +resource "azurerm_cognitive_account" "test" { + name = "acctestcogacc-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + kind = "Face" + + sku { + name = "S0" + tier = "Standard" + } +} +`, rInt, location, rInt) +} + +func testAccAzureRMCognitiveAccount_complete(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestrg-%d" + location = "%s" +} + +resource "azurerm_cognitive_account" "test" { + name = "acctestcogacc-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + kind = "Face" + + sku { + name = "S0" + tier = "Standard" + } + + tags { + Acceptance = "Test" + } +} +`, rInt, location, rInt) +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/accounts.go b/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/accounts.go new file mode 100644 index 000000000000..d873e761f210 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/accounts.go @@ -0,0 +1,842 @@ +package cognitiveservices + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// AccountsClient is the cognitive Services Management Client +type AccountsClient struct { + BaseClient +} + +// NewAccountsClient creates an instance of the AccountsClient client. +func NewAccountsClient(subscriptionID string) AccountsClient { + return NewAccountsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewAccountsClientWithBaseURI creates an instance of the AccountsClient client. +func NewAccountsClientWithBaseURI(baseURI string, subscriptionID string) AccountsClient { + return AccountsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// Create create Cognitive Services Account. Accounts is a resource group wide resource type. It holds the keys for +// developer to access intelligent APIs. It's also the resource type for billing. +// Parameters: +// resourceGroupName - the name of the resource group within the user's subscription. +// accountName - the name of Cognitive Services account. +// parameters - the parameters to provide for the created account. +func (client AccountsClient) Create(ctx context.Context, resourceGroupName string, accountName string, parameters AccountCreateParameters) (result Account, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: accountName, + Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 64, Chain: nil}, + {Target: "accountName", Name: validation.MinLength, Rule: 2, Chain: nil}, + {Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}, + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.Sku", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "parameters.Location", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "parameters.Properties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("cognitiveservices.AccountsClient", "Create", err.Error()) + } + + req, err := client.CreatePreparer(ctx, resourceGroupName, accountName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Create", resp, "Failure responding to request") + } + + return +} + +// CreatePreparer prepares the Create request. +func (client AccountsClient) CreatePreparer(ctx context.Context, resourceGroupName string, accountName string, parameters AccountCreateParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "accountName": autorest.Encode("path", accountName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-18" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client AccountsClient) CreateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client AccountsClient) CreateResponder(resp *http.Response) (result Account, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete deletes a Cognitive Services account from the resource group. +// Parameters: +// resourceGroupName - the name of the resource group within the user's subscription. +// accountName - the name of Cognitive Services account. +func (client AccountsClient) Delete(ctx context.Context, resourceGroupName string, accountName string) (result autorest.Response, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: accountName, + Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 64, Chain: nil}, + {Target: "accountName", Name: validation.MinLength, Rule: 2, Chain: nil}, + {Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("cognitiveservices.AccountsClient", "Delete", err.Error()) + } + + req, err := client.DeletePreparer(ctx, resourceGroupName, accountName) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client AccountsClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "accountName": autorest.Encode("path", accountName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-18" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client AccountsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client AccountsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// GetProperties returns a Cognitive Services account specified by the parameters. +// Parameters: +// resourceGroupName - the name of the resource group within the user's subscription. +// accountName - the name of Cognitive Services account. +func (client AccountsClient) GetProperties(ctx context.Context, resourceGroupName string, accountName string) (result Account, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: accountName, + Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 64, Chain: nil}, + {Target: "accountName", Name: validation.MinLength, Rule: 2, Chain: nil}, + {Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("cognitiveservices.AccountsClient", "GetProperties", err.Error()) + } + + req, err := client.GetPropertiesPreparer(ctx, resourceGroupName, accountName) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "GetProperties", nil, "Failure preparing request") + return + } + + resp, err := client.GetPropertiesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "GetProperties", resp, "Failure sending request") + return + } + + result, err = client.GetPropertiesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "GetProperties", resp, "Failure responding to request") + } + + return +} + +// GetPropertiesPreparer prepares the GetProperties request. +func (client AccountsClient) GetPropertiesPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "accountName": autorest.Encode("path", accountName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-18" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetPropertiesSender sends the GetProperties request. The method will close the +// http.Response Body if it receives an error. +func (client AccountsClient) GetPropertiesSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// GetPropertiesResponder handles the response to the GetProperties request. The method always +// closes the http.Response Body. +func (client AccountsClient) GetPropertiesResponder(resp *http.Response) (result Account, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetUsages get usages for the requested Cognitive Services account +// Parameters: +// resourceGroupName - the name of the resource group within the user's subscription. +// accountName - the name of Cognitive Services account. +// filter - an OData filter expression that describes a subset of usages to return. The supported parameter is +// name.value (name of the metric, can have an or of multiple names). +func (client AccountsClient) GetUsages(ctx context.Context, resourceGroupName string, accountName string, filter string) (result UsagesResult, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: accountName, + Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 64, Chain: nil}, + {Target: "accountName", Name: validation.MinLength, Rule: 2, Chain: nil}, + {Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("cognitiveservices.AccountsClient", "GetUsages", err.Error()) + } + + req, err := client.GetUsagesPreparer(ctx, resourceGroupName, accountName, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "GetUsages", nil, "Failure preparing request") + return + } + + resp, err := client.GetUsagesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "GetUsages", resp, "Failure sending request") + return + } + + result, err = client.GetUsagesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "GetUsages", resp, "Failure responding to request") + } + + return +} + +// GetUsagesPreparer prepares the GetUsages request. +func (client AccountsClient) GetUsagesPreparer(ctx context.Context, resourceGroupName string, accountName string, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "accountName": autorest.Encode("path", accountName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-18" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}/usages", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetUsagesSender sends the GetUsages request. The method will close the +// http.Response Body if it receives an error. +func (client AccountsClient) GetUsagesSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// GetUsagesResponder handles the response to the GetUsages request. The method always +// closes the http.Response Body. +func (client AccountsClient) GetUsagesResponder(resp *http.Response) (result UsagesResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List returns all the resources of a particular type belonging to a subscription. +func (client AccountsClient) List(ctx context.Context) (result AccountListResultPage, err error) { + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.alr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "List", resp, "Failure sending request") + return + } + + result.alr, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client AccountsClient) ListPreparer(ctx context.Context) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-18" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.CognitiveServices/accounts", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client AccountsClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client AccountsClient) ListResponder(resp *http.Response) (result AccountListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client AccountsClient) listNextResults(lastResults AccountListResult) (result AccountListResult, err error) { + req, err := lastResults.accountListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client AccountsClient) ListComplete(ctx context.Context) (result AccountListResultIterator, err error) { + result.page, err = client.List(ctx) + return +} + +// ListByResourceGroup returns all the resources of a particular type belonging to a resource group +// Parameters: +// resourceGroupName - the name of the resource group within the user's subscription. +func (client AccountsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result AccountListResultPage, err error) { + result.fn = client.listByResourceGroupNextResults + req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.alr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListByResourceGroup", resp, "Failure sending request") + return + } + + result.alr, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListByResourceGroup", resp, "Failure responding to request") + } + + return +} + +// ListByResourceGroupPreparer prepares the ListByResourceGroup request. +func (client AccountsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-18" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client AccountsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (client AccountsClient) ListByResourceGroupResponder(resp *http.Response) (result AccountListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listByResourceGroupNextResults retrieves the next set of results, if any. +func (client AccountsClient) listByResourceGroupNextResults(lastResults AccountListResult) (result AccountListResult, err error) { + req, err := lastResults.accountListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "listByResourceGroupNextResults", resp, "Failure sending next results request") + } + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. +func (client AccountsClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result AccountListResultIterator, err error) { + result.page, err = client.ListByResourceGroup(ctx, resourceGroupName) + return +} + +// ListKeys lists the account keys for the specified Cognitive Services account. +// Parameters: +// resourceGroupName - the name of the resource group within the user's subscription. +// accountName - the name of Cognitive Services account. +func (client AccountsClient) ListKeys(ctx context.Context, resourceGroupName string, accountName string) (result AccountKeys, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: accountName, + Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 64, Chain: nil}, + {Target: "accountName", Name: validation.MinLength, Rule: 2, Chain: nil}, + {Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("cognitiveservices.AccountsClient", "ListKeys", err.Error()) + } + + req, err := client.ListKeysPreparer(ctx, resourceGroupName, accountName) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListKeys", nil, "Failure preparing request") + return + } + + resp, err := client.ListKeysSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListKeys", resp, "Failure sending request") + return + } + + result, err = client.ListKeysResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListKeys", resp, "Failure responding to request") + } + + return +} + +// ListKeysPreparer prepares the ListKeys request. +func (client AccountsClient) ListKeysPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "accountName": autorest.Encode("path", accountName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-18" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}/listKeys", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListKeysSender sends the ListKeys request. The method will close the +// http.Response Body if it receives an error. +func (client AccountsClient) ListKeysSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListKeysResponder handles the response to the ListKeys request. The method always +// closes the http.Response Body. +func (client AccountsClient) ListKeysResponder(resp *http.Response) (result AccountKeys, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListSkus list available SKUs for the requested Cognitive Services account +// Parameters: +// resourceGroupName - the name of the resource group within the user's subscription. +// accountName - the name of Cognitive Services account. +func (client AccountsClient) ListSkus(ctx context.Context, resourceGroupName string, accountName string) (result AccountEnumerateSkusResult, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: accountName, + Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 64, Chain: nil}, + {Target: "accountName", Name: validation.MinLength, Rule: 2, Chain: nil}, + {Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("cognitiveservices.AccountsClient", "ListSkus", err.Error()) + } + + req, err := client.ListSkusPreparer(ctx, resourceGroupName, accountName) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListSkus", nil, "Failure preparing request") + return + } + + resp, err := client.ListSkusSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListSkus", resp, "Failure sending request") + return + } + + result, err = client.ListSkusResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "ListSkus", resp, "Failure responding to request") + } + + return +} + +// ListSkusPreparer prepares the ListSkus request. +func (client AccountsClient) ListSkusPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "accountName": autorest.Encode("path", accountName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-18" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}/skus", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSkusSender sends the ListSkus request. The method will close the +// http.Response Body if it receives an error. +func (client AccountsClient) ListSkusSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListSkusResponder handles the response to the ListSkus request. The method always +// closes the http.Response Body. +func (client AccountsClient) ListSkusResponder(resp *http.Response) (result AccountEnumerateSkusResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// RegenerateKey regenerates the specified account key for the specified Cognitive Services account. +// Parameters: +// resourceGroupName - the name of the resource group within the user's subscription. +// accountName - the name of Cognitive Services account. +// parameters - regenerate key parameters. +func (client AccountsClient) RegenerateKey(ctx context.Context, resourceGroupName string, accountName string, parameters RegenerateKeyParameters) (result AccountKeys, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: accountName, + Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 64, Chain: nil}, + {Target: "accountName", Name: validation.MinLength, Rule: 2, Chain: nil}, + {Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("cognitiveservices.AccountsClient", "RegenerateKey", err.Error()) + } + + req, err := client.RegenerateKeyPreparer(ctx, resourceGroupName, accountName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "RegenerateKey", nil, "Failure preparing request") + return + } + + resp, err := client.RegenerateKeySender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "RegenerateKey", resp, "Failure sending request") + return + } + + result, err = client.RegenerateKeyResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "RegenerateKey", resp, "Failure responding to request") + } + + return +} + +// RegenerateKeyPreparer prepares the RegenerateKey request. +func (client AccountsClient) RegenerateKeyPreparer(ctx context.Context, resourceGroupName string, accountName string, parameters RegenerateKeyParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "accountName": autorest.Encode("path", accountName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-18" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}/regenerateKey", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RegenerateKeySender sends the RegenerateKey request. The method will close the +// http.Response Body if it receives an error. +func (client AccountsClient) RegenerateKeySender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// RegenerateKeyResponder handles the response to the RegenerateKey request. The method always +// closes the http.Response Body. +func (client AccountsClient) RegenerateKeyResponder(resp *http.Response) (result AccountKeys, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Update updates a Cognitive Services account +// Parameters: +// resourceGroupName - the name of the resource group within the user's subscription. +// accountName - the name of Cognitive Services account. +// parameters - the parameters to provide for the created account. +func (client AccountsClient) Update(ctx context.Context, resourceGroupName string, accountName string, parameters AccountUpdateParameters) (result Account, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: accountName, + Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 64, Chain: nil}, + {Target: "accountName", Name: validation.MinLength, Rule: 2, Chain: nil}, + {Target: "accountName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("cognitiveservices.AccountsClient", "Update", err.Error()) + } + + req, err := client.UpdatePreparer(ctx, resourceGroupName, accountName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.AccountsClient", "Update", resp, "Failure responding to request") + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client AccountsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, parameters AccountUpdateParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "accountName": autorest.Encode("path", accountName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-18" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices/accounts/{accountName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client AccountsClient) UpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client AccountsClient) UpdateResponder(resp *http.Response) (result Account, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/checkskuavailability.go b/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/checkskuavailability.go new file mode 100644 index 000000000000..a8bcd57afdd1 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/checkskuavailability.go @@ -0,0 +1,116 @@ +package cognitiveservices + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// CheckSkuAvailabilityClient is the cognitive Services Management Client +type CheckSkuAvailabilityClient struct { + BaseClient +} + +// NewCheckSkuAvailabilityClient creates an instance of the CheckSkuAvailabilityClient client. +func NewCheckSkuAvailabilityClient(subscriptionID string) CheckSkuAvailabilityClient { + return NewCheckSkuAvailabilityClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewCheckSkuAvailabilityClientWithBaseURI creates an instance of the CheckSkuAvailabilityClient client. +func NewCheckSkuAvailabilityClientWithBaseURI(baseURI string, subscriptionID string) CheckSkuAvailabilityClient { + return CheckSkuAvailabilityClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List check available SKUs. +// Parameters: +// location - resource location. +// parameters - check SKU Availablity POST body. +func (client CheckSkuAvailabilityClient) List(ctx context.Context, location string, parameters CheckSkuAvailabilityParameter) (result CheckSkuAvailabilityResultList, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.Skus", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "parameters.Type", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("cognitiveservices.CheckSkuAvailabilityClient", "List", err.Error()) + } + + req, err := client.ListPreparer(ctx, location, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.CheckSkuAvailabilityClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "cognitiveservices.CheckSkuAvailabilityClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.CheckSkuAvailabilityClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client CheckSkuAvailabilityClient) ListPreparer(ctx context.Context, location string, parameters CheckSkuAvailabilityParameter) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "location": autorest.Encode("path", location), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-18" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.CognitiveServices/locations/{location}/checkSkuAvailability", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client CheckSkuAvailabilityClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client CheckSkuAvailabilityClient) ListResponder(resp *http.Response) (result CheckSkuAvailabilityResultList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/client.go b/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/client.go new file mode 100644 index 000000000000..83d2865d93df --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/client.go @@ -0,0 +1,51 @@ +// Package cognitiveservices implements the Azure ARM Cognitiveservices service API version 2017-04-18. +// +// Cognitive Services Management Client +package cognitiveservices + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" +) + +const ( + // DefaultBaseURI is the default URI used for the service Cognitiveservices + DefaultBaseURI = "https://management.azure.com" +) + +// BaseClient is the base client for Cognitiveservices. +type BaseClient struct { + autorest.Client + BaseURI string + SubscriptionID string +} + +// New creates an instance of the BaseClient client. +func New(subscriptionID string) BaseClient { + return NewWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewWithBaseURI creates an instance of the BaseClient client. +func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { + return BaseClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + BaseURI: baseURI, + SubscriptionID: subscriptionID, + } +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/models.go b/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/models.go new file mode 100644 index 000000000000..619aeee25618 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/models.go @@ -0,0 +1,936 @@ +package cognitiveservices + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "encoding/json" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/to" + "net/http" +) + +// KeyName enumerates the values for key name. +type KeyName string + +const ( + // Key1 ... + Key1 KeyName = "Key1" + // Key2 ... + Key2 KeyName = "Key2" +) + +// PossibleKeyNameValues returns an array of possible values for the KeyName const type. +func PossibleKeyNameValues() []KeyName { + return []KeyName{Key1, Key2} +} + +// Kind enumerates the values for kind. +type Kind string + +const ( + // BingAutosuggestv7 ... + BingAutosuggestv7 Kind = "Bing.Autosuggest.v7" + // BingCustomSearch ... + BingCustomSearch Kind = "Bing.CustomSearch" + // BingSearchv7 ... + BingSearchv7 Kind = "Bing.Search.v7" + // BingSpeech ... + BingSpeech Kind = "Bing.Speech" + // BingSpellCheckv7 ... + BingSpellCheckv7 Kind = "Bing.SpellCheck.v7" + // ComputerVision ... + ComputerVision Kind = "ComputerVision" + // ContentModerator ... + ContentModerator Kind = "ContentModerator" + // CustomSpeech ... + CustomSpeech Kind = "CustomSpeech" + // CustomVisionPrediction ... + CustomVisionPrediction Kind = "CustomVision.Prediction" + // CustomVisionTraining ... + CustomVisionTraining Kind = "CustomVision.Training" + // Emotion ... + Emotion Kind = "Emotion" + // Face ... + Face Kind = "Face" + // LUIS ... + LUIS Kind = "LUIS" + // QnAMaker ... + QnAMaker Kind = "QnAMaker" + // SpeakerRecognition ... + SpeakerRecognition Kind = "SpeakerRecognition" + // SpeechTranslation ... + SpeechTranslation Kind = "SpeechTranslation" + // TextAnalytics ... + TextAnalytics Kind = "TextAnalytics" + // TextTranslation ... + TextTranslation Kind = "TextTranslation" + // WebLM ... + WebLM Kind = "WebLM" +) + +// PossibleKindValues returns an array of possible values for the Kind const type. +func PossibleKindValues() []Kind { + return []Kind{BingAutosuggestv7, BingCustomSearch, BingSearchv7, BingSpeech, BingSpellCheckv7, ComputerVision, ContentModerator, CustomSpeech, CustomVisionPrediction, CustomVisionTraining, Emotion, Face, LUIS, QnAMaker, SpeakerRecognition, SpeechTranslation, TextAnalytics, TextTranslation, WebLM} +} + +// ProvisioningState enumerates the values for provisioning state. +type ProvisioningState string + +const ( + // Creating ... + Creating ProvisioningState = "Creating" + // Deleting ... + Deleting ProvisioningState = "Deleting" + // Failed ... + Failed ProvisioningState = "Failed" + // Moving ... + Moving ProvisioningState = "Moving" + // ResolvingDNS ... + ResolvingDNS ProvisioningState = "ResolvingDNS" + // Succeeded ... + Succeeded ProvisioningState = "Succeeded" +) + +// PossibleProvisioningStateValues returns an array of possible values for the ProvisioningState const type. +func PossibleProvisioningStateValues() []ProvisioningState { + return []ProvisioningState{Creating, Deleting, Failed, Moving, ResolvingDNS, Succeeded} +} + +// QuotaUsageStatus enumerates the values for quota usage status. +type QuotaUsageStatus string + +const ( + // Blocked ... + Blocked QuotaUsageStatus = "Blocked" + // Included ... + Included QuotaUsageStatus = "Included" + // InOverage ... + InOverage QuotaUsageStatus = "InOverage" + // Unknown ... + Unknown QuotaUsageStatus = "Unknown" +) + +// PossibleQuotaUsageStatusValues returns an array of possible values for the QuotaUsageStatus const type. +func PossibleQuotaUsageStatusValues() []QuotaUsageStatus { + return []QuotaUsageStatus{Blocked, Included, InOverage, Unknown} +} + +// ResourceSkuRestrictionsReasonCode enumerates the values for resource sku restrictions reason code. +type ResourceSkuRestrictionsReasonCode string + +const ( + // NotAvailableForSubscription ... + NotAvailableForSubscription ResourceSkuRestrictionsReasonCode = "NotAvailableForSubscription" + // QuotaID ... + QuotaID ResourceSkuRestrictionsReasonCode = "QuotaId" +) + +// PossibleResourceSkuRestrictionsReasonCodeValues returns an array of possible values for the ResourceSkuRestrictionsReasonCode const type. +func PossibleResourceSkuRestrictionsReasonCodeValues() []ResourceSkuRestrictionsReasonCode { + return []ResourceSkuRestrictionsReasonCode{NotAvailableForSubscription, QuotaID} +} + +// ResourceSkuRestrictionsType enumerates the values for resource sku restrictions type. +type ResourceSkuRestrictionsType string + +const ( + // Location ... + Location ResourceSkuRestrictionsType = "Location" + // Zone ... + Zone ResourceSkuRestrictionsType = "Zone" +) + +// PossibleResourceSkuRestrictionsTypeValues returns an array of possible values for the ResourceSkuRestrictionsType const type. +func PossibleResourceSkuRestrictionsTypeValues() []ResourceSkuRestrictionsType { + return []ResourceSkuRestrictionsType{Location, Zone} +} + +// SkuName enumerates the values for sku name. +type SkuName string + +const ( + // F0 ... + F0 SkuName = "F0" + // P0 ... + P0 SkuName = "P0" + // P1 ... + P1 SkuName = "P1" + // P2 ... + P2 SkuName = "P2" + // S0 ... + S0 SkuName = "S0" + // S1 ... + S1 SkuName = "S1" + // S2 ... + S2 SkuName = "S2" + // S3 ... + S3 SkuName = "S3" + // S4 ... + S4 SkuName = "S4" + // S5 ... + S5 SkuName = "S5" + // S6 ... + S6 SkuName = "S6" +) + +// PossibleSkuNameValues returns an array of possible values for the SkuName const type. +func PossibleSkuNameValues() []SkuName { + return []SkuName{F0, P0, P1, P2, S0, S1, S2, S3, S4, S5, S6} +} + +// SkuTier enumerates the values for sku tier. +type SkuTier string + +const ( + // Free ... + Free SkuTier = "Free" + // Premium ... + Premium SkuTier = "Premium" + // Standard ... + Standard SkuTier = "Standard" +) + +// PossibleSkuTierValues returns an array of possible values for the SkuTier const type. +func PossibleSkuTierValues() []SkuTier { + return []SkuTier{Free, Premium, Standard} +} + +// UnitType enumerates the values for unit type. +type UnitType string + +const ( + // Bytes ... + Bytes UnitType = "Bytes" + // BytesPerSecond ... + BytesPerSecond UnitType = "BytesPerSecond" + // Count ... + Count UnitType = "Count" + // CountPerSecond ... + CountPerSecond UnitType = "CountPerSecond" + // Milliseconds ... + Milliseconds UnitType = "Milliseconds" + // Percent ... + Percent UnitType = "Percent" + // Seconds ... + Seconds UnitType = "Seconds" +) + +// PossibleUnitTypeValues returns an array of possible values for the UnitType const type. +func PossibleUnitTypeValues() []UnitType { + return []UnitType{Bytes, BytesPerSecond, Count, CountPerSecond, Milliseconds, Percent, Seconds} +} + +// Account cognitive Services Account is an Azure resource representing the provisioned account, its type, location +// and SKU. +type Account struct { + autorest.Response `json:"-"` + // Etag - Entity Tag + Etag *string `json:"etag,omitempty"` + // ID - The id of the created account + ID *string `json:"id,omitempty"` + // Kind - Type of cognitive service account. + Kind *string `json:"kind,omitempty"` + // Location - The location of the resource + Location *string `json:"location,omitempty"` + // Name - The name of the created account + Name *string `json:"name,omitempty"` + // AccountProperties - Properties of Cognitive Services account. + *AccountProperties `json:"properties,omitempty"` + // Sku - The SKU of Cognitive Services account. + Sku *Sku `json:"sku,omitempty"` + // Tags - Gets or sets a list of key value pairs that describe the resource. These tags can be used in viewing and grouping this resource (across resource groups). A maximum of 15 tags can be provided for a resource. Each tag must have a key no greater than 128 characters and value no greater than 256 characters. + Tags map[string]*string `json:"tags"` + // Type - Resource type + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for Account. +func (a Account) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if a.Etag != nil { + objectMap["etag"] = a.Etag + } + if a.ID != nil { + objectMap["id"] = a.ID + } + if a.Kind != nil { + objectMap["kind"] = a.Kind + } + if a.Location != nil { + objectMap["location"] = a.Location + } + if a.Name != nil { + objectMap["name"] = a.Name + } + if a.AccountProperties != nil { + objectMap["properties"] = a.AccountProperties + } + if a.Sku != nil { + objectMap["sku"] = a.Sku + } + if a.Tags != nil { + objectMap["tags"] = a.Tags + } + if a.Type != nil { + objectMap["type"] = a.Type + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for Account struct. +func (a *Account) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "etag": + if v != nil { + var etag string + err = json.Unmarshal(*v, &etag) + if err != nil { + return err + } + a.Etag = &etag + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + a.ID = &ID + } + case "kind": + if v != nil { + var kind string + err = json.Unmarshal(*v, &kind) + if err != nil { + return err + } + a.Kind = &kind + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + a.Location = &location + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + a.Name = &name + } + case "properties": + if v != nil { + var accountProperties AccountProperties + err = json.Unmarshal(*v, &accountProperties) + if err != nil { + return err + } + a.AccountProperties = &accountProperties + } + case "sku": + if v != nil { + var sku Sku + err = json.Unmarshal(*v, &sku) + if err != nil { + return err + } + a.Sku = &sku + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + a.Tags = tags + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + a.Type = &typeVar + } + } + } + + return nil +} + +// AccountCreateParameters the parameters to provide for the account. +type AccountCreateParameters struct { + // Sku - Required. Gets or sets the SKU of the resource. + Sku *Sku `json:"sku,omitempty"` + // Kind - Required. Gets or sets the Kind of the resource. Possible values include: 'BingAutosuggestv7', 'BingCustomSearch', 'BingSearchv7', 'BingSpeech', 'BingSpellCheckv7', 'ComputerVision', 'ContentModerator', 'CustomSpeech', 'CustomVisionPrediction', 'CustomVisionTraining', 'Emotion', 'Face', 'LUIS', 'QnAMaker', 'SpeakerRecognition', 'SpeechTranslation', 'TextAnalytics', 'TextTranslation', 'WebLM' + Kind Kind `json:"kind,omitempty"` + // Location - Required. Gets or sets the location of the resource. This will be one of the supported and registered Azure Geo Regions (e.g. West US, East US, Southeast Asia, etc.). The geo region of a resource cannot be changed once it is created, but if an identical geo region is specified on update the request will succeed. + Location *string `json:"location,omitempty"` + // Tags - Gets or sets a list of key value pairs that describe the resource. These tags can be used in viewing and grouping this resource (across resource groups). A maximum of 15 tags can be provided for a resource. Each tag must have a key no greater than 128 characters and value no greater than 256 characters. + Tags map[string]*string `json:"tags"` + // Properties - Must exist in the request. Must be an empty object. Must not be null. + Properties interface{} `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for AccountCreateParameters. +func (acp AccountCreateParameters) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if acp.Sku != nil { + objectMap["sku"] = acp.Sku + } + if acp.Kind != "" { + objectMap["kind"] = acp.Kind + } + if acp.Location != nil { + objectMap["location"] = acp.Location + } + if acp.Tags != nil { + objectMap["tags"] = acp.Tags + } + objectMap["properties"] = acp.Properties + return json.Marshal(objectMap) +} + +// AccountEnumerateSkusResult the list of cognitive services accounts operation response. +type AccountEnumerateSkusResult struct { + autorest.Response `json:"-"` + // Value - Gets the list of Cognitive Services accounts and their properties. + Value *[]ResourceAndSku `json:"value,omitempty"` +} + +// AccountKeys the access keys for the cognitive services account. +type AccountKeys struct { + autorest.Response `json:"-"` + // Key1 - Gets the value of key 1. + Key1 *string `json:"key1,omitempty"` + // Key2 - Gets the value of key 2. + Key2 *string `json:"key2,omitempty"` +} + +// AccountListResult the list of cognitive services accounts operation response. +type AccountListResult struct { + autorest.Response `json:"-"` + // NextLink - The link used to get the next page of accounts. + NextLink *string `json:"nextLink,omitempty"` + // Value - Gets the list of Cognitive Services accounts and their properties. + Value *[]Account `json:"value,omitempty"` +} + +// AccountListResultIterator provides access to a complete listing of Account values. +type AccountListResultIterator struct { + i int + page AccountListResultPage +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *AccountListResultIterator) Next() error { + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err := iter.page.Next() + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter AccountListResultIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter AccountListResultIterator) Response() AccountListResult { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter AccountListResultIterator) Value() Account { + if !iter.page.NotDone() { + return Account{} + } + return iter.page.Values()[iter.i] +} + +// IsEmpty returns true if the ListResult contains no values. +func (alr AccountListResult) IsEmpty() bool { + return alr.Value == nil || len(*alr.Value) == 0 +} + +// accountListResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (alr AccountListResult) accountListResultPreparer() (*http.Request, error) { + if alr.NextLink == nil || len(to.String(alr.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(alr.NextLink))) +} + +// AccountListResultPage contains a page of Account values. +type AccountListResultPage struct { + fn func(AccountListResult) (AccountListResult, error) + alr AccountListResult +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *AccountListResultPage) Next() error { + next, err := page.fn(page.alr) + if err != nil { + return err + } + page.alr = next + return nil +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page AccountListResultPage) NotDone() bool { + return !page.alr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page AccountListResultPage) Response() AccountListResult { + return page.alr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page AccountListResultPage) Values() []Account { + if page.alr.IsEmpty() { + return nil + } + return *page.alr.Value +} + +// AccountProperties properties of Cognitive Services account. +type AccountProperties struct { + // ProvisioningState - Gets the status of the cognitive services account at the time the operation was called. Possible values include: 'Creating', 'ResolvingDNS', 'Moving', 'Deleting', 'Succeeded', 'Failed' + ProvisioningState ProvisioningState `json:"provisioningState,omitempty"` + // Endpoint - Endpoint of the created account. + Endpoint *string `json:"endpoint,omitempty"` + // InternalID - The internal identifier. + InternalID *string `json:"internalId,omitempty"` +} + +// AccountUpdateParameters the parameters to provide for the account. +type AccountUpdateParameters struct { + // Sku - Gets or sets the SKU of the resource. + Sku *Sku `json:"sku,omitempty"` + // Tags - Gets or sets a list of key value pairs that describe the resource. These tags can be used in viewing and grouping this resource (across resource groups). A maximum of 15 tags can be provided for a resource. Each tag must have a key no greater than 128 characters and value no greater than 256 characters. + Tags map[string]*string `json:"tags"` +} + +// MarshalJSON is the custom marshaler for AccountUpdateParameters. +func (aup AccountUpdateParameters) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if aup.Sku != nil { + objectMap["sku"] = aup.Sku + } + if aup.Tags != nil { + objectMap["tags"] = aup.Tags + } + return json.Marshal(objectMap) +} + +// CheckSkuAvailabilityParameter check SKU availability parameter. +type CheckSkuAvailabilityParameter struct { + // Skus - The SKU of the resource. + Skus *[]SkuName `json:"skus,omitempty"` + // Kind - The Kind of the resource. Possible values include: 'BingAutosuggestv7', 'BingCustomSearch', 'BingSearchv7', 'BingSpeech', 'BingSpellCheckv7', 'ComputerVision', 'ContentModerator', 'CustomSpeech', 'CustomVisionPrediction', 'CustomVisionTraining', 'Emotion', 'Face', 'LUIS', 'QnAMaker', 'SpeakerRecognition', 'SpeechTranslation', 'TextAnalytics', 'TextTranslation', 'WebLM' + Kind Kind `json:"kind,omitempty"` + // Type - The Type of the resource. + Type *string `json:"type,omitempty"` +} + +// CheckSkuAvailabilityResult check SKU availability result. +type CheckSkuAvailabilityResult struct { + // Kind - The Kind of the resource. Possible values include: 'BingAutosuggestv7', 'BingCustomSearch', 'BingSearchv7', 'BingSpeech', 'BingSpellCheckv7', 'ComputerVision', 'ContentModerator', 'CustomSpeech', 'CustomVisionPrediction', 'CustomVisionTraining', 'Emotion', 'Face', 'LUIS', 'QnAMaker', 'SpeakerRecognition', 'SpeechTranslation', 'TextAnalytics', 'TextTranslation', 'WebLM' + Kind Kind `json:"kind,omitempty"` + // Type - The Type of the resource. + Type *string `json:"type,omitempty"` + // SkuName - The SKU of Cognitive Services account. Possible values include: 'F0', 'P0', 'P1', 'P2', 'S0', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6' + SkuName SkuName `json:"skuName,omitempty"` + // SkuAvailable - Indicates the given SKU is available or not. + SkuAvailable *bool `json:"skuAvailable,omitempty"` + // Reason - Reason why the SKU is not available. + Reason *string `json:"reason,omitempty"` + // Message - Additional error message. + Message *string `json:"message,omitempty"` +} + +// CheckSkuAvailabilityResultList check SKU availability result list. +type CheckSkuAvailabilityResultList struct { + autorest.Response `json:"-"` + // Value - Check SKU availability result list. + Value *[]CheckSkuAvailabilityResult `json:"value,omitempty"` +} + +// Error cognitive Services error object. +type Error struct { + // Error - The error body. + Error *ErrorBody `json:"error,omitempty"` +} + +// ErrorBody cognitive Services error body. +type ErrorBody struct { + // Code - error code + Code *string `json:"code,omitempty"` + // Message - error message + Message *string `json:"message,omitempty"` +} + +// MetricName a metric name. +type MetricName struct { + // Value - The name of the metric. + Value *string `json:"value,omitempty"` + // LocalizedValue - The friendly name of the metric. + LocalizedValue *string `json:"localizedValue,omitempty"` +} + +// OperationDisplayInfo the operation supported by Cognitive Services. +type OperationDisplayInfo struct { + // Description - The description of the operation. + Description *string `json:"description,omitempty"` + // Operation - The action that users can perform, based on their permission level. + Operation *string `json:"operation,omitempty"` + // Provider - Service provider: Microsoft Cognitive Services. + Provider *string `json:"provider,omitempty"` + // Resource - Resource on which the operation is performed. + Resource *string `json:"resource,omitempty"` +} + +// OperationEntity the operation supported by Cognitive Services. +type OperationEntity struct { + // Name - Operation name: {provider}/{resource}/{operation}. + Name *string `json:"name,omitempty"` + // Display - The operation supported by Cognitive Services. + Display *OperationDisplayInfo `json:"display,omitempty"` + // Origin - The origin of the operation. + Origin *string `json:"origin,omitempty"` + // Properties - Additional properties. + Properties interface{} `json:"properties,omitempty"` +} + +// OperationEntityListResult the list of cognitive services accounts operation response. +type OperationEntityListResult struct { + autorest.Response `json:"-"` + // NextLink - The link used to get the next page of operations. + NextLink *string `json:"nextLink,omitempty"` + // Value - The list of operations. + Value *[]OperationEntity `json:"value,omitempty"` +} + +// OperationEntityListResultIterator provides access to a complete listing of OperationEntity values. +type OperationEntityListResultIterator struct { + i int + page OperationEntityListResultPage +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *OperationEntityListResultIterator) Next() error { + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err := iter.page.Next() + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter OperationEntityListResultIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter OperationEntityListResultIterator) Response() OperationEntityListResult { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter OperationEntityListResultIterator) Value() OperationEntity { + if !iter.page.NotDone() { + return OperationEntity{} + } + return iter.page.Values()[iter.i] +} + +// IsEmpty returns true if the ListResult contains no values. +func (oelr OperationEntityListResult) IsEmpty() bool { + return oelr.Value == nil || len(*oelr.Value) == 0 +} + +// operationEntityListResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (oelr OperationEntityListResult) operationEntityListResultPreparer() (*http.Request, error) { + if oelr.NextLink == nil || len(to.String(oelr.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(oelr.NextLink))) +} + +// OperationEntityListResultPage contains a page of OperationEntity values. +type OperationEntityListResultPage struct { + fn func(OperationEntityListResult) (OperationEntityListResult, error) + oelr OperationEntityListResult +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *OperationEntityListResultPage) Next() error { + next, err := page.fn(page.oelr) + if err != nil { + return err + } + page.oelr = next + return nil +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page OperationEntityListResultPage) NotDone() bool { + return !page.oelr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page OperationEntityListResultPage) Response() OperationEntityListResult { + return page.oelr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page OperationEntityListResultPage) Values() []OperationEntity { + if page.oelr.IsEmpty() { + return nil + } + return *page.oelr.Value +} + +// RegenerateKeyParameters regenerate key parameters. +type RegenerateKeyParameters struct { + // KeyName - key name to generate (Key1|Key2). Possible values include: 'Key1', 'Key2' + KeyName KeyName `json:"keyName,omitempty"` +} + +// ResourceAndSku cognitive Services resource type and SKU. +type ResourceAndSku struct { + // ResourceType - Resource Namespace and Type + ResourceType *string `json:"resourceType,omitempty"` + // Sku - The SKU of Cognitive Services account. + Sku *Sku `json:"sku,omitempty"` +} + +// ResourceSku describes an available Cognitive Services SKU. +type ResourceSku struct { + // ResourceType - The type of resource the SKU applies to. + ResourceType *string `json:"resourceType,omitempty"` + // Name - The name of SKU. + Name *string `json:"name,omitempty"` + // Tier - Specifies the tier of Cognitive Services account. + Tier *string `json:"tier,omitempty"` + // Kind - The Kind of resources that are supported in this SKU. + Kind *string `json:"kind,omitempty"` + // Locations - The set of locations that the SKU is available. + Locations *[]string `json:"locations,omitempty"` + // Restrictions - The restrictions because of which SKU cannot be used. This is empty if there are no restrictions. + Restrictions *[]ResourceSkuRestrictions `json:"restrictions,omitempty"` +} + +// ResourceSkuRestrictionInfo ... +type ResourceSkuRestrictionInfo struct { + // Locations - Locations where the SKU is restricted + Locations *[]string `json:"locations,omitempty"` + // Zones - List of availability zones where the SKU is restricted. + Zones *[]string `json:"zones,omitempty"` +} + +// ResourceSkuRestrictions describes restrictions of a SKU. +type ResourceSkuRestrictions struct { + // Type - The type of restrictions. Possible values include: 'Location', 'Zone' + Type ResourceSkuRestrictionsType `json:"type,omitempty"` + // Values - The value of restrictions. If the restriction type is set to location. This would be different locations where the SKU is restricted. + Values *[]string `json:"values,omitempty"` + // RestrictionInfo - The information about the restriction where the SKU cannot be used. + RestrictionInfo *ResourceSkuRestrictionInfo `json:"restrictionInfo,omitempty"` + // ReasonCode - The reason for restriction. Possible values include: 'QuotaID', 'NotAvailableForSubscription' + ReasonCode ResourceSkuRestrictionsReasonCode `json:"reasonCode,omitempty"` +} + +// ResourceSkusResult the Get Skus operation response. +type ResourceSkusResult struct { + autorest.Response `json:"-"` + // Value - The list of skus available for the subscription. + Value *[]ResourceSku `json:"value,omitempty"` + // NextLink - The uri to fetch the next page of Skus. + NextLink *string `json:"nextLink,omitempty"` +} + +// ResourceSkusResultIterator provides access to a complete listing of ResourceSku values. +type ResourceSkusResultIterator struct { + i int + page ResourceSkusResultPage +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *ResourceSkusResultIterator) Next() error { + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err := iter.page.Next() + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter ResourceSkusResultIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter ResourceSkusResultIterator) Response() ResourceSkusResult { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter ResourceSkusResultIterator) Value() ResourceSku { + if !iter.page.NotDone() { + return ResourceSku{} + } + return iter.page.Values()[iter.i] +} + +// IsEmpty returns true if the ListResult contains no values. +func (rsr ResourceSkusResult) IsEmpty() bool { + return rsr.Value == nil || len(*rsr.Value) == 0 +} + +// resourceSkusResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (rsr ResourceSkusResult) resourceSkusResultPreparer() (*http.Request, error) { + if rsr.NextLink == nil || len(to.String(rsr.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(rsr.NextLink))) +} + +// ResourceSkusResultPage contains a page of ResourceSku values. +type ResourceSkusResultPage struct { + fn func(ResourceSkusResult) (ResourceSkusResult, error) + rsr ResourceSkusResult +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *ResourceSkusResultPage) Next() error { + next, err := page.fn(page.rsr) + if err != nil { + return err + } + page.rsr = next + return nil +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page ResourceSkusResultPage) NotDone() bool { + return !page.rsr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page ResourceSkusResultPage) Response() ResourceSkusResult { + return page.rsr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page ResourceSkusResultPage) Values() []ResourceSku { + if page.rsr.IsEmpty() { + return nil + } + return *page.rsr.Value +} + +// Sku the SKU of the cognitive services account. +type Sku struct { + // Name - Gets or sets the sku name. Required for account creation, optional for update. Possible values include: 'F0', 'P0', 'P1', 'P2', 'S0', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6' + Name SkuName `json:"name,omitempty"` + // Tier - Gets the sku tier. This is based on the SKU name. Possible values include: 'Free', 'Standard', 'Premium' + Tier SkuTier `json:"tier,omitempty"` +} + +// Usage the usage data for a usage request. +type Usage struct { + // Unit - The unit of the metric. Possible values include: 'Count', 'Bytes', 'Seconds', 'Percent', 'CountPerSecond', 'BytesPerSecond', 'Milliseconds' + Unit UnitType `json:"unit,omitempty"` + // Name - The name information for the metric. + Name *MetricName `json:"name,omitempty"` + // QuotaPeriod - The quota period used to summarize the usage values. + QuotaPeriod *string `json:"quotaPeriod,omitempty"` + // Limit - Maximum value for this metric. + Limit *float64 `json:"limit,omitempty"` + // CurrentValue - Current value for this metric. + CurrentValue *float64 `json:"currentValue,omitempty"` + // NextResetTime - Next reset time for current quota. + NextResetTime *string `json:"nextResetTime,omitempty"` + // Status - Cognitive Services account quota usage status. Possible values include: 'Included', 'Blocked', 'InOverage', 'Unknown' + Status QuotaUsageStatus `json:"status,omitempty"` +} + +// UsagesResult the response to a list usage request. +type UsagesResult struct { + autorest.Response `json:"-"` + // Value - The list of usages for Cognitive Service account. + Value *[]Usage `json:"value,omitempty"` +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/operations.go b/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/operations.go new file mode 100644 index 000000000000..997e891b497a --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/operations.go @@ -0,0 +1,126 @@ +package cognitiveservices + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "net/http" +) + +// OperationsClient is the cognitive Services Management Client +type OperationsClient struct { + BaseClient +} + +// NewOperationsClient creates an instance of the OperationsClient client. +func NewOperationsClient(subscriptionID string) OperationsClient { + return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewOperationsClientWithBaseURI creates an instance of the OperationsClient client. +func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string) OperationsClient { + return OperationsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List lists all the available Cognitive Services account operations. +func (client OperationsClient) List(ctx context.Context) (result OperationEntityListResultPage, err error) { + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.OperationsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.oelr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "cognitiveservices.OperationsClient", "List", resp, "Failure sending request") + return + } + + result.oelr, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.OperationsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) { + const APIVersion = "2017-04-18" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/Microsoft.CognitiveServices/operations"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client OperationsClient) ListResponder(resp *http.Response) (result OperationEntityListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client OperationsClient) listNextResults(lastResults OperationEntityListResult) (result OperationEntityListResult, err error) { + req, err := lastResults.operationEntityListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "cognitiveservices.OperationsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "cognitiveservices.OperationsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.OperationsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client OperationsClient) ListComplete(ctx context.Context) (result OperationEntityListResultIterator, err error) { + result.page, err = client.List(ctx) + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/resourceskus.go b/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/resourceskus.go new file mode 100644 index 000000000000..fe790c3e09cc --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/resourceskus.go @@ -0,0 +1,130 @@ +package cognitiveservices + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "net/http" +) + +// ResourceSkusClient is the cognitive Services Management Client +type ResourceSkusClient struct { + BaseClient +} + +// NewResourceSkusClient creates an instance of the ResourceSkusClient client. +func NewResourceSkusClient(subscriptionID string) ResourceSkusClient { + return NewResourceSkusClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewResourceSkusClientWithBaseURI creates an instance of the ResourceSkusClient client. +func NewResourceSkusClientWithBaseURI(baseURI string, subscriptionID string) ResourceSkusClient { + return ResourceSkusClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List gets the list of Microsoft.CognitiveServices SKUs available for your Subscription. +func (client ResourceSkusClient) List(ctx context.Context) (result ResourceSkusResultPage, err error) { + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.ResourceSkusClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.rsr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "cognitiveservices.ResourceSkusClient", "List", resp, "Failure sending request") + return + } + + result.rsr, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.ResourceSkusClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client ResourceSkusClient) ListPreparer(ctx context.Context) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-18" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.CognitiveServices/skus", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client ResourceSkusClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client ResourceSkusClient) ListResponder(resp *http.Response) (result ResourceSkusResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client ResourceSkusClient) listNextResults(lastResults ResourceSkusResult) (result ResourceSkusResult, err error) { + req, err := lastResults.resourceSkusResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "cognitiveservices.ResourceSkusClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "cognitiveservices.ResourceSkusClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "cognitiveservices.ResourceSkusClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client ResourceSkusClient) ListComplete(ctx context.Context) (result ResourceSkusResultIterator, err error) { + result.page, err = client.List(ctx) + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/version.go b/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/version.go new file mode 100644 index 000000000000..32d0c8d199fb --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices/version.go @@ -0,0 +1,30 @@ +package cognitiveservices + +import "github.com/Azure/azure-sdk-for-go/version" + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// UserAgent returns the UserAgent string to use when sending http.Requests. +func UserAgent() string { + return "Azure-SDK-For-Go/" + version.Number + " cognitiveservices/2017-04-18" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return version.Number +} diff --git a/vendor/vendor.json b/vendor/vendor.json index 37103cecad19..576ef9c7c2c3 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -26,6 +26,14 @@ "version": "v21.1.0", "versionExact": "v21.1.0" }, + { + "checksumSHA1": "aWRle6uvrmNNv+Awt3+Ymr0DDhQ=", + "path": "github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices", + "revision": "2935c0241c74bd8549b843978dd6fc1be6f48b4a", + "revisionTime": "2018-08-31T14:25:13Z", + "version": "v20.1.0", + "versionExact": "v20.1.0" + }, { "checksumSHA1": "iS3V1RJwe8QKQ8k+IdX6MRxFjjs=", "path": "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-06-01/compute", diff --git a/website/azurerm.erb b/website/azurerm.erb index b1d7c5f6aa7e..d9f4c5751679 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -414,6 +414,17 @@ + > + Cognitive Services Resources + + + > CosmosDB (DocumentDB) Resources