diff --git a/azurerm/config.go b/azurerm/config.go index 941a5b15a0ba..31fb8867593e 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -29,6 +29,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/monitor/mgmt/2018-03-01/insights" "github.com/Azure/azure-sdk-for-go/services/mysql/mgmt/2017-12-01/mysql" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-04-01/network" + "github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs" "github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql" "github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-01-01-preview/authorization" "github.com/Azure/azure-sdk-for-go/services/preview/dns/mgmt/2018-03-01-preview/dns" @@ -182,6 +183,10 @@ type ArmClient struct { vnetPeeringsClient network.VirtualNetworkPeeringsClient watcherClient network.WatchersClient + // Notification Hubs + notificationHubsClient notificationhubs.Client + notificationNamespacesClient notificationhubs.NamespacesClient + // Recovery Services recoveryServicesVaultsClient recoveryservices.VaultsClient @@ -404,8 +409,10 @@ func getArmClient(c *authentication.Config) (*ArmClient, error) { client.registerLogicClients(endpoint, c.SubscriptionID, auth, sender) client.registerMonitorClients(endpoint, c.SubscriptionID, auth, sender) client.registerNetworkingClients(endpoint, c.SubscriptionID, auth, sender) + client.registerNotificationHubsClient(endpoint, c.SubscriptionID, auth, sender) client.registerOperationalInsightsClients(endpoint, c.SubscriptionID, auth, sender) client.registerRecoveryServiceClients(endpoint, c.SubscriptionID, auth) + client.registerPolicyClients(endpoint, c.SubscriptionID, auth) client.registerRedisClients(endpoint, c.SubscriptionID, auth, sender) client.registerRelayClients(endpoint, c.SubscriptionID, auth, sender) client.registerResourcesClients(endpoint, c.SubscriptionID, auth) @@ -415,7 +422,6 @@ func getArmClient(c *authentication.Config) (*ArmClient, error) { client.registerStorageClients(endpoint, c.SubscriptionID, auth) client.registerTrafficManagerClients(endpoint, c.SubscriptionID, auth) client.registerWebClients(endpoint, c.SubscriptionID, auth) - client.registerPolicyClients(endpoint, c.SubscriptionID, auth) return &client, nil } @@ -837,6 +843,16 @@ func (c *ArmClient) registerNetworkingClients(endpoint, subscriptionId string, a c.watcherClient = watchersClient } +func (c *ArmClient) registerNotificationHubsClient(endpoint, subscriptionId string, auth *autorest.BearerAuthorizer, sender autorest.Sender) { + namespacesClient := notificationhubs.NewNamespacesClientWithBaseURI(endpoint, subscriptionId) + c.configureClient(&namespacesClient.Client, auth) + c.notificationNamespacesClient = namespacesClient + + notificationHubsClient := notificationhubs.NewClientWithBaseURI(endpoint, subscriptionId) + c.configureClient(¬ificationHubsClient.Client, auth) + c.notificationHubsClient = notificationHubsClient +} + func (c *ArmClient) registerOperationalInsightsClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) { opwc := operationalinsights.NewWorkspacesClientWithBaseURI(endpoint, subscriptionId) c.configureClient(&opwc.Client, auth) diff --git a/azurerm/data_source_notification_hub.go b/azurerm/data_source_notification_hub.go new file mode 100644 index 000000000000..124b4ba55358 --- /dev/null +++ b/azurerm/data_source_notification_hub.go @@ -0,0 +1,176 @@ +package azurerm + +import ( + "fmt" + + "github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs" + "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func dataSourceNotificationHub() *schema.Resource { + return &schema.Resource{ + Read: dataSourceNotificationHubRead, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + + "namespace_name": { + Type: schema.TypeString, + Required: true, + }, + + "resource_group_name": resourceGroupNameForDataSourceSchema(), + + "location": locationForDataSourceSchema(), + + "apns_credential": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "application_mode": { + Type: schema.TypeString, + Computed: true, + }, + "bundle_id": { + Type: schema.TypeString, + Computed: true, + }, + "key_id": { + Type: schema.TypeString, + Computed: true, + }, + // Team ID (within Apple & the Portal) == "AppID" (within the API) + "team_id": { + Type: schema.TypeString, + Computed: true, + }, + "token": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + }, + }, + }, + + "gcm_credential": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "api_key": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + }, + }, + }, + + // NOTE: skipping tags as there's a bug in the API where the Keys for Tags are returned in lower-case + // Azure Rest API Specs issue: https://github.com/Azure/azure-sdk-for-go/issues/2239 + //"tags": tagsForDataSourceSchema(), + }, + } +} + +func dataSourceNotificationHubRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).notificationHubsClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + namespaceName := d.Get("namespace_name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + resp, err := client.Get(ctx, resourceGroup, namespaceName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Notification Hub %q was not found in Namespace %q / Resource Group %q", name, namespaceName, resourceGroup) + } + + return fmt.Errorf("Error making Read request on Notification Hub %q (Namespace %q / Resource Group %q): %+v", name, namespaceName, resourceGroup, err) + } + + credentials, err := client.GetPnsCredentials(ctx, resourceGroup, namespaceName, name) + if err != nil { + return fmt.Errorf("Error retrieving Credentials for Notification Hub %q (Namespace %q / Resource Group %q): %+v", name, namespaceName, resourceGroup, err) + } + + d.SetId(*resp.ID) + + d.Set("name", resp.Name) + d.Set("namespace_name", namespaceName) + d.Set("resource_group_name", resourceGroup) + if location := resp.Location; location != nil { + d.Set("location", azureRMNormalizeLocation(*location)) + } + + if props := credentials.PnsCredentialsProperties; props != nil { + apns := flattenNotificationHubsDataSourceAPNSCredentials(props.ApnsCredential) + if d.Set("apns_credential", apns); err != nil { + return fmt.Errorf("Error setting `apns_credential`: %+v", err) + } + + gcm := flattenNotificationHubsDataSourceGCMCredentials(props.GcmCredential) + if d.Set("gcm_credential", gcm); err != nil { + return fmt.Errorf("Error setting `gcm_credential`: %+v", err) + } + } + + return nil +} + +func flattenNotificationHubsDataSourceAPNSCredentials(input *notificationhubs.ApnsCredential) []interface{} { + if input == nil { + return make([]interface{}, 0) + } + + output := make(map[string]interface{}, 0) + + if bundleId := input.AppName; bundleId != nil { + output["bundle_id"] = *bundleId + } + + if endpoint := input.Endpoint; endpoint != nil { + applicationEndpoints := map[string]string{ + "https://api.push.apple.com:443/3/device": "Production", + "https://api.development.push.apple.com:443/3/device": "Sandbox", + } + applicationMode := applicationEndpoints[*endpoint] + output["application_mode"] = applicationMode + } + + if keyId := input.KeyID; keyId != nil { + output["key_id"] = *keyId + } + + if teamId := input.AppID; teamId != nil { + output["team_id"] = *teamId + } + + if token := input.Token; token != nil { + output["token"] = *token + } + + return []interface{}{output} +} + +func flattenNotificationHubsDataSourceGCMCredentials(input *notificationhubs.GcmCredential) []interface{} { + if input == nil { + return []interface{}{} + } + + output := make(map[string]interface{}, 0) + if props := input.GcmCredentialProperties; props != nil { + if apiKey := props.GoogleAPIKey; apiKey != nil { + output["api_key"] = *apiKey + } + } + + return []interface{}{output} +} diff --git a/azurerm/data_source_notification_hub_namespace.go b/azurerm/data_source_notification_hub_namespace.go new file mode 100644 index 000000000000..9c4bf559ad6d --- /dev/null +++ b/azurerm/data_source_notification_hub_namespace.go @@ -0,0 +1,109 @@ +package azurerm + +import ( + "fmt" + + "github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs" + "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func dataSourceNotificationHubNamespace() *schema.Resource { + return &schema.Resource{ + Read: resourceArmDataSourceNotificationHubNamespaceRead, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + + "resource_group_name": resourceGroupNameForDataSourceSchema(), + + "location": locationForDataSourceSchema(), + + "sku": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + + "enabled": { + Type: schema.TypeBool, + Computed: true, + }, + + "namespace_type": { + Type: schema.TypeString, + Computed: true, + }, + + // NOTE: skipping tags as there's a bug in the API where the Keys for Tags are returned in lower-case + // Azure Rest API Specs issue: https://github.com/Azure/azure-sdk-for-go/issues/2239 + //"tags": tagsForDataSourceSchema(), + + "servicebus_endpoint": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func resourceArmDataSourceNotificationHubNamespaceRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).notificationNamespacesClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Notification Hub Namespace %q (Resource Group %q) was not found", name, resourceGroup) + } + + return fmt.Errorf("Error making Read request on Notification Hub Namespace %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + d.SetId(*resp.ID) + + d.Set("name", resp.Name) + d.Set("resource_group_name", resourceGroup) + if location := resp.Location; location != nil { + d.Set("location", azureRMNormalizeLocation(*location)) + } + + sku := flattenNotificationHubDataSourceNamespacesSku(resp.Sku) + if err := d.Set("sku", sku); err != nil { + return fmt.Errorf("Error setting `sku`: %+v", err) + } + + if props := resp.NamespaceProperties; props != nil { + d.Set("enabled", props.Enabled) + d.Set("namespace_type", props.NamespaceType) + d.Set("servicebus_endpoint", props.ServiceBusEndpoint) + } + + return nil +} + +func flattenNotificationHubDataSourceNamespacesSku(input *notificationhubs.Sku) []interface{} { + outputs := make([]interface{}, 0) + if input == nil { + return outputs + } + + output := map[string]interface{}{ + "name": string(input.Name), + } + outputs = append(outputs, output) + return outputs +} diff --git a/azurerm/data_source_notification_hub_namespace_test.go b/azurerm/data_source_notification_hub_namespace_test.go new file mode 100644 index 000000000000..a145d68de305 --- /dev/null +++ b/azurerm/data_source_notification_hub_namespace_test.go @@ -0,0 +1,43 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccDataSourceAzureRMNotificationHubNamespace_free(t *testing.T) { + dataSourceName := "data.azurerm_notification_hub_namespace.test" + rInt := acctest.RandInt() + location := testLocation() + config := testAccDataSourceAzureRMNotificationHubNamespaceFree(rInt, location) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMNotificationHubNamespaceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "namespace_type", "NotificationHub"), + resource.TestCheckResourceAttr(dataSourceName, "sku.0.name", "Free"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMNotificationHubNamespaceFree(rInt int, location string) string { + resource := testAzureRMNotificationHubNamespace_free(rInt, location) + return fmt.Sprintf(` +%s + +data "azurerm_notification_hub_namespace" "test" { + name = "${azurerm_notification_hub_namespace.test.name}" + resource_group_name = "${azurerm_notification_hub_namespace.test.resource_group_name}" +} +`, resource) +} diff --git a/azurerm/data_source_notification_hub_test.go b/azurerm/data_source_notification_hub_test.go new file mode 100644 index 000000000000..999c12404c70 --- /dev/null +++ b/azurerm/data_source_notification_hub_test.go @@ -0,0 +1,44 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccDataSourceAzureRMNotificationHub_basic(t *testing.T) { + dataSourceName := "data.azurerm_notification_hub.test" + rInt := acctest.RandInt() + location := testLocation() + config := testAccDataSourceAzureRMNotificationHubBasic(rInt, location) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMNotificationHubDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "apns_credential.#", "0"), + resource.TestCheckResourceAttr(dataSourceName, "gcm_credential.#", "0"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMNotificationHubBasic(rInt int, location string) string { + resource := testAzureRMNotificationHub_basic(rInt, location) + return fmt.Sprintf(` +%s + +data "azurerm_notification_hub" "test" { + name = "${azurerm_notification_hub.test.name}" + namespace_name = "${azurerm_notification_hub_namespace.test.name}" + resource_group_name = "${azurerm_notification_hub_namespace.test.resource_group_name}" +} +`, resource) +} diff --git a/azurerm/import_arm_notification_hub_authorization_rule_test.go b/azurerm/import_arm_notification_hub_authorization_rule_test.go new file mode 100644 index 000000000000..7485c89ae89b --- /dev/null +++ b/azurerm/import_arm_notification_hub_authorization_rule_test.go @@ -0,0 +1,80 @@ +package azurerm + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAzureRMNotificationHubAuthorizationRule_importListen(t *testing.T) { + resourceName := "azurerm_notification_hub_authorization_rule.test" + + ri := acctest.RandInt() + location := testLocation() + config := testAzureRMNotificationHubAuthorizationRule_listen(ri, location) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMNotificationHubAuthorizationRuleDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMNotificationHubAuthorizationRule_importManage(t *testing.T) { + resourceName := "azurerm_notification_hub_authorization_rule.test" + + ri := acctest.RandInt() + location := testLocation() + config := testAzureRMNotificationHubAuthorizationRule_manage(ri, location) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMNotificationHubAuthorizationRuleDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMNotificationHubAuthorizationRule_importSend(t *testing.T) { + resourceName := "azurerm_notification_hub_authorization_rule.test" + + ri := acctest.RandInt() + location := testLocation() + config := testAzureRMNotificationHubAuthorizationRule_send(ri, location) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMNotificationHubAuthorizationRuleDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/azurerm/import_arm_notification_hub_namespace_test.go b/azurerm/import_arm_notification_hub_namespace_test.go new file mode 100644 index 000000000000..b8c05ce6511f --- /dev/null +++ b/azurerm/import_arm_notification_hub_namespace_test.go @@ -0,0 +1,32 @@ +package azurerm + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAzureRMNotificationHubNamespace_importFree(t *testing.T) { + resourceName := "azurerm_notification_hub_namespace.test" + + ri := acctest.RandInt() + location := testLocation() + config := testAzureRMNotificationHubNamespace_free(ri, location) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMNotificationHubNamespaceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/azurerm/import_arm_notification_hub_test.go b/azurerm/import_arm_notification_hub_test.go new file mode 100644 index 000000000000..9cbb4abe45a5 --- /dev/null +++ b/azurerm/import_arm_notification_hub_test.go @@ -0,0 +1,32 @@ +package azurerm + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAzureRMNotificationHub_importBasic(t *testing.T) { + resourceName := "azurerm_notification_hub.test" + + ri := acctest.RandInt() + location := testLocation() + config := testAzureRMNotificationHub_basic(ri, location) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMNotificationHubDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/azurerm/provider.go b/azurerm/provider.go index 071bc38b3335..cc9f0d98927d 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -98,6 +98,8 @@ func Provider() terraform.ResourceProvider { "azurerm_managed_disk": dataSourceArmManagedDisk(), "azurerm_network_interface": dataSourceArmNetworkInterface(), "azurerm_network_security_group": dataSourceArmNetworkSecurityGroup(), + "azurerm_notification_hub": dataSourceNotificationHub(), + "azurerm_notification_hub_namespace": dataSourceNotificationHubNamespace(), "azurerm_platform_image": dataSourceArmPlatformImage(), "azurerm_public_ip": dataSourceArmPublicIP(), "azurerm_public_ips": dataSourceArmPublicIPs(), @@ -194,6 +196,9 @@ func Provider() terraform.ResourceProvider { "azurerm_network_security_group": resourceArmNetworkSecurityGroup(), "azurerm_network_security_rule": resourceArmNetworkSecurityRule(), "azurerm_network_watcher": resourceArmNetworkWatcher(), + "azurerm_notification_hub": resourceArmNotificationHub(), + "azurerm_notification_hub_authorization_rule": resourceArmNotificationHubAuthorizationRule(), + "azurerm_notification_hub_namespace": resourceArmNotificationHubNamespace(), "azurerm_packet_capture": resourceArmPacketCapture(), "azurerm_policy_assignment": resourceArmPolicyAssignment(), "azurerm_policy_definition": resourceArmPolicyDefinition(), @@ -366,6 +371,7 @@ func determineAzureResourceProvidersToRegister(providerList []resources.Provider "microsoft.insights": {}, "Microsoft.Logic": {}, "Microsoft.ManagedIdentity": {}, + "Microsoft.NotificationHubs": {}, "Microsoft.Network": {}, "Microsoft.OperationalInsights": {}, "Microsoft.Relay": {}, diff --git a/azurerm/resource_arm_notification_hub.go b/azurerm/resource_arm_notification_hub.go new file mode 100644 index 000000000000..e0bb33203e95 --- /dev/null +++ b/azurerm/resource_arm_notification_hub.go @@ -0,0 +1,338 @@ +package azurerm + +import ( + "fmt" + "log" + + "github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs" + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +const apnsProductionName = "Production" +const apnsProductionEndpoint = "https://api.push.apple.com:443/3/device" +const apnsSandboxName = "Sandbox" +const apnsSandboxEndpoint = "https://api.development.push.apple.com:443/3/device" + +func resourceArmNotificationHub() *schema.Resource { + return &schema.Resource{ + Create: resourceArmNotificationHubCreateUpdate, + Read: resourceArmNotificationHubRead, + Update: resourceArmNotificationHubCreateUpdate, + Delete: resourceArmNotificationHubDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + CustomizeDiff: func(diff *schema.ResourceDiff, v interface{}) error { + // NOTE: the ForceNew is to workaround a bug in the Azure SDK where nil-values aren't sent to the API. + // Bug: https://github.com/Azure/azure-sdk-for-go/issues/2246 + + oAPNS, nAPNS := diff.GetChange("apns_credential.#") + oAPNSi := oAPNS.(int) + nAPNSi := nAPNS.(int) + if nAPNSi < oAPNSi { + diff.ForceNew("apns_credential") + } + + oGCM, nGCM := diff.GetChange("gcm_credential.#") + oGCMi := oGCM.(int) + nGCMi := nGCM.(int) + if nGCMi < oGCMi { + diff.ForceNew("gcm_credential") + } + + return nil + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "namespace_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "resource_group_name": resourceGroupNameSchema(), + + "location": locationSchema(), + + "apns_credential": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + // NOTE: APNS supports two modes, certificate auth (v1) and token auth (v2) + // certificate authentication/v1 is marked for deprecation; as such we're not + // supporting it at this time. + "application_mode": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + apnsProductionName, + apnsSandboxName, + }, false), + }, + "bundle_id": { + Type: schema.TypeString, + Required: true, + }, + "key_id": { + Type: schema.TypeString, + Required: true, + }, + // Team ID (within Apple & the Portal) == "AppID" (within the API) + "team_id": { + Type: schema.TypeString, + Required: true, + }, + "token": { + Type: schema.TypeString, + Required: true, + Sensitive: true, + }, + }, + }, + }, + + "gcm_credential": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "api_key": { + Type: schema.TypeString, + Required: true, + Sensitive: true, + }, + }, + }, + }, + + // NOTE: skipping tags as there's a bug in the API where the Keys for Tags are returned in lower-case + // Azure Rest API Specs issue: https://github.com/Azure/azure-sdk-for-go/issues/2239 + //"tags": tagsSchema(), + }, + } +} + +func resourceArmNotificationHubCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).notificationHubsClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + namespaceName := d.Get("namespace_name").(string) + resourceGroup := d.Get("resource_group_name").(string) + location := azureRMNormalizeLocation(d.Get("location").(string)) + + apnsRaw := d.Get("apns_credential").([]interface{}) + apnsCredential, err := expandNotificationHubsAPNSCredentials(apnsRaw) + if err != nil { + return err + } + + gcmRaw := d.Get("gcm_credential").([]interface{}) + gcmCredentials, err := expandNotificationHubsGCMCredentials(gcmRaw) + if err != nil { + return err + } + + parameters := notificationhubs.CreateOrUpdateParameters{ + Location: utils.String(location), + Properties: ¬ificationhubs.Properties{ + ApnsCredential: apnsCredential, + GcmCredential: gcmCredentials, + }, + } + + _, err = client.CreateOrUpdate(ctx, resourceGroup, namespaceName, name, parameters) + if err != nil { + return fmt.Errorf("Error creating Notification Hub %q (Namespace %q / Resource Group %q): %+v", name, namespaceName, resourceGroup, err) + } + + read, err := client.Get(ctx, resourceGroup, namespaceName, name) + if err != nil { + return fmt.Errorf("Error retrieving Notification Hub %q (Namespace %q / Resource Group %q): %+v", name, namespaceName, resourceGroup, err) + } + if read.ID == nil { + return fmt.Errorf("Cannot read Notification Hub %q (Namespace %q / Resource Group %q) ID", name, namespaceName, resourceGroup) + } + + d.SetId(*read.ID) + + return resourceArmNotificationHubRead(d, meta) +} + +func resourceArmNotificationHubRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).notificationHubsClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + namespaceName := id.Path["namespaces"] + name := id.Path["notificationHubs"] + + resp, err := client.Get(ctx, resourceGroup, namespaceName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[DEBUG] Notification Hub %q was not found in Namespace %q / Resource Group %q", name, namespaceName, resourceGroup) + d.SetId("") + return nil + } + + return fmt.Errorf("Error making Read request on Notification Hub %q (Namespace %q / Resource Group %q): %+v", name, namespaceName, resourceGroup, err) + } + + credentials, err := client.GetPnsCredentials(ctx, resourceGroup, namespaceName, name) + if err != nil { + return fmt.Errorf("Error retrieving Credentials for Notification Hub %q (Namespace %q / Resource Group %q): %+v", name, namespaceName, resourceGroup, err) + } + + d.Set("name", resp.Name) + d.Set("namespace_name", namespaceName) + d.Set("resource_group_name", resourceGroup) + if location := resp.Location; location != nil { + d.Set("location", azureRMNormalizeLocation(*location)) + } + + if props := credentials.PnsCredentialsProperties; props != nil { + apns := flattenNotificationHubsAPNSCredentials(props.ApnsCredential) + if d.Set("apns_credential", apns); err != nil { + return fmt.Errorf("Error setting `apns_credential`: %+v", err) + } + + gcm := flattenNotificationHubsGCMCredentials(props.GcmCredential) + if d.Set("gcm_credential", gcm); err != nil { + return fmt.Errorf("Error setting `gcm_credential`: %+v", err) + } + } + + return nil +} + +func resourceArmNotificationHubDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).notificationHubsClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + namespaceName := id.Path["namespaces"] + name := id.Path["notificationHubs"] + + resp, err := client.Delete(ctx, resourceGroup, namespaceName, name) + if err != nil { + if !utils.ResponseWasNotFound(resp) { + return fmt.Errorf("Error deleting Notification Hub %q (Namespace %q / Resource Group %q): %+v", name, namespaceName, resourceGroup, err) + } + } + + return nil +} + +func expandNotificationHubsAPNSCredentials(inputs []interface{}) (*notificationhubs.ApnsCredential, error) { + if len(inputs) == 0 { + return nil, nil + } + + input := inputs[0].(map[string]interface{}) + applicationMode := input["application_mode"].(string) + bundleId := input["bundle_id"].(string) + keyId := input["key_id"].(string) + teamId := input["team_id"].(string) + token := input["token"].(string) + + applicationEndpoints := map[string]string{ + apnsProductionName: apnsProductionEndpoint, + apnsSandboxName: apnsSandboxEndpoint, + } + endpoint := applicationEndpoints[applicationMode] + + credentials := notificationhubs.ApnsCredential{ + ApnsCredentialProperties: ¬ificationhubs.ApnsCredentialProperties{ + AppID: utils.String(teamId), + AppName: utils.String(bundleId), + Endpoint: utils.String(endpoint), + KeyID: utils.String(keyId), + Token: utils.String(token), + }, + } + return &credentials, nil +} + +func flattenNotificationHubsAPNSCredentials(input *notificationhubs.ApnsCredential) []interface{} { + if input == nil { + return make([]interface{}, 0) + } + + output := make(map[string]interface{}, 0) + + if bundleId := input.AppName; bundleId != nil { + output["bundle_id"] = *bundleId + } + + if endpoint := input.Endpoint; endpoint != nil { + applicationEndpoints := map[string]string{ + apnsProductionEndpoint: apnsProductionName, + apnsSandboxEndpoint: apnsSandboxName, + } + applicationMode := applicationEndpoints[*endpoint] + output["application_mode"] = applicationMode + } + + if keyId := input.KeyID; keyId != nil { + output["key_id"] = *keyId + } + + if teamId := input.AppID; teamId != nil { + output["team_id"] = *teamId + } + + if token := input.Token; token != nil { + output["token"] = *token + } + + return []interface{}{output} +} + +func expandNotificationHubsGCMCredentials(inputs []interface{}) (*notificationhubs.GcmCredential, error) { + if len(inputs) == 0 { + return nil, nil + } + + input := inputs[0].(map[string]interface{}) + apiKey := input["api_key"].(string) + credentials := notificationhubs.GcmCredential{ + GcmCredentialProperties: ¬ificationhubs.GcmCredentialProperties{ + GoogleAPIKey: utils.String(apiKey), + }, + } + return &credentials, nil +} + +func flattenNotificationHubsGCMCredentials(input *notificationhubs.GcmCredential) []interface{} { + if input == nil { + return []interface{}{} + } + + output := make(map[string]interface{}, 0) + if props := input.GcmCredentialProperties; props != nil { + if apiKey := props.GoogleAPIKey; apiKey != nil { + output["api_key"] = *apiKey + } + } + + return []interface{}{output} +} diff --git a/azurerm/resource_arm_notification_hub_authorization_rule.go b/azurerm/resource_arm_notification_hub_authorization_rule.go new file mode 100644 index 000000000000..6ae0bcfee923 --- /dev/null +++ b/azurerm/resource_arm_notification_hub_authorization_rule.go @@ -0,0 +1,220 @@ +package azurerm + +import ( + "fmt" + "log" + + "github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs" + "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmNotificationHubAuthorizationRule() *schema.Resource { + return &schema.Resource{ + Create: resourceArmNotificationHubAuthorizationRuleCreateUpdate, + Read: resourceArmNotificationHubAuthorizationRuleRead, + Update: resourceArmNotificationHubAuthorizationRuleCreateUpdate, + Delete: resourceArmNotificationHubAuthorizationRuleDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + // TODO: customizeDiff for send+listen when manage selected + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "notification_hub_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "namespace_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "resource_group_name": resourceGroupNameSchema(), + + "manage": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + + "send": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + + "listen": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + + "primary_access_key": { + Type: schema.TypeString, + Computed: true, + }, + + "secondary_access_key": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func resourceArmNotificationHubAuthorizationRuleCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).notificationHubsClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + notificationHubName := d.Get("notification_hub_name").(string) + namespaceName := d.Get("namespace_name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + manage := d.Get("manage").(bool) + send := d.Get("send").(bool) + listen := d.Get("listen").(bool) + rights := expandNotificationHubAuthorizationRuleRights(manage, send, listen) + parameters := notificationhubs.SharedAccessAuthorizationRuleCreateOrUpdateParameters{ + Properties: ¬ificationhubs.SharedAccessAuthorizationRuleProperties{ + Rights: rights, + }, + } + + _, err := client.CreateOrUpdateAuthorizationRule(ctx, resourceGroup, namespaceName, notificationHubName, name, parameters) + if err != nil { + return fmt.Errorf("Error creating Authorization Rule %q (Notification Hub %q / Namespace %q / Resource Group %q): %+v", name, notificationHubName, namespaceName, resourceGroup, err) + } + + read, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, notificationHubName, name) + if err != nil { + return fmt.Errorf("Error retrieving Authorization Rule %q (Notification Hub %q / Namespace %q / Resource Group %q): %+v", name, notificationHubName, namespaceName, resourceGroup, err) + } + if read.ID == nil { + return fmt.Errorf("Cannot read Authorization Rule %q (Notification Hub %q / Namespace %q / Resource Group %q) ID", name, notificationHubName, namespaceName, resourceGroup) + } + + d.SetId(*read.ID) + + return resourceArmNotificationHubAuthorizationRuleRead(d, meta) +} + +func resourceArmNotificationHubAuthorizationRuleRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).notificationHubsClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + namespaceName := id.Path["namespaces"] + notificationHubName := id.Path["notificationHubs"] + name := id.Path["AuthorizationRules"] + + resp, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, notificationHubName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[DEBUG] Authorization Rule %q was not found in Notification Hub %q / Namespace %q / Resource Group %q", name, notificationHubName, namespaceName, resourceGroup) + d.SetId("") + return nil + } + + return fmt.Errorf("Error making Read request on Authorization Rule %q (Notification Hub %q / Namespace %q / Resource Group %q): %+v", name, notificationHubName, namespaceName, resourceGroup, err) + } + + keysResp, err := client.ListKeys(ctx, resourceGroup, namespaceName, notificationHubName, name) + if err != nil { + return fmt.Errorf("Error Listing Access Keys for Authorization Rule %q (Notification Hub %q / Namespace %q / Resource Group %q): %+v", name, notificationHubName, namespaceName, resourceGroup, err) + } + + d.Set("name", resp.Name) + d.Set("notification_hub_name", notificationHubName) + d.Set("namespace_name", namespaceName) + d.Set("resource_group_name", resourceGroup) + + if props := resp.SharedAccessAuthorizationRuleProperties; props != nil { + manage, send, listen := flattenNotificationHubAuthorizationRuleRights(props.Rights) + d.Set("manage", manage) + d.Set("send", send) + d.Set("listen", listen) + } + + d.Set("primary_access_key", keysResp.PrimaryKey) + d.Set("secondary_access_key", keysResp.SecondaryKey) + + return nil +} + +func resourceArmNotificationHubAuthorizationRuleDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).notificationHubsClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + namespaceName := id.Path["namespaces"] + notificationHubName := id.Path["notificationHubs"] + name := id.Path["AuthorizationRules"] + + resp, err := client.DeleteAuthorizationRule(ctx, resourceGroup, namespaceName, notificationHubName, name) + if err != nil { + if !utils.ResponseWasNotFound(resp) { + return fmt.Errorf("Error deleting Authorization Rule %q (Notification Hub %q / Namespace %q / Resource Group %q): %+v", name, notificationHubName, namespaceName, resourceGroup, err) + } + } + + return nil +} + +func expandNotificationHubAuthorizationRuleRights(manage bool, send bool, listen bool) *[]notificationhubs.AccessRights { + rights := make([]notificationhubs.AccessRights, 0) + + if manage { + rights = append(rights, notificationhubs.Manage) + } + + if send { + rights = append(rights, notificationhubs.Send) + } + + if listen { + rights = append(rights, notificationhubs.Listen) + } + + return &rights +} + +func flattenNotificationHubAuthorizationRuleRights(input *[]notificationhubs.AccessRights) (manage bool, send bool, listen bool) { + if input == nil { + return + } + + for _, right := range *input { + switch right { + case notificationhubs.Manage: + manage = true + continue + case notificationhubs.Send: + send = true + continue + case notificationhubs.Listen: + listen = true + continue + } + } + + return +} diff --git a/azurerm/resource_arm_notification_hub_authorization_rule_test.go b/azurerm/resource_arm_notification_hub_authorization_rule_test.go new file mode 100644 index 000000000000..7d2cf480ee70 --- /dev/null +++ b/azurerm/resource_arm_notification_hub_authorization_rule_test.go @@ -0,0 +1,256 @@ +package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccAzureRMNotificationHubAuthorizationRule_listen(t *testing.T) { + resourceName := "azurerm_notification_hub_authorization_rule.test" + + ri := acctest.RandInt() + location := testLocation() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMNotificationHubAuthorizationRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAzureRMNotificationHubAuthorizationRule_listen(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNotificationHubAuthorizationRuleExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "manage", "false"), + resource.TestCheckResourceAttr(resourceName, "send", "false"), + resource.TestCheckResourceAttr(resourceName, "listen", "true"), + resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + ), + }, + }, + }) +} + +func TestAccAzureRMNotificationHubAuthorizationRule_manage(t *testing.T) { + resourceName := "azurerm_notification_hub_authorization_rule.test" + + ri := acctest.RandInt() + location := testLocation() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMNotificationHubAuthorizationRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAzureRMNotificationHubAuthorizationRule_manage(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNotificationHubAuthorizationRuleExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "manage", "true"), + resource.TestCheckResourceAttr(resourceName, "send", "true"), + resource.TestCheckResourceAttr(resourceName, "listen", "true"), + resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + ), + }, + }, + }) +} + +func TestAccAzureRMNotificationHubAuthorizationRule_send(t *testing.T) { + resourceName := "azurerm_notification_hub_authorization_rule.test" + + ri := acctest.RandInt() + location := testLocation() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMNotificationHubAuthorizationRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAzureRMNotificationHubAuthorizationRule_send(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNotificationHubAuthorizationRuleExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "manage", "false"), + resource.TestCheckResourceAttr(resourceName, "send", "true"), + resource.TestCheckResourceAttr(resourceName, "listen", "true"), + resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + ), + }, + }, + }) +} + +func TestAccAzureRMNotificationHubAuthorizationRule_updated(t *testing.T) { + resourceName := "azurerm_notification_hub_authorization_rule.test" + + ri := acctest.RandInt() + location := testLocation() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMNotificationHubAuthorizationRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAzureRMNotificationHubAuthorizationRule_listen(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNotificationHubAuthorizationRuleExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "manage", "false"), + resource.TestCheckResourceAttr(resourceName, "send", "false"), + resource.TestCheckResourceAttr(resourceName, "listen", "true"), + resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + ), + }, + { + Config: testAzureRMNotificationHubAuthorizationRule_manage(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNotificationHubAuthorizationRuleExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "manage", "true"), + resource.TestCheckResourceAttr(resourceName, "send", "true"), + resource.TestCheckResourceAttr(resourceName, "listen", "true"), + resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + ), + }, + }, + }) +} + +func testCheckAzureRMNotificationHubAuthorizationRuleExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("not found: %s", name) + } + + client := testAccProvider.Meta().(*ArmClient).notificationHubsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + resourceGroup := rs.Primary.Attributes["resource_group_name"] + notificationHubName := rs.Primary.Attributes["notification_hub_name"] + namespaceName := rs.Primary.Attributes["namespace_name"] + ruleName := rs.Primary.Attributes["name"] + + resp, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, notificationHubName, ruleName) + if err != nil { + return fmt.Errorf("Bad: Get on notificationHubsClient: %s", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Notification Hub Authorization Rule does not exist: %s", name) + } + + return nil + } +} + +func testCheckAzureRMNotificationHubAuthorizationRuleDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).notificationHubsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_notification_hub_authorization_rule" { + continue + } + + resourceGroup := rs.Primary.Attributes["resource_group_name"] + notificationHubName := rs.Primary.Attributes["notification_hub_name"] + namespaceName := rs.Primary.Attributes["namespace_name"] + ruleName := rs.Primary.Attributes["name"] + resp, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, notificationHubName, ruleName) + + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Notification Hub Authorization Rule still exists:%s", *resp.Name) + } + } + + return nil +} + +func testAzureRMNotificationHubAuthorizationRule_listen(ri int, location string) string { + template := testAzureRMNotificationHubAuthorizationRule_template(ri, location) + return fmt.Sprintf(` +%s + +resource "azurerm_notification_hub_authorization_rule" "test" { + name = "acctestrule-%d" + notification_hub_name = "${azurerm_notification_hub.test.name}" + namespace_name = "${azurerm_notification_hub_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + listen = true +} +`, template, ri) +} + +func testAzureRMNotificationHubAuthorizationRule_send(ri int, location string) string { + template := testAzureRMNotificationHubAuthorizationRule_template(ri, location) + return fmt.Sprintf(` +%s + +resource "azurerm_notification_hub_authorization_rule" "test" { + name = "acctestrule-%d" + notification_hub_name = "${azurerm_notification_hub.test.name}" + namespace_name = "${azurerm_notification_hub_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + send = true + listen = true +} +`, template, ri) +} + +func testAzureRMNotificationHubAuthorizationRule_manage(ri int, location string) string { + template := testAzureRMNotificationHubAuthorizationRule_template(ri, location) + return fmt.Sprintf(` +%s + +resource "azurerm_notification_hub_authorization_rule" "test" { + name = "acctestrule-%d" + notification_hub_name = "${azurerm_notification_hub.test.name}" + namespace_name = "${azurerm_notification_hub_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + manage = true + send = true + listen = true +} +`, template, ri) +} + +func testAzureRMNotificationHubAuthorizationRule_template(ri int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestrg-%d" + location = "%s" +} + +resource "azurerm_notification_hub_namespace" "test" { + name = "acctestnhn-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + namespace_type = "NotificationHub" + + sku { + name = "Free" + } +} + +resource "azurerm_notification_hub" "test" { + name = "acctestnh-%d" + namespace_name = "${azurerm_notification_hub_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" +} +`, ri, location, ri, ri) +} diff --git a/azurerm/resource_arm_notification_hub_namespace.go b/azurerm/resource_arm_notification_hub_namespace.go new file mode 100644 index 000000000000..a672c84ec51a --- /dev/null +++ b/azurerm/resource_arm_notification_hub_namespace.go @@ -0,0 +1,242 @@ +package azurerm + +import ( + "context" + "fmt" + "log" + "strconv" + "time" + + "github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs" + "github.com/hashicorp/terraform/helper/resource" + "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/utils" +) + +func resourceArmNotificationHubNamespace() *schema.Resource { + return &schema.Resource{ + Create: resourceArmNotificationHubNamespaceCreateUpdate, + Read: resourceArmNotificationHubNamespaceRead, + Update: resourceArmNotificationHubNamespaceCreateUpdate, + Delete: resourceArmNotificationHubNamespaceDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "resource_group_name": resourceGroupNameSchema(), + + "location": locationSchema(), + + "sku": { + Type: schema.TypeList, + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + string(notificationhubs.Basic), + string(notificationhubs.Free), + string(notificationhubs.Standard), + }, false), + }, + }, + }, + }, + + "enabled": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + + "namespace_type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(notificationhubs.Messaging), + string(notificationhubs.NotificationHub), + }, true), + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + }, + + // NOTE: skipping tags as there's a bug in the API where the Keys for Tags are returned in lower-case + // Azure Rest API Specs issue: https://github.com/Azure/azure-sdk-for-go/issues/2239 + //"tags": tagsSchema(), + + "servicebus_endpoint": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func resourceArmNotificationHubNamespaceCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).notificationNamespacesClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + location := azureRMNormalizeLocation(d.Get("location").(string)) + + sku := expandNotificationHubNamespacesSku(d.Get("sku").([]interface{})) + + namespaceType := d.Get("namespace_type").(string) + enabled := d.Get("enabled").(bool) + + parameters := notificationhubs.NamespaceCreateOrUpdateParameters{ + Location: utils.String(location), + Sku: sku, + NamespaceProperties: ¬ificationhubs.NamespaceProperties{ + Region: utils.String(location), + NamespaceType: notificationhubs.NamespaceType(namespaceType), + Enabled: utils.Bool(enabled), + }, + } + _, err := client.CreateOrUpdate(ctx, resourceGroup, name, parameters) + if err != nil { + return fmt.Errorf("Error creating/updating Notification Hub Namesapce %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + read, err := client.Get(ctx, resourceGroup, name) + if err != nil { + return fmt.Errorf("Error retrieving Notification Hub Namesapce %q (Resource Group %q): %+v", name, resourceGroup, err) + } + if read.ID == nil { + return fmt.Errorf("Cannot read Notification Hub Namespace %q (Resource Group %q) ID", name, resourceGroup) + } + + d.SetId(*read.ID) + + return resourceArmNotificationHubNamespaceRead(d, meta) +} + +func resourceArmNotificationHubNamespaceRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).notificationNamespacesClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + name := id.Path["namespaces"] + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[DEBUG] Notification Hub Namespace %q (Resource Group %q) was not found - removing from state!", name, resourceGroup) + d.SetId("") + return nil + } + + return fmt.Errorf("Error making Read request on Notification Hub Namespace %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", resourceGroup) + if location := resp.Location; location != nil { + d.Set("location", azureRMNormalizeLocation(*location)) + } + + sku := flattenNotificationHubNamespacesSku(resp.Sku) + if err := d.Set("sku", sku); err != nil { + return fmt.Errorf("Error setting `sku`: %+v", err) + } + + if props := resp.NamespaceProperties; props != nil { + d.Set("enabled", props.Enabled) + d.Set("namespace_type", props.NamespaceType) + d.Set("servicebus_endpoint", props.ServiceBusEndpoint) + } + + return nil +} + +func resourceArmNotificationHubNamespaceDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).notificationNamespacesClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + name := id.Path["namespaces"] + + future, err := client.Delete(ctx, resourceGroup, name) + if err != nil { + if !response.WasNotFound(future.Response()) { + return fmt.Errorf("Error deleting Notification Hub Namespace %q (Resource Group %q): %+v", name, resourceGroup, err) + } + } + + // the future returned from the Delete method is broken 50% of the time - let's poll ourselves for now + // Related Bug: https://github.com/Azure/azure-sdk-for-go/issues/2254 + log.Printf("[DEBUG] Waiting for Notification Hub Namespace %q (Resource Group %q) to be deleted", name, resourceGroup) + stateConf := &resource.StateChangeConf{ + Pending: []string{"200", "202"}, + Target: []string{"404"}, + Refresh: notificationHubNamespaceStateRefreshFunc(ctx, client, resourceGroup, name), + Timeout: 10 * time.Minute, + } + if _, err := stateConf.WaitForState(); err != nil { + return fmt.Errorf("Error waiting for Notification Hub %q (Resource Group %q) to be deleted: %s", name, resourceGroup, err) + } + + return nil +} + +func expandNotificationHubNamespacesSku(input []interface{}) *notificationhubs.Sku { + v := input[0].(map[string]interface{}) + + skuName := v["name"].(string) + + return ¬ificationhubs.Sku{ + Name: notificationhubs.SkuName(skuName), + } +} + +func flattenNotificationHubNamespacesSku(input *notificationhubs.Sku) []interface{} { + outputs := make([]interface{}, 0) + if input == nil { + return outputs + } + + output := map[string]interface{}{ + "name": string(input.Name), + } + outputs = append(outputs, output) + return outputs +} + +func notificationHubNamespaceStateRefreshFunc(ctx context.Context, client notificationhubs.NamespacesClient, resourceGroupName string, name string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + res, err := client.Get(ctx, resourceGroupName, name) + if err != nil { + if !utils.ResponseWasNotFound(res.Response) { + return nil, "", fmt.Errorf("Error retrieving Notification Hub Namespace %q (Resource Group %q): %s", name, resourceGroupName, err) + } + } + + // Note: this exists as the Delete API only seems to work some of the time + // in this case we're going to try triggering the Deletion again, in-case it didn't work prior to this attepmpt + // Upstream Bug: https://github.com/Azure/azure-sdk-for-go/issues/2254 + client.Delete(ctx, resourceGroupName, name) + + return res, strconv.Itoa(res.StatusCode), nil + } +} diff --git a/azurerm/resource_arm_notification_hub_namespace_test.go b/azurerm/resource_arm_notification_hub_namespace_test.go new file mode 100644 index 000000000000..828b9a741fee --- /dev/null +++ b/azurerm/resource_arm_notification_hub_namespace_test.go @@ -0,0 +1,123 @@ +package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccAzureRMNotificationHubNamespace_free(t *testing.T) { + resourceName := "azurerm_notification_hub_namespace.test" + + ri := acctest.RandInt() + location := testLocation() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMNotificationHubNamespaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAzureRMNotificationHubNamespace_free(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNotificationHubNamespaceExists(resourceName), + ), + }, + }, + }) +} + +func testCheckAzureRMNotificationHubNamespaceExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("not found: %s", name) + } + + client := testAccProvider.Meta().(*ArmClient).notificationNamespacesClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + resourceGroup := rs.Primary.Attributes["resource_group_name"] + namespaceName := rs.Primary.Attributes["name"] + + resp, err := client.Get(ctx, resourceGroup, namespaceName) + if err != nil { + return fmt.Errorf("Bad: Get on notificationNamespacesClient: %s", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Notification Hub Namespace does not exist: %s", name) + } + + return nil + } +} + +func testCheckAzureRMNotificationHubNamespaceDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).notificationNamespacesClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_notification_hub_namespace" { + continue + } + + resourceGroup := rs.Primary.Attributes["resource_group_name"] + namespaceName := rs.Primary.Attributes["name"] + resp, err := client.Get(ctx, resourceGroup, namespaceName) + + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Notification Hub Namespace still exists:%s", *resp.Name) + } + } + + return nil +} + +func testAzureRMNotificationHubNamespace_free(ri int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestrg-%d" + location = "%s" +} + +resource "azurerm_notification_hub_namespace" "test" { + name = "acctestnhn-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + namespace_type = "NotificationHub" + + sku { + name = "Free" + } +} +`, ri, location, ri) +} + +func testAzureRMNotificationHubNamespace_basic(ri int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestrg-%d" + location = "%s" +} + +resource "azurerm_notification_hub_namespace" "test" { + name = "acctestnhn-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + namespace_type = "NotificationHub" + + sku { + name = "Basic" + } +} +`, ri, location, ri) +} diff --git a/azurerm/resource_arm_notification_hub_test.go b/azurerm/resource_arm_notification_hub_test.go new file mode 100644 index 000000000000..ef57f9c34558 --- /dev/null +++ b/azurerm/resource_arm_notification_hub_test.go @@ -0,0 +1,114 @@ +package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccAzureRMNotificationHub_basic(t *testing.T) { + resourceName := "azurerm_notification_hub.test" + + ri := acctest.RandInt() + location := testLocation() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMNotificationHubDestroy, + Steps: []resource.TestStep{ + { + Config: testAzureRMNotificationHub_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNotificationHubExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "apns_credential.#", "0"), + resource.TestCheckResourceAttr(resourceName, "gcm_credential.#", "0"), + ), + }, + }, + }) +} + +func testCheckAzureRMNotificationHubExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("not found: %s", name) + } + + client := testAccProvider.Meta().(*ArmClient).notificationHubsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + resourceGroup := rs.Primary.Attributes["resource_group_name"] + namespaceName := rs.Primary.Attributes["namespace_name"] + hubName := rs.Primary.Attributes["name"] + + resp, err := client.Get(ctx, resourceGroup, namespaceName, hubName) + if err != nil { + return fmt.Errorf("Bad: Get on notificationHubsClient: %s", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Notification Hub does not exist: %s", name) + } + + return nil + } +} + +func testCheckAzureRMNotificationHubDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).notificationHubsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_notification_hub" { + continue + } + + resourceGroup := rs.Primary.Attributes["resource_group_name"] + namespaceName := rs.Primary.Attributes["namespace_name"] + hubName := rs.Primary.Attributes["name"] + + resp, err := client.Get(ctx, resourceGroup, namespaceName, hubName) + + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Notification Hub still exists:%s", *resp.Name) + } + } + + return nil +} + +func testAzureRMNotificationHub_basic(ri int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestrgpol-%d" + location = "%s" +} + +resource "azurerm_notification_hub_namespace" "test" { + name = "acctestnhn-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + namespace_type = "NotificationHub" + sku { + name = "Free" + } +} + +resource "azurerm_notification_hub" "test" { + name = "acctestnh-%d" + namespace_name = "${azurerm_notification_hub_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" +} +`, ri, location, ri, ri) +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs/client.go b/vendor/github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs/client.go new file mode 100644 index 000000000000..e6e99da73137 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs/client.go @@ -0,0 +1,51 @@ +// Package notificationhubs implements the Azure ARM Notificationhubs service API version 2017-04-01. +// +// Azure NotificationHub client +package notificationhubs + +// 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 Notificationhubs + DefaultBaseURI = "https://management.azure.com" +) + +// BaseClient is the base client for Notificationhubs. +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/notificationhubs/mgmt/2017-04-01/notificationhubs/models.go b/vendor/github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs/models.go new file mode 100644 index 000000000000..82520f63cce1 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs/models.go @@ -0,0 +1,2128 @@ +package notificationhubs + +// 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/azure" + "github.com/Azure/go-autorest/autorest/date" + "github.com/Azure/go-autorest/autorest/to" + "net/http" +) + +// AccessRights enumerates the values for access rights. +type AccessRights string + +const ( + // Listen ... + Listen AccessRights = "Listen" + // Manage ... + Manage AccessRights = "Manage" + // Send ... + Send AccessRights = "Send" +) + +// PossibleAccessRightsValues returns an array of possible values for the AccessRights const type. +func PossibleAccessRightsValues() []AccessRights { + return []AccessRights{Listen, Manage, Send} +} + +// NamespaceType enumerates the values for namespace type. +type NamespaceType string + +const ( + // Messaging ... + Messaging NamespaceType = "Messaging" + // NotificationHub ... + NotificationHub NamespaceType = "NotificationHub" +) + +// PossibleNamespaceTypeValues returns an array of possible values for the NamespaceType const type. +func PossibleNamespaceTypeValues() []NamespaceType { + return []NamespaceType{Messaging, NotificationHub} +} + +// SkuName enumerates the values for sku name. +type SkuName string + +const ( + // Basic ... + Basic SkuName = "Basic" + // Free ... + Free SkuName = "Free" + // Standard ... + Standard SkuName = "Standard" +) + +// PossibleSkuNameValues returns an array of possible values for the SkuName const type. +func PossibleSkuNameValues() []SkuName { + return []SkuName{Basic, Free, Standard} +} + +// AdmCredential description of a NotificationHub AdmCredential. +type AdmCredential struct { + // AdmCredentialProperties - Properties of NotificationHub AdmCredential. + *AdmCredentialProperties `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for AdmCredential. +func (ac AdmCredential) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if ac.AdmCredentialProperties != nil { + objectMap["properties"] = ac.AdmCredentialProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for AdmCredential struct. +func (ac *AdmCredential) 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 "properties": + if v != nil { + var admCredentialProperties AdmCredentialProperties + err = json.Unmarshal(*v, &admCredentialProperties) + if err != nil { + return err + } + ac.AdmCredentialProperties = &admCredentialProperties + } + } + } + + return nil +} + +// AdmCredentialProperties description of a NotificationHub AdmCredential. +type AdmCredentialProperties struct { + // ClientID - The client identifier. + ClientID *string `json:"clientId,omitempty"` + // ClientSecret - The credential secret access key. + ClientSecret *string `json:"clientSecret,omitempty"` + // AuthTokenURL - The URL of the authorization token. + AuthTokenURL *string `json:"authTokenUrl,omitempty"` +} + +// ApnsCredential description of a NotificationHub ApnsCredential. +type ApnsCredential struct { + // ApnsCredentialProperties - Properties of NotificationHub ApnsCredential. + *ApnsCredentialProperties `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for ApnsCredential. +func (ac ApnsCredential) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if ac.ApnsCredentialProperties != nil { + objectMap["properties"] = ac.ApnsCredentialProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for ApnsCredential struct. +func (ac *ApnsCredential) 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 "properties": + if v != nil { + var apnsCredentialProperties ApnsCredentialProperties + err = json.Unmarshal(*v, &apnsCredentialProperties) + if err != nil { + return err + } + ac.ApnsCredentialProperties = &apnsCredentialProperties + } + } + } + + return nil +} + +// ApnsCredentialProperties description of a NotificationHub ApnsCredential. +type ApnsCredentialProperties struct { + // ApnsCertificate - The APNS certificate. + ApnsCertificate *string `json:"apnsCertificate,omitempty"` + // CertificateKey - The certificate key. + CertificateKey *string `json:"certificateKey,omitempty"` + // Endpoint - The endpoint of this credential. + Endpoint *string `json:"endpoint,omitempty"` + // Thumbprint - The Apns certificate Thumbprint + Thumbprint *string `json:"thumbprint,omitempty"` + // KeyID - A 10-character key identifier (kid) key, obtained from your developer account + KeyID *string `json:"keyId,omitempty"` + // AppName - The name of the application + AppName *string `json:"appName,omitempty"` + // AppID - The issuer (iss) registered claim key, whose value is your 10-character Team ID, obtained from your developer account + AppID *string `json:"appId,omitempty"` + // Token - Provider Authentication Token, obtained through your developer account + Token *string `json:"token,omitempty"` +} + +// BaiduCredential description of a NotificationHub BaiduCredential. +type BaiduCredential struct { + // BaiduCredentialProperties - Properties of NotificationHub BaiduCredential. + *BaiduCredentialProperties `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for BaiduCredential. +func (bc BaiduCredential) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if bc.BaiduCredentialProperties != nil { + objectMap["properties"] = bc.BaiduCredentialProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for BaiduCredential struct. +func (bc *BaiduCredential) 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 "properties": + if v != nil { + var baiduCredentialProperties BaiduCredentialProperties + err = json.Unmarshal(*v, &baiduCredentialProperties) + if err != nil { + return err + } + bc.BaiduCredentialProperties = &baiduCredentialProperties + } + } + } + + return nil +} + +// BaiduCredentialProperties description of a NotificationHub BaiduCredential. +type BaiduCredentialProperties struct { + // BaiduAPIKey - Baidu Api Key. + BaiduAPIKey *string `json:"baiduApiKey,omitempty"` + // BaiduEndPoint - Baidu Endpoint. + BaiduEndPoint *string `json:"baiduEndPoint,omitempty"` + // BaiduSecretKey - Baidu Secret Key + BaiduSecretKey *string `json:"baiduSecretKey,omitempty"` +} + +// CheckAvailabilityParameters parameters supplied to the Check Name Availability for Namespace and +// NotificationHubs. +type CheckAvailabilityParameters struct { + // ID - Resource Id + ID *string `json:"id,omitempty"` + // Name - Resource name + Name *string `json:"name,omitempty"` + // Type - Resource type + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Tags - Resource tags + Tags map[string]*string `json:"tags"` + // Sku - The sku of the created namespace + Sku *Sku `json:"sku,omitempty"` + // IsAvailiable - True if the name is available and can be used to create new Namespace/NotificationHub. Otherwise false. + IsAvailiable *bool `json:"isAvailiable,omitempty"` +} + +// MarshalJSON is the custom marshaler for CheckAvailabilityParameters. +func (capVar CheckAvailabilityParameters) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if capVar.ID != nil { + objectMap["id"] = capVar.ID + } + if capVar.Name != nil { + objectMap["name"] = capVar.Name + } + if capVar.Type != nil { + objectMap["type"] = capVar.Type + } + if capVar.Location != nil { + objectMap["location"] = capVar.Location + } + if capVar.Tags != nil { + objectMap["tags"] = capVar.Tags + } + if capVar.Sku != nil { + objectMap["sku"] = capVar.Sku + } + if capVar.IsAvailiable != nil { + objectMap["isAvailiable"] = capVar.IsAvailiable + } + return json.Marshal(objectMap) +} + +// CheckAvailabilityResult description of a CheckAvailibility resource. +type CheckAvailabilityResult struct { + autorest.Response `json:"-"` + // IsAvailiable - True if the name is available and can be used to create new Namespace/NotificationHub. Otherwise false. + IsAvailiable *bool `json:"isAvailiable,omitempty"` + // ID - Resource Id + ID *string `json:"id,omitempty"` + // Name - Resource name + Name *string `json:"name,omitempty"` + // Type - Resource type + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Tags - Resource tags + Tags map[string]*string `json:"tags"` + // Sku - The sku of the created namespace + Sku *Sku `json:"sku,omitempty"` +} + +// MarshalJSON is the custom marshaler for CheckAvailabilityResult. +func (car CheckAvailabilityResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if car.IsAvailiable != nil { + objectMap["isAvailiable"] = car.IsAvailiable + } + if car.ID != nil { + objectMap["id"] = car.ID + } + if car.Name != nil { + objectMap["name"] = car.Name + } + if car.Type != nil { + objectMap["type"] = car.Type + } + if car.Location != nil { + objectMap["location"] = car.Location + } + if car.Tags != nil { + objectMap["tags"] = car.Tags + } + if car.Sku != nil { + objectMap["sku"] = car.Sku + } + return json.Marshal(objectMap) +} + +// CreateOrUpdateParameters parameters supplied to the CreateOrUpdate NotificationHub operation. +type CreateOrUpdateParameters struct { + // Properties - Properties of the NotificationHub. + *Properties `json:"properties,omitempty"` + // ID - Resource Id + ID *string `json:"id,omitempty"` + // Name - Resource name + Name *string `json:"name,omitempty"` + // Type - Resource type + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Tags - Resource tags + Tags map[string]*string `json:"tags"` + // Sku - The sku of the created namespace + Sku *Sku `json:"sku,omitempty"` +} + +// MarshalJSON is the custom marshaler for CreateOrUpdateParameters. +func (coup CreateOrUpdateParameters) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if coup.Properties != nil { + objectMap["properties"] = coup.Properties + } + if coup.ID != nil { + objectMap["id"] = coup.ID + } + if coup.Name != nil { + objectMap["name"] = coup.Name + } + if coup.Type != nil { + objectMap["type"] = coup.Type + } + if coup.Location != nil { + objectMap["location"] = coup.Location + } + if coup.Tags != nil { + objectMap["tags"] = coup.Tags + } + if coup.Sku != nil { + objectMap["sku"] = coup.Sku + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for CreateOrUpdateParameters struct. +func (coup *CreateOrUpdateParameters) 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 "properties": + if v != nil { + var properties Properties + err = json.Unmarshal(*v, &properties) + if err != nil { + return err + } + coup.Properties = &properties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + coup.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + coup.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + coup.Type = &typeVar + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + coup.Location = &location + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + coup.Tags = tags + } + case "sku": + if v != nil { + var sku Sku + err = json.Unmarshal(*v, &sku) + if err != nil { + return err + } + coup.Sku = &sku + } + } + } + + return nil +} + +// DebugSendResponse description of a NotificationHub Resource. +type DebugSendResponse struct { + autorest.Response `json:"-"` + // DebugSendResult - Properties of the NotificationHub. + *DebugSendResult `json:"properties,omitempty"` + // ID - Resource Id + ID *string `json:"id,omitempty"` + // Name - Resource name + Name *string `json:"name,omitempty"` + // Type - Resource type + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Tags - Resource tags + Tags map[string]*string `json:"tags"` + // Sku - The sku of the created namespace + Sku *Sku `json:"sku,omitempty"` +} + +// MarshalJSON is the custom marshaler for DebugSendResponse. +func (dsr DebugSendResponse) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if dsr.DebugSendResult != nil { + objectMap["properties"] = dsr.DebugSendResult + } + if dsr.ID != nil { + objectMap["id"] = dsr.ID + } + if dsr.Name != nil { + objectMap["name"] = dsr.Name + } + if dsr.Type != nil { + objectMap["type"] = dsr.Type + } + if dsr.Location != nil { + objectMap["location"] = dsr.Location + } + if dsr.Tags != nil { + objectMap["tags"] = dsr.Tags + } + if dsr.Sku != nil { + objectMap["sku"] = dsr.Sku + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for DebugSendResponse struct. +func (dsr *DebugSendResponse) 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 "properties": + if v != nil { + var debugSendResult DebugSendResult + err = json.Unmarshal(*v, &debugSendResult) + if err != nil { + return err + } + dsr.DebugSendResult = &debugSendResult + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + dsr.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + dsr.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + dsr.Type = &typeVar + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + dsr.Location = &location + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + dsr.Tags = tags + } + case "sku": + if v != nil { + var sku Sku + err = json.Unmarshal(*v, &sku) + if err != nil { + return err + } + dsr.Sku = &sku + } + } + } + + return nil +} + +// DebugSendResult ... +type DebugSendResult struct { + // Success - successful send + Success *float64 `json:"success,omitempty"` + // Failure - send failure + Failure *float64 `json:"failure,omitempty"` + // Results - actual failure description + Results interface{} `json:"results,omitempty"` +} + +// ErrorResponse error reponse indicates NotificationHubs service is not able to process the incoming request. The +// reason is provided in the error message. +type ErrorResponse struct { + // Code - Error code. + Code *string `json:"code,omitempty"` + // Message - Error message indicating why the operation failed. + Message *string `json:"message,omitempty"` +} + +// GcmCredential description of a NotificationHub GcmCredential. +type GcmCredential struct { + // GcmCredentialProperties - Properties of NotificationHub GcmCredential. + *GcmCredentialProperties `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for GcmCredential. +func (gc GcmCredential) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if gc.GcmCredentialProperties != nil { + objectMap["properties"] = gc.GcmCredentialProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for GcmCredential struct. +func (gc *GcmCredential) 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 "properties": + if v != nil { + var gcmCredentialProperties GcmCredentialProperties + err = json.Unmarshal(*v, &gcmCredentialProperties) + if err != nil { + return err + } + gc.GcmCredentialProperties = &gcmCredentialProperties + } + } + } + + return nil +} + +// GcmCredentialProperties description of a NotificationHub GcmCredential. +type GcmCredentialProperties struct { + // GcmEndpoint - The GCM endpoint. + GcmEndpoint *string `json:"gcmEndpoint,omitempty"` + // GoogleAPIKey - The Google API key. + GoogleAPIKey *string `json:"googleApiKey,omitempty"` +} + +// ListResult the response of the List NotificationHub operation. +type ListResult struct { + autorest.Response `json:"-"` + // Value - Result of the List NotificationHub operation. + Value *[]ResourceType `json:"value,omitempty"` + // NextLink - Link to the next set of results. Not empty if Value contains incomplete list of NotificationHub + NextLink *string `json:"nextLink,omitempty"` +} + +// ListResultIterator provides access to a complete listing of ResourceType values. +type ListResultIterator struct { + i int + page ListResultPage +} + +// 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 *ListResultIterator) 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 ListResultIterator) 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 ListResultIterator) Response() ListResult { + 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 ListResultIterator) Value() ResourceType { + if !iter.page.NotDone() { + return ResourceType{} + } + return iter.page.Values()[iter.i] +} + +// IsEmpty returns true if the ListResult contains no values. +func (lr ListResult) IsEmpty() bool { + return lr.Value == nil || len(*lr.Value) == 0 +} + +// listResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (lr ListResult) listResultPreparer() (*http.Request, error) { + if lr.NextLink == nil || len(to.String(lr.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(lr.NextLink))) +} + +// ListResultPage contains a page of ResourceType values. +type ListResultPage struct { + fn func(ListResult) (ListResult, error) + lr ListResult +} + +// 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 *ListResultPage) Next() error { + next, err := page.fn(page.lr) + if err != nil { + return err + } + page.lr = next + return nil +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page ListResultPage) NotDone() bool { + return !page.lr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page ListResultPage) Response() ListResult { + return page.lr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page ListResultPage) Values() []ResourceType { + if page.lr.IsEmpty() { + return nil + } + return *page.lr.Value +} + +// MpnsCredential description of a NotificationHub MpnsCredential. +type MpnsCredential struct { + // MpnsCredentialProperties - Properties of NotificationHub MpnsCredential. + *MpnsCredentialProperties `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for MpnsCredential. +func (mc MpnsCredential) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if mc.MpnsCredentialProperties != nil { + objectMap["properties"] = mc.MpnsCredentialProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for MpnsCredential struct. +func (mc *MpnsCredential) 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 "properties": + if v != nil { + var mpnsCredentialProperties MpnsCredentialProperties + err = json.Unmarshal(*v, &mpnsCredentialProperties) + if err != nil { + return err + } + mc.MpnsCredentialProperties = &mpnsCredentialProperties + } + } + } + + return nil +} + +// MpnsCredentialProperties description of a NotificationHub MpnsCredential. +type MpnsCredentialProperties struct { + // MpnsCertificate - The MPNS certificate. + MpnsCertificate *string `json:"mpnsCertificate,omitempty"` + // CertificateKey - The certificate key for this credential. + CertificateKey *string `json:"certificateKey,omitempty"` + // Thumbprint - The Mpns certificate Thumbprint + Thumbprint *string `json:"thumbprint,omitempty"` +} + +// NamespaceCreateOrUpdateParameters parameters supplied to the CreateOrUpdate Namespace operation. +type NamespaceCreateOrUpdateParameters struct { + // NamespaceProperties - Properties of the Namespace. + *NamespaceProperties `json:"properties,omitempty"` + // ID - Resource Id + ID *string `json:"id,omitempty"` + // Name - Resource name + Name *string `json:"name,omitempty"` + // Type - Resource type + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Tags - Resource tags + Tags map[string]*string `json:"tags"` + // Sku - The sku of the created namespace + Sku *Sku `json:"sku,omitempty"` +} + +// MarshalJSON is the custom marshaler for NamespaceCreateOrUpdateParameters. +func (ncoup NamespaceCreateOrUpdateParameters) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if ncoup.NamespaceProperties != nil { + objectMap["properties"] = ncoup.NamespaceProperties + } + if ncoup.ID != nil { + objectMap["id"] = ncoup.ID + } + if ncoup.Name != nil { + objectMap["name"] = ncoup.Name + } + if ncoup.Type != nil { + objectMap["type"] = ncoup.Type + } + if ncoup.Location != nil { + objectMap["location"] = ncoup.Location + } + if ncoup.Tags != nil { + objectMap["tags"] = ncoup.Tags + } + if ncoup.Sku != nil { + objectMap["sku"] = ncoup.Sku + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for NamespaceCreateOrUpdateParameters struct. +func (ncoup *NamespaceCreateOrUpdateParameters) 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 "properties": + if v != nil { + var namespaceProperties NamespaceProperties + err = json.Unmarshal(*v, &namespaceProperties) + if err != nil { + return err + } + ncoup.NamespaceProperties = &namespaceProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + ncoup.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + ncoup.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + ncoup.Type = &typeVar + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + ncoup.Location = &location + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + ncoup.Tags = tags + } + case "sku": + if v != nil { + var sku Sku + err = json.Unmarshal(*v, &sku) + if err != nil { + return err + } + ncoup.Sku = &sku + } + } + } + + return nil +} + +// NamespaceListResult the response of the List Namespace operation. +type NamespaceListResult struct { + autorest.Response `json:"-"` + // Value - Result of the List Namespace operation. + Value *[]NamespaceResource `json:"value,omitempty"` + // NextLink - Link to the next set of results. Not empty if Value contains incomplete list of Namespaces + NextLink *string `json:"nextLink,omitempty"` +} + +// NamespaceListResultIterator provides access to a complete listing of NamespaceResource values. +type NamespaceListResultIterator struct { + i int + page NamespaceListResultPage +} + +// 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 *NamespaceListResultIterator) 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 NamespaceListResultIterator) 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 NamespaceListResultIterator) Response() NamespaceListResult { + 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 NamespaceListResultIterator) Value() NamespaceResource { + if !iter.page.NotDone() { + return NamespaceResource{} + } + return iter.page.Values()[iter.i] +} + +// IsEmpty returns true if the ListResult contains no values. +func (nlr NamespaceListResult) IsEmpty() bool { + return nlr.Value == nil || len(*nlr.Value) == 0 +} + +// namespaceListResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (nlr NamespaceListResult) namespaceListResultPreparer() (*http.Request, error) { + if nlr.NextLink == nil || len(to.String(nlr.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(nlr.NextLink))) +} + +// NamespaceListResultPage contains a page of NamespaceResource values. +type NamespaceListResultPage struct { + fn func(NamespaceListResult) (NamespaceListResult, error) + nlr NamespaceListResult +} + +// 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 *NamespaceListResultPage) Next() error { + next, err := page.fn(page.nlr) + if err != nil { + return err + } + page.nlr = next + return nil +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page NamespaceListResultPage) NotDone() bool { + return !page.nlr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page NamespaceListResultPage) Response() NamespaceListResult { + return page.nlr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page NamespaceListResultPage) Values() []NamespaceResource { + if page.nlr.IsEmpty() { + return nil + } + return *page.nlr.Value +} + +// NamespacePatchParameters parameters supplied to the Patch Namespace operation. +type NamespacePatchParameters struct { + // Tags - Resource tags + Tags map[string]*string `json:"tags"` + // Sku - The sku of the created namespace + Sku *Sku `json:"sku,omitempty"` +} + +// MarshalJSON is the custom marshaler for NamespacePatchParameters. +func (npp NamespacePatchParameters) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if npp.Tags != nil { + objectMap["tags"] = npp.Tags + } + if npp.Sku != nil { + objectMap["sku"] = npp.Sku + } + return json.Marshal(objectMap) +} + +// NamespaceProperties namespace properties. +type NamespaceProperties struct { + // Name - The name of the namespace. + Name *string `json:"name,omitempty"` + // ProvisioningState - Provisioning state of the Namespace. + ProvisioningState *string `json:"provisioningState,omitempty"` + // Region - Specifies the targeted region in which the namespace should be created. It can be any of the following values: Australia EastAustralia SoutheastCentral USEast USEast US 2West USNorth Central USSouth Central USEast AsiaSoutheast AsiaBrazil SouthJapan EastJapan WestNorth EuropeWest Europe + Region *string `json:"region,omitempty"` + // MetricID - Identifier for Azure Insights metrics + MetricID *string `json:"metricId,omitempty"` + // Status - Status of the namespace. It can be any of these values:1 = Created/Active2 = Creating3 = Suspended4 = Deleting + Status *string `json:"status,omitempty"` + // CreatedAt - The time the namespace was created. + CreatedAt *date.Time `json:"createdAt,omitempty"` + // UpdatedAt - The time the namespace was updated. + UpdatedAt *date.Time `json:"updatedAt,omitempty"` + // ServiceBusEndpoint - Endpoint you can use to perform NotificationHub operations. + ServiceBusEndpoint *string `json:"serviceBusEndpoint,omitempty"` + // SubscriptionID - The Id of the Azure subscription associated with the namespace. + SubscriptionID *string `json:"subscriptionId,omitempty"` + // ScaleUnit - ScaleUnit where the namespace gets created + ScaleUnit *string `json:"scaleUnit,omitempty"` + // Enabled - Whether or not the namespace is currently enabled. + Enabled *bool `json:"enabled,omitempty"` + // Critical - Whether or not the namespace is set as Critical. + Critical *bool `json:"critical,omitempty"` + // DataCenter - Data center for the namespace + DataCenter *string `json:"dataCenter,omitempty"` + // NamespaceType - The namespace type. Possible values include: 'Messaging', 'NotificationHub' + NamespaceType NamespaceType `json:"namespaceType,omitempty"` +} + +// NamespaceResource description of a Namespace resource. +type NamespaceResource struct { + autorest.Response `json:"-"` + // NamespaceProperties - Properties of the Namespace. + *NamespaceProperties `json:"properties,omitempty"` + // ID - Resource Id + ID *string `json:"id,omitempty"` + // Name - Resource name + Name *string `json:"name,omitempty"` + // Type - Resource type + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Tags - Resource tags + Tags map[string]*string `json:"tags"` + // Sku - The sku of the created namespace + Sku *Sku `json:"sku,omitempty"` +} + +// MarshalJSON is the custom marshaler for NamespaceResource. +func (nr NamespaceResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if nr.NamespaceProperties != nil { + objectMap["properties"] = nr.NamespaceProperties + } + if nr.ID != nil { + objectMap["id"] = nr.ID + } + if nr.Name != nil { + objectMap["name"] = nr.Name + } + if nr.Type != nil { + objectMap["type"] = nr.Type + } + if nr.Location != nil { + objectMap["location"] = nr.Location + } + if nr.Tags != nil { + objectMap["tags"] = nr.Tags + } + if nr.Sku != nil { + objectMap["sku"] = nr.Sku + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for NamespaceResource struct. +func (nr *NamespaceResource) 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 "properties": + if v != nil { + var namespaceProperties NamespaceProperties + err = json.Unmarshal(*v, &namespaceProperties) + if err != nil { + return err + } + nr.NamespaceProperties = &namespaceProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + nr.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + nr.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + nr.Type = &typeVar + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + nr.Location = &location + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + nr.Tags = tags + } + case "sku": + if v != nil { + var sku Sku + err = json.Unmarshal(*v, &sku) + if err != nil { + return err + } + nr.Sku = &sku + } + } + } + + return nil +} + +// NamespacesDeleteFuture an abstraction for monitoring and retrieving the results of a long-running operation. +type NamespacesDeleteFuture struct { + azure.Future +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future *NamespacesDeleteFuture) Result(client NamespacesClient) (ar autorest.Response, err error) { + var done bool + done, err = future.Done(client) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesDeleteFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("notificationhubs.NamespacesDeleteFuture") + return + } + ar.Response = future.Response() + return +} + +// Operation a NotificationHubs REST API operation +type Operation struct { + // Name - Operation name: {provider}/{resource}/{operation} + Name *string `json:"name,omitempty"` + // Display - The object that represents the operation. + Display *OperationDisplay `json:"display,omitempty"` +} + +// OperationDisplay the object that represents the operation. +type OperationDisplay struct { + // Provider - Service provider: Microsoft.NotificationHubs + Provider *string `json:"provider,omitempty"` + // Resource - Resource on which the operation is performed: Invoice, etc. + Resource *string `json:"resource,omitempty"` + // Operation - Operation type: Read, write, delete, etc. + Operation *string `json:"operation,omitempty"` +} + +// OperationListResult result of the request to list NotificationHubs operations. It contains a list of operations +// and a URL link to get the next set of results. +type OperationListResult struct { + autorest.Response `json:"-"` + // Value - List of NotificationHubs operations supported by the Microsoft.NotificationHubs resource provider. + Value *[]Operation `json:"value,omitempty"` + // NextLink - URL to get the next set of operation list results if there are any. + NextLink *string `json:"nextLink,omitempty"` +} + +// OperationListResultIterator provides access to a complete listing of Operation values. +type OperationListResultIterator struct { + i int + page OperationListResultPage +} + +// 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 *OperationListResultIterator) 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 OperationListResultIterator) 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 OperationListResultIterator) Response() OperationListResult { + 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 OperationListResultIterator) Value() Operation { + if !iter.page.NotDone() { + return Operation{} + } + return iter.page.Values()[iter.i] +} + +// IsEmpty returns true if the ListResult contains no values. +func (olr OperationListResult) IsEmpty() bool { + return olr.Value == nil || len(*olr.Value) == 0 +} + +// operationListResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (olr OperationListResult) operationListResultPreparer() (*http.Request, error) { + if olr.NextLink == nil || len(to.String(olr.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(olr.NextLink))) +} + +// OperationListResultPage contains a page of Operation values. +type OperationListResultPage struct { + fn func(OperationListResult) (OperationListResult, error) + olr OperationListResult +} + +// 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 *OperationListResultPage) Next() error { + next, err := page.fn(page.olr) + if err != nil { + return err + } + page.olr = next + return nil +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page OperationListResultPage) NotDone() bool { + return !page.olr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page OperationListResultPage) Response() OperationListResult { + return page.olr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page OperationListResultPage) Values() []Operation { + if page.olr.IsEmpty() { + return nil + } + return *page.olr.Value +} + +// PatchParameters parameters supplied to the patch NotificationHub operation. +type PatchParameters struct { + // Properties - Properties of the NotificationHub. + *Properties `json:"properties,omitempty"` + // ID - Resource Id + ID *string `json:"id,omitempty"` + // Name - Resource name + Name *string `json:"name,omitempty"` + // Type - Resource type + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Tags - Resource tags + Tags map[string]*string `json:"tags"` + // Sku - The sku of the created namespace + Sku *Sku `json:"sku,omitempty"` +} + +// MarshalJSON is the custom marshaler for PatchParameters. +func (pp PatchParameters) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if pp.Properties != nil { + objectMap["properties"] = pp.Properties + } + if pp.ID != nil { + objectMap["id"] = pp.ID + } + if pp.Name != nil { + objectMap["name"] = pp.Name + } + if pp.Type != nil { + objectMap["type"] = pp.Type + } + if pp.Location != nil { + objectMap["location"] = pp.Location + } + if pp.Tags != nil { + objectMap["tags"] = pp.Tags + } + if pp.Sku != nil { + objectMap["sku"] = pp.Sku + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for PatchParameters struct. +func (pp *PatchParameters) 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 "properties": + if v != nil { + var properties Properties + err = json.Unmarshal(*v, &properties) + if err != nil { + return err + } + pp.Properties = &properties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + pp.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + pp.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + pp.Type = &typeVar + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + pp.Location = &location + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + pp.Tags = tags + } + case "sku": + if v != nil { + var sku Sku + err = json.Unmarshal(*v, &sku) + if err != nil { + return err + } + pp.Sku = &sku + } + } + } + + return nil +} + +// PnsCredentialsProperties description of a NotificationHub PNS Credentials. +type PnsCredentialsProperties struct { + // ApnsCredential - The ApnsCredential of the created NotificationHub + ApnsCredential *ApnsCredential `json:"apnsCredential,omitempty"` + // WnsCredential - The WnsCredential of the created NotificationHub + WnsCredential *WnsCredential `json:"wnsCredential,omitempty"` + // GcmCredential - The GcmCredential of the created NotificationHub + GcmCredential *GcmCredential `json:"gcmCredential,omitempty"` + // MpnsCredential - The MpnsCredential of the created NotificationHub + MpnsCredential *MpnsCredential `json:"mpnsCredential,omitempty"` + // AdmCredential - The AdmCredential of the created NotificationHub + AdmCredential *AdmCredential `json:"admCredential,omitempty"` + // BaiduCredential - The BaiduCredential of the created NotificationHub + BaiduCredential *BaiduCredential `json:"baiduCredential,omitempty"` +} + +// PnsCredentialsResource description of a NotificationHub PNS Credentials. +type PnsCredentialsResource struct { + autorest.Response `json:"-"` + // PnsCredentialsProperties - NotificationHub PNS Credentials. + *PnsCredentialsProperties `json:"properties,omitempty"` + // ID - Resource Id + ID *string `json:"id,omitempty"` + // Name - Resource name + Name *string `json:"name,omitempty"` + // Type - Resource type + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Tags - Resource tags + Tags map[string]*string `json:"tags"` + // Sku - The sku of the created namespace + Sku *Sku `json:"sku,omitempty"` +} + +// MarshalJSON is the custom marshaler for PnsCredentialsResource. +func (pcr PnsCredentialsResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if pcr.PnsCredentialsProperties != nil { + objectMap["properties"] = pcr.PnsCredentialsProperties + } + if pcr.ID != nil { + objectMap["id"] = pcr.ID + } + if pcr.Name != nil { + objectMap["name"] = pcr.Name + } + if pcr.Type != nil { + objectMap["type"] = pcr.Type + } + if pcr.Location != nil { + objectMap["location"] = pcr.Location + } + if pcr.Tags != nil { + objectMap["tags"] = pcr.Tags + } + if pcr.Sku != nil { + objectMap["sku"] = pcr.Sku + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for PnsCredentialsResource struct. +func (pcr *PnsCredentialsResource) 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 "properties": + if v != nil { + var pnsCredentialsProperties PnsCredentialsProperties + err = json.Unmarshal(*v, &pnsCredentialsProperties) + if err != nil { + return err + } + pcr.PnsCredentialsProperties = &pnsCredentialsProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + pcr.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + pcr.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + pcr.Type = &typeVar + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + pcr.Location = &location + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + pcr.Tags = tags + } + case "sku": + if v != nil { + var sku Sku + err = json.Unmarshal(*v, &sku) + if err != nil { + return err + } + pcr.Sku = &sku + } + } + } + + return nil +} + +// PolicykeyResource namespace/NotificationHub Regenerate Keys +type PolicykeyResource struct { + // PolicyKey - Name of the key that has to be regenerated for the Namespace/Notification Hub Authorization Rule. The value can be Primary Key/Secondary Key. + PolicyKey *string `json:"policyKey,omitempty"` +} + +// Properties notificationHub properties. +type Properties struct { + // Name - The NotificationHub name. + Name *string `json:"name,omitempty"` + // RegistrationTTL - The RegistrationTtl of the created NotificationHub + RegistrationTTL *string `json:"registrationTtl,omitempty"` + // AuthorizationRules - The AuthorizationRules of the created NotificationHub + AuthorizationRules *[]SharedAccessAuthorizationRuleProperties `json:"authorizationRules,omitempty"` + // ApnsCredential - The ApnsCredential of the created NotificationHub + ApnsCredential *ApnsCredential `json:"apnsCredential,omitempty"` + // WnsCredential - The WnsCredential of the created NotificationHub + WnsCredential *WnsCredential `json:"wnsCredential,omitempty"` + // GcmCredential - The GcmCredential of the created NotificationHub + GcmCredential *GcmCredential `json:"gcmCredential,omitempty"` + // MpnsCredential - The MpnsCredential of the created NotificationHub + MpnsCredential *MpnsCredential `json:"mpnsCredential,omitempty"` + // AdmCredential - The AdmCredential of the created NotificationHub + AdmCredential *AdmCredential `json:"admCredential,omitempty"` + // BaiduCredential - The BaiduCredential of the created NotificationHub + BaiduCredential *BaiduCredential `json:"baiduCredential,omitempty"` +} + +// Resource ... +type Resource struct { + // ID - Resource Id + ID *string `json:"id,omitempty"` + // Name - Resource name + Name *string `json:"name,omitempty"` + // Type - Resource type + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Tags - Resource tags + Tags map[string]*string `json:"tags"` + // Sku - The sku of the created namespace + Sku *Sku `json:"sku,omitempty"` +} + +// MarshalJSON is the custom marshaler for Resource. +func (r Resource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if r.ID != nil { + objectMap["id"] = r.ID + } + if r.Name != nil { + objectMap["name"] = r.Name + } + if r.Type != nil { + objectMap["type"] = r.Type + } + if r.Location != nil { + objectMap["location"] = r.Location + } + if r.Tags != nil { + objectMap["tags"] = r.Tags + } + if r.Sku != nil { + objectMap["sku"] = r.Sku + } + return json.Marshal(objectMap) +} + +// ResourceListKeys namespace/NotificationHub Connection String +type ResourceListKeys struct { + autorest.Response `json:"-"` + // PrimaryConnectionString - PrimaryConnectionString of the AuthorizationRule. + PrimaryConnectionString *string `json:"primaryConnectionString,omitempty"` + // SecondaryConnectionString - SecondaryConnectionString of the created AuthorizationRule + SecondaryConnectionString *string `json:"secondaryConnectionString,omitempty"` + // PrimaryKey - PrimaryKey of the created AuthorizationRule. + PrimaryKey *string `json:"primaryKey,omitempty"` + // SecondaryKey - SecondaryKey of the created AuthorizationRule + SecondaryKey *string `json:"secondaryKey,omitempty"` + // KeyName - KeyName of the created AuthorizationRule + KeyName *string `json:"keyName,omitempty"` +} + +// ResourceType description of a NotificationHub Resource. +type ResourceType struct { + autorest.Response `json:"-"` + // Properties - Properties of the NotificationHub. + *Properties `json:"properties,omitempty"` + // ID - Resource Id + ID *string `json:"id,omitempty"` + // Name - Resource name + Name *string `json:"name,omitempty"` + // Type - Resource type + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Tags - Resource tags + Tags map[string]*string `json:"tags"` + // Sku - The sku of the created namespace + Sku *Sku `json:"sku,omitempty"` +} + +// MarshalJSON is the custom marshaler for ResourceType. +func (rt ResourceType) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if rt.Properties != nil { + objectMap["properties"] = rt.Properties + } + if rt.ID != nil { + objectMap["id"] = rt.ID + } + if rt.Name != nil { + objectMap["name"] = rt.Name + } + if rt.Type != nil { + objectMap["type"] = rt.Type + } + if rt.Location != nil { + objectMap["location"] = rt.Location + } + if rt.Tags != nil { + objectMap["tags"] = rt.Tags + } + if rt.Sku != nil { + objectMap["sku"] = rt.Sku + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for ResourceType struct. +func (rt *ResourceType) 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 "properties": + if v != nil { + var properties Properties + err = json.Unmarshal(*v, &properties) + if err != nil { + return err + } + rt.Properties = &properties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + rt.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + rt.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + rt.Type = &typeVar + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + rt.Location = &location + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + rt.Tags = tags + } + case "sku": + if v != nil { + var sku Sku + err = json.Unmarshal(*v, &sku) + if err != nil { + return err + } + rt.Sku = &sku + } + } + } + + return nil +} + +// SharedAccessAuthorizationRuleCreateOrUpdateParameters parameters supplied to the CreateOrUpdate Namespace +// AuthorizationRules. +type SharedAccessAuthorizationRuleCreateOrUpdateParameters struct { + // Properties - Properties of the Namespace AuthorizationRules. + Properties *SharedAccessAuthorizationRuleProperties `json:"properties,omitempty"` +} + +// SharedAccessAuthorizationRuleListResult the response of the List Namespace operation. +type SharedAccessAuthorizationRuleListResult struct { + autorest.Response `json:"-"` + // Value - Result of the List AuthorizationRules operation. + Value *[]SharedAccessAuthorizationRuleResource `json:"value,omitempty"` + // NextLink - Link to the next set of results. Not empty if Value contains incomplete list of AuthorizationRules + NextLink *string `json:"nextLink,omitempty"` +} + +// SharedAccessAuthorizationRuleListResultIterator provides access to a complete listing of +// SharedAccessAuthorizationRuleResource values. +type SharedAccessAuthorizationRuleListResultIterator struct { + i int + page SharedAccessAuthorizationRuleListResultPage +} + +// 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 *SharedAccessAuthorizationRuleListResultIterator) 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 SharedAccessAuthorizationRuleListResultIterator) 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 SharedAccessAuthorizationRuleListResultIterator) Response() SharedAccessAuthorizationRuleListResult { + 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 SharedAccessAuthorizationRuleListResultIterator) Value() SharedAccessAuthorizationRuleResource { + if !iter.page.NotDone() { + return SharedAccessAuthorizationRuleResource{} + } + return iter.page.Values()[iter.i] +} + +// IsEmpty returns true if the ListResult contains no values. +func (saarlr SharedAccessAuthorizationRuleListResult) IsEmpty() bool { + return saarlr.Value == nil || len(*saarlr.Value) == 0 +} + +// sharedAccessAuthorizationRuleListResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (saarlr SharedAccessAuthorizationRuleListResult) sharedAccessAuthorizationRuleListResultPreparer() (*http.Request, error) { + if saarlr.NextLink == nil || len(to.String(saarlr.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(saarlr.NextLink))) +} + +// SharedAccessAuthorizationRuleListResultPage contains a page of SharedAccessAuthorizationRuleResource values. +type SharedAccessAuthorizationRuleListResultPage struct { + fn func(SharedAccessAuthorizationRuleListResult) (SharedAccessAuthorizationRuleListResult, error) + saarlr SharedAccessAuthorizationRuleListResult +} + +// 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 *SharedAccessAuthorizationRuleListResultPage) Next() error { + next, err := page.fn(page.saarlr) + if err != nil { + return err + } + page.saarlr = next + return nil +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page SharedAccessAuthorizationRuleListResultPage) NotDone() bool { + return !page.saarlr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page SharedAccessAuthorizationRuleListResultPage) Response() SharedAccessAuthorizationRuleListResult { + return page.saarlr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page SharedAccessAuthorizationRuleListResultPage) Values() []SharedAccessAuthorizationRuleResource { + if page.saarlr.IsEmpty() { + return nil + } + return *page.saarlr.Value +} + +// SharedAccessAuthorizationRuleProperties sharedAccessAuthorizationRule properties. +type SharedAccessAuthorizationRuleProperties struct { + // Rights - The rights associated with the rule. + Rights *[]AccessRights `json:"rights,omitempty"` + // PrimaryKey - A base64-encoded 256-bit primary key for signing and validating the SAS token. + PrimaryKey *string `json:"primaryKey,omitempty"` + // SecondaryKey - A base64-encoded 256-bit primary key for signing and validating the SAS token. + SecondaryKey *string `json:"secondaryKey,omitempty"` + // KeyName - A string that describes the authorization rule. + KeyName *string `json:"keyName,omitempty"` + // ClaimType - A string that describes the claim type + ClaimType *string `json:"claimType,omitempty"` + // ClaimValue - A string that describes the claim value + ClaimValue *string `json:"claimValue,omitempty"` + // ModifiedTime - The last modified time for this rule + ModifiedTime *string `json:"modifiedTime,omitempty"` + // CreatedTime - The created time for this rule + CreatedTime *string `json:"createdTime,omitempty"` + // Revision - The revision number for the rule + Revision *int32 `json:"revision,omitempty"` +} + +// SharedAccessAuthorizationRuleResource description of a Namespace AuthorizationRules. +type SharedAccessAuthorizationRuleResource struct { + autorest.Response `json:"-"` + // SharedAccessAuthorizationRuleProperties - Pproperties of the Namespace AuthorizationRule. + *SharedAccessAuthorizationRuleProperties `json:"properties,omitempty"` + // ID - Resource Id + ID *string `json:"id,omitempty"` + // Name - Resource name + Name *string `json:"name,omitempty"` + // Type - Resource type + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Tags - Resource tags + Tags map[string]*string `json:"tags"` + // Sku - The sku of the created namespace + Sku *Sku `json:"sku,omitempty"` +} + +// MarshalJSON is the custom marshaler for SharedAccessAuthorizationRuleResource. +func (saarr SharedAccessAuthorizationRuleResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if saarr.SharedAccessAuthorizationRuleProperties != nil { + objectMap["properties"] = saarr.SharedAccessAuthorizationRuleProperties + } + if saarr.ID != nil { + objectMap["id"] = saarr.ID + } + if saarr.Name != nil { + objectMap["name"] = saarr.Name + } + if saarr.Type != nil { + objectMap["type"] = saarr.Type + } + if saarr.Location != nil { + objectMap["location"] = saarr.Location + } + if saarr.Tags != nil { + objectMap["tags"] = saarr.Tags + } + if saarr.Sku != nil { + objectMap["sku"] = saarr.Sku + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for SharedAccessAuthorizationRuleResource struct. +func (saarr *SharedAccessAuthorizationRuleResource) 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 "properties": + if v != nil { + var sharedAccessAuthorizationRuleProperties SharedAccessAuthorizationRuleProperties + err = json.Unmarshal(*v, &sharedAccessAuthorizationRuleProperties) + if err != nil { + return err + } + saarr.SharedAccessAuthorizationRuleProperties = &sharedAccessAuthorizationRuleProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + saarr.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + saarr.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + saarr.Type = &typeVar + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + saarr.Location = &location + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + saarr.Tags = tags + } + case "sku": + if v != nil { + var sku Sku + err = json.Unmarshal(*v, &sku) + if err != nil { + return err + } + saarr.Sku = &sku + } + } + } + + return nil +} + +// Sku the Sku description for a namespace +type Sku struct { + // Name - Name of the notification hub sku. Possible values include: 'Free', 'Basic', 'Standard' + Name SkuName `json:"name,omitempty"` + // Tier - The tier of particular sku + Tier *string `json:"tier,omitempty"` + // Size - The Sku size + Size *string `json:"size,omitempty"` + // Family - The Sku Family + Family *string `json:"family,omitempty"` + // Capacity - The capacity of the resource + Capacity *int32 `json:"capacity,omitempty"` +} + +// SubResource ... +type SubResource struct { + // ID - Resource Id + ID *string `json:"id,omitempty"` +} + +// WnsCredential description of a NotificationHub WnsCredential. +type WnsCredential struct { + // WnsCredentialProperties - Properties of NotificationHub WnsCredential. + *WnsCredentialProperties `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for WnsCredential. +func (wc WnsCredential) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if wc.WnsCredentialProperties != nil { + objectMap["properties"] = wc.WnsCredentialProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for WnsCredential struct. +func (wc *WnsCredential) 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 "properties": + if v != nil { + var wnsCredentialProperties WnsCredentialProperties + err = json.Unmarshal(*v, &wnsCredentialProperties) + if err != nil { + return err + } + wc.WnsCredentialProperties = &wnsCredentialProperties + } + } + } + + return nil +} + +// WnsCredentialProperties description of a NotificationHub WnsCredential. +type WnsCredentialProperties struct { + // PackageSid - The package ID for this credential. + PackageSid *string `json:"packageSid,omitempty"` + // SecretKey - The secret key. + SecretKey *string `json:"secretKey,omitempty"` + // WindowsLiveEndpoint - The Windows Live endpoint. + WindowsLiveEndpoint *string `json:"windowsLiveEndpoint,omitempty"` +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs/namespaces.go b/vendor/github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs/namespaces.go new file mode 100644 index 000000000000..e7362a7a0a89 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs/namespaces.go @@ -0,0 +1,1028 @@ +package notificationhubs + +// 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" +) + +// NamespacesClient is the azure NotificationHub client +type NamespacesClient struct { + BaseClient +} + +// NewNamespacesClient creates an instance of the NamespacesClient client. +func NewNamespacesClient(subscriptionID string) NamespacesClient { + return NewNamespacesClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewNamespacesClientWithBaseURI creates an instance of the NamespacesClient client. +func NewNamespacesClientWithBaseURI(baseURI string, subscriptionID string) NamespacesClient { + return NamespacesClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CheckAvailability checks the availability of the given service namespace across all Azure subscriptions. This is +// useful because the domain name is created based on the service namespace name. +// Parameters: +// parameters - the namespace name. +func (client NamespacesClient) CheckAvailability(ctx context.Context, parameters CheckAvailabilityParameters) (result CheckAvailabilityResult, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.Name", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("notificationhubs.NamespacesClient", "CheckAvailability", err.Error()) + } + + req, err := client.CheckAvailabilityPreparer(ctx, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "CheckAvailability", nil, "Failure preparing request") + return + } + + resp, err := client.CheckAvailabilitySender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "CheckAvailability", resp, "Failure sending request") + return + } + + result, err = client.CheckAvailabilityResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "CheckAvailability", resp, "Failure responding to request") + } + + return +} + +// CheckAvailabilityPreparer prepares the CheckAvailability request. +func (client NamespacesClient) CheckAvailabilityPreparer(ctx context.Context, parameters CheckAvailabilityParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + 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.NotificationHubs/checkNamespaceAvailability", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CheckAvailabilitySender sends the CheckAvailability request. The method will close the +// http.Response Body if it receives an error. +func (client NamespacesClient) CheckAvailabilitySender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// CheckAvailabilityResponder handles the response to the CheckAvailability request. The method always +// closes the http.Response Body. +func (client NamespacesClient) CheckAvailabilityResponder(resp *http.Response) (result CheckAvailabilityResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// CreateOrUpdate creates/Updates a service namespace. Once created, this namespace's resource manifest is immutable. +// This operation is idempotent. +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// parameters - parameters supplied to create a Namespace Resource. +func (client NamespacesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, namespaceName string, parameters NamespaceCreateOrUpdateParameters) (result NamespaceResource, err error) { + req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, namespaceName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client NamespacesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, namespaceName string, parameters NamespaceCreateOrUpdateParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "namespaceName": autorest.Encode("path", namespaceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + 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.NotificationHubs/namespaces/{namespaceName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client NamespacesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client NamespacesClient) CreateOrUpdateResponder(resp *http.Response) (result NamespaceResource, 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 +} + +// CreateOrUpdateAuthorizationRule creates an authorization rule for a namespace +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// authorizationRuleName - aauthorization Rule Name. +// parameters - the shared access authorization rule. +func (client NamespacesClient) CreateOrUpdateAuthorizationRule(ctx context.Context, resourceGroupName string, namespaceName string, authorizationRuleName string, parameters SharedAccessAuthorizationRuleCreateOrUpdateParameters) (result SharedAccessAuthorizationRuleResource, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.Properties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("notificationhubs.NamespacesClient", "CreateOrUpdateAuthorizationRule", err.Error()) + } + + req, err := client.CreateOrUpdateAuthorizationRulePreparer(ctx, resourceGroupName, namespaceName, authorizationRuleName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "CreateOrUpdateAuthorizationRule", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateAuthorizationRuleSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "CreateOrUpdateAuthorizationRule", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateAuthorizationRuleResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "CreateOrUpdateAuthorizationRule", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdateAuthorizationRulePreparer prepares the CreateOrUpdateAuthorizationRule request. +func (client NamespacesClient) CreateOrUpdateAuthorizationRulePreparer(ctx context.Context, resourceGroupName string, namespaceName string, authorizationRuleName string, parameters SharedAccessAuthorizationRuleCreateOrUpdateParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationRuleName": autorest.Encode("path", authorizationRuleName), + "namespaceName": autorest.Encode("path", namespaceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + 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.NotificationHubs/namespaces/{namespaceName}/AuthorizationRules/{authorizationRuleName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateAuthorizationRuleSender sends the CreateOrUpdateAuthorizationRule request. The method will close the +// http.Response Body if it receives an error. +func (client NamespacesClient) CreateOrUpdateAuthorizationRuleSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateAuthorizationRuleResponder handles the response to the CreateOrUpdateAuthorizationRule request. The method always +// closes the http.Response Body. +func (client NamespacesClient) CreateOrUpdateAuthorizationRuleResponder(resp *http.Response) (result SharedAccessAuthorizationRuleResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete deletes an existing namespace. This operation also removes all associated notificationHubs under the +// namespace. +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +func (client NamespacesClient) Delete(ctx context.Context, resourceGroupName string, namespaceName string) (result NamespacesDeleteFuture, err error) { + req, err := client.DeletePreparer(ctx, resourceGroupName, namespaceName) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = client.DeleteSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "Delete", result.Response(), "Failure sending request") + return + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client NamespacesClient) DeletePreparer(ctx context.Context, resourceGroupName string, namespaceName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "namespaceName": autorest.Encode("path", namespaceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}", 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 NamespacesClient) DeleteSender(req *http.Request) (future NamespacesDeleteFuture, err error) { + var resp *http.Response + resp, err = autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) + if err != nil { + return + } + err = autorest.Respond(resp, azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent)) + if err != nil { + return + } + future.Future, err = azure.NewFutureFromResponse(resp) + return +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client NamespacesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// DeleteAuthorizationRule deletes a namespace authorization rule +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// authorizationRuleName - authorization Rule Name. +func (client NamespacesClient) DeleteAuthorizationRule(ctx context.Context, resourceGroupName string, namespaceName string, authorizationRuleName string) (result autorest.Response, err error) { + req, err := client.DeleteAuthorizationRulePreparer(ctx, resourceGroupName, namespaceName, authorizationRuleName) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "DeleteAuthorizationRule", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteAuthorizationRuleSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "DeleteAuthorizationRule", resp, "Failure sending request") + return + } + + result, err = client.DeleteAuthorizationRuleResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "DeleteAuthorizationRule", resp, "Failure responding to request") + } + + return +} + +// DeleteAuthorizationRulePreparer prepares the DeleteAuthorizationRule request. +func (client NamespacesClient) DeleteAuthorizationRulePreparer(ctx context.Context, resourceGroupName string, namespaceName string, authorizationRuleName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationRuleName": autorest.Encode("path", authorizationRuleName), + "namespaceName": autorest.Encode("path", namespaceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/AuthorizationRules/{authorizationRuleName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteAuthorizationRuleSender sends the DeleteAuthorizationRule request. The method will close the +// http.Response Body if it receives an error. +func (client NamespacesClient) DeleteAuthorizationRuleSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteAuthorizationRuleResponder handles the response to the DeleteAuthorizationRule request. The method always +// closes the http.Response Body. +func (client NamespacesClient) DeleteAuthorizationRuleResponder(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 +} + +// Get returns the description for the specified namespace. +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +func (client NamespacesClient) Get(ctx context.Context, resourceGroupName string, namespaceName string) (result NamespaceResource, err error) { + req, err := client.GetPreparer(ctx, resourceGroupName, namespaceName) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client NamespacesClient) GetPreparer(ctx context.Context, resourceGroupName string, namespaceName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "namespaceName": autorest.Encode("path", namespaceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client NamespacesClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client NamespacesClient) GetResponder(resp *http.Response) (result NamespaceResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetAuthorizationRule gets an authorization rule for a namespace by name. +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name +// authorizationRuleName - authorization rule name. +func (client NamespacesClient) GetAuthorizationRule(ctx context.Context, resourceGroupName string, namespaceName string, authorizationRuleName string) (result SharedAccessAuthorizationRuleResource, err error) { + req, err := client.GetAuthorizationRulePreparer(ctx, resourceGroupName, namespaceName, authorizationRuleName) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "GetAuthorizationRule", nil, "Failure preparing request") + return + } + + resp, err := client.GetAuthorizationRuleSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "GetAuthorizationRule", resp, "Failure sending request") + return + } + + result, err = client.GetAuthorizationRuleResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "GetAuthorizationRule", resp, "Failure responding to request") + } + + return +} + +// GetAuthorizationRulePreparer prepares the GetAuthorizationRule request. +func (client NamespacesClient) GetAuthorizationRulePreparer(ctx context.Context, resourceGroupName string, namespaceName string, authorizationRuleName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationRuleName": autorest.Encode("path", authorizationRuleName), + "namespaceName": autorest.Encode("path", namespaceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/AuthorizationRules/{authorizationRuleName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetAuthorizationRuleSender sends the GetAuthorizationRule request. The method will close the +// http.Response Body if it receives an error. +func (client NamespacesClient) GetAuthorizationRuleSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// GetAuthorizationRuleResponder handles the response to the GetAuthorizationRule request. The method always +// closes the http.Response Body. +func (client NamespacesClient) GetAuthorizationRuleResponder(resp *http.Response) (result SharedAccessAuthorizationRuleResource, 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 lists the available namespaces within a resourceGroup. +// Parameters: +// resourceGroupName - the name of the resource group. If resourceGroupName value is null the method lists all +// the namespaces within subscription +func (client NamespacesClient) List(ctx context.Context, resourceGroupName string) (result NamespaceListResultPage, err error) { + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, resourceGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.nlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "List", resp, "Failure sending request") + return + } + + result.nlr, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client NamespacesClient) ListPreparer(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-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces", 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 NamespacesClient) 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 NamespacesClient) ListResponder(resp *http.Response) (result NamespaceListResult, 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 NamespacesClient) listNextResults(lastResults NamespaceListResult) (result NamespaceListResult, err error) { + req, err := lastResults.namespaceListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "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, "notificationhubs.NamespacesClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client NamespacesClient) ListComplete(ctx context.Context, resourceGroupName string) (result NamespaceListResultIterator, err error) { + result.page, err = client.List(ctx, resourceGroupName) + return +} + +// ListAll lists all the available namespaces within the subscription irrespective of the resourceGroups. +func (client NamespacesClient) ListAll(ctx context.Context) (result NamespaceListResultPage, err error) { + result.fn = client.listAllNextResults + req, err := client.ListAllPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "ListAll", nil, "Failure preparing request") + return + } + + resp, err := client.ListAllSender(req) + if err != nil { + result.nlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "ListAll", resp, "Failure sending request") + return + } + + result.nlr, err = client.ListAllResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "ListAll", resp, "Failure responding to request") + } + + return +} + +// ListAllPreparer prepares the ListAll request. +func (client NamespacesClient) ListAllPreparer(ctx context.Context) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.NotificationHubs/namespaces", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListAllSender sends the ListAll request. The method will close the +// http.Response Body if it receives an error. +func (client NamespacesClient) ListAllSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListAllResponder handles the response to the ListAll request. The method always +// closes the http.Response Body. +func (client NamespacesClient) ListAllResponder(resp *http.Response) (result NamespaceListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listAllNextResults retrieves the next set of results, if any. +func (client NamespacesClient) listAllNextResults(lastResults NamespaceListResult) (result NamespaceListResult, err error) { + req, err := lastResults.namespaceListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "listAllNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListAllSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "listAllNextResults", resp, "Failure sending next results request") + } + result, err = client.ListAllResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "listAllNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListAllComplete enumerates all values, automatically crossing page boundaries as required. +func (client NamespacesClient) ListAllComplete(ctx context.Context) (result NamespaceListResultIterator, err error) { + result.page, err = client.ListAll(ctx) + return +} + +// ListAuthorizationRules gets the authorization rules for a namespace. +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name +func (client NamespacesClient) ListAuthorizationRules(ctx context.Context, resourceGroupName string, namespaceName string) (result SharedAccessAuthorizationRuleListResultPage, err error) { + result.fn = client.listAuthorizationRulesNextResults + req, err := client.ListAuthorizationRulesPreparer(ctx, resourceGroupName, namespaceName) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "ListAuthorizationRules", nil, "Failure preparing request") + return + } + + resp, err := client.ListAuthorizationRulesSender(req) + if err != nil { + result.saarlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "ListAuthorizationRules", resp, "Failure sending request") + return + } + + result.saarlr, err = client.ListAuthorizationRulesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "ListAuthorizationRules", resp, "Failure responding to request") + } + + return +} + +// ListAuthorizationRulesPreparer prepares the ListAuthorizationRules request. +func (client NamespacesClient) ListAuthorizationRulesPreparer(ctx context.Context, resourceGroupName string, namespaceName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "namespaceName": autorest.Encode("path", namespaceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/AuthorizationRules", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListAuthorizationRulesSender sends the ListAuthorizationRules request. The method will close the +// http.Response Body if it receives an error. +func (client NamespacesClient) ListAuthorizationRulesSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListAuthorizationRulesResponder handles the response to the ListAuthorizationRules request. The method always +// closes the http.Response Body. +func (client NamespacesClient) ListAuthorizationRulesResponder(resp *http.Response) (result SharedAccessAuthorizationRuleListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listAuthorizationRulesNextResults retrieves the next set of results, if any. +func (client NamespacesClient) listAuthorizationRulesNextResults(lastResults SharedAccessAuthorizationRuleListResult) (result SharedAccessAuthorizationRuleListResult, err error) { + req, err := lastResults.sharedAccessAuthorizationRuleListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "listAuthorizationRulesNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListAuthorizationRulesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "listAuthorizationRulesNextResults", resp, "Failure sending next results request") + } + result, err = client.ListAuthorizationRulesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "listAuthorizationRulesNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListAuthorizationRulesComplete enumerates all values, automatically crossing page boundaries as required. +func (client NamespacesClient) ListAuthorizationRulesComplete(ctx context.Context, resourceGroupName string, namespaceName string) (result SharedAccessAuthorizationRuleListResultIterator, err error) { + result.page, err = client.ListAuthorizationRules(ctx, resourceGroupName, namespaceName) + return +} + +// ListKeys gets the Primary and Secondary ConnectionStrings to the namespace +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// authorizationRuleName - the connection string of the namespace for the specified authorizationRule. +func (client NamespacesClient) ListKeys(ctx context.Context, resourceGroupName string, namespaceName string, authorizationRuleName string) (result SharedAccessAuthorizationRuleListResult, err error) { + req, err := client.ListKeysPreparer(ctx, resourceGroupName, namespaceName, authorizationRuleName) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "ListKeys", nil, "Failure preparing request") + return + } + + resp, err := client.ListKeysSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "ListKeys", resp, "Failure sending request") + return + } + + result, err = client.ListKeysResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "ListKeys", resp, "Failure responding to request") + } + + return +} + +// ListKeysPreparer prepares the ListKeys request. +func (client NamespacesClient) ListKeysPreparer(ctx context.Context, resourceGroupName string, namespaceName string, authorizationRuleName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationRuleName": autorest.Encode("path", authorizationRuleName), + "namespaceName": autorest.Encode("path", namespaceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/AuthorizationRules/{authorizationRuleName}/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 NamespacesClient) 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 NamespacesClient) ListKeysResponder(resp *http.Response) (result SharedAccessAuthorizationRuleListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Patch patches the existing namespace +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// parameters - parameters supplied to patch a Namespace Resource. +func (client NamespacesClient) Patch(ctx context.Context, resourceGroupName string, namespaceName string, parameters NamespacePatchParameters) (result NamespaceResource, err error) { + req, err := client.PatchPreparer(ctx, resourceGroupName, namespaceName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "Patch", nil, "Failure preparing request") + return + } + + resp, err := client.PatchSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "Patch", resp, "Failure sending request") + return + } + + result, err = client.PatchResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "Patch", resp, "Failure responding to request") + } + + return +} + +// PatchPreparer prepares the Patch request. +func (client NamespacesClient) PatchPreparer(ctx context.Context, resourceGroupName string, namespaceName string, parameters NamespacePatchParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "namespaceName": autorest.Encode("path", namespaceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + 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.NotificationHubs/namespaces/{namespaceName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// PatchSender sends the Patch request. The method will close the +// http.Response Body if it receives an error. +func (client NamespacesClient) PatchSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// PatchResponder handles the response to the Patch request. The method always +// closes the http.Response Body. +func (client NamespacesClient) PatchResponder(resp *http.Response) (result NamespaceResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// RegenerateKeys regenerates the Primary/Secondary Keys to the Namespace Authorization Rule +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// authorizationRuleName - the connection string of the namespace for the specified authorizationRule. +// parameters - parameters supplied to regenerate the Namespace Authorization Rule Key. +func (client NamespacesClient) RegenerateKeys(ctx context.Context, resourceGroupName string, namespaceName string, authorizationRuleName string, parameters PolicykeyResource) (result ResourceListKeys, err error) { + req, err := client.RegenerateKeysPreparer(ctx, resourceGroupName, namespaceName, authorizationRuleName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "RegenerateKeys", nil, "Failure preparing request") + return + } + + resp, err := client.RegenerateKeysSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "RegenerateKeys", resp, "Failure sending request") + return + } + + result, err = client.RegenerateKeysResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.NamespacesClient", "RegenerateKeys", resp, "Failure responding to request") + } + + return +} + +// RegenerateKeysPreparer prepares the RegenerateKeys request. +func (client NamespacesClient) RegenerateKeysPreparer(ctx context.Context, resourceGroupName string, namespaceName string, authorizationRuleName string, parameters PolicykeyResource) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationRuleName": autorest.Encode("path", authorizationRuleName), + "namespaceName": autorest.Encode("path", namespaceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + 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.NotificationHubs/namespaces/{namespaceName}/AuthorizationRules/{authorizationRuleName}/regenerateKeys", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RegenerateKeysSender sends the RegenerateKeys request. The method will close the +// http.Response Body if it receives an error. +func (client NamespacesClient) RegenerateKeysSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// RegenerateKeysResponder handles the response to the RegenerateKeys request. The method always +// closes the http.Response Body. +func (client NamespacesClient) RegenerateKeysResponder(resp *http.Response) (result ResourceListKeys, 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/notificationhubs/mgmt/2017-04-01/notificationhubs/notificationhubs.go b/vendor/github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs/notificationhubs.go new file mode 100644 index 000000000000..29e1e678beb3 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs/notificationhubs.go @@ -0,0 +1,1109 @@ +package notificationhubs + +// 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" +) + +// Client is the azure NotificationHub client +type Client struct { + BaseClient +} + +// NewClient creates an instance of the Client client. +func NewClient(subscriptionID string) Client { + return NewClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewClientWithBaseURI creates an instance of the Client client. +func NewClientWithBaseURI(baseURI string, subscriptionID string) Client { + return Client{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CheckNotificationHubAvailability checks the availability of the given notificationHub in a namespace. +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// parameters - the notificationHub name. +func (client Client) CheckNotificationHubAvailability(ctx context.Context, resourceGroupName string, namespaceName string, parameters CheckAvailabilityParameters) (result CheckAvailabilityResult, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.Name", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("notificationhubs.Client", "CheckNotificationHubAvailability", err.Error()) + } + + req, err := client.CheckNotificationHubAvailabilityPreparer(ctx, resourceGroupName, namespaceName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CheckNotificationHubAvailability", nil, "Failure preparing request") + return + } + + resp, err := client.CheckNotificationHubAvailabilitySender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CheckNotificationHubAvailability", resp, "Failure sending request") + return + } + + result, err = client.CheckNotificationHubAvailabilityResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CheckNotificationHubAvailability", resp, "Failure responding to request") + } + + return +} + +// CheckNotificationHubAvailabilityPreparer prepares the CheckNotificationHubAvailability request. +func (client Client) CheckNotificationHubAvailabilityPreparer(ctx context.Context, resourceGroupName string, namespaceName string, parameters CheckAvailabilityParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "namespaceName": autorest.Encode("path", namespaceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + 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.NotificationHubs/namespaces/{namespaceName}/checkNotificationHubAvailability", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CheckNotificationHubAvailabilitySender sends the CheckNotificationHubAvailability request. The method will close the +// http.Response Body if it receives an error. +func (client Client) CheckNotificationHubAvailabilitySender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// CheckNotificationHubAvailabilityResponder handles the response to the CheckNotificationHubAvailability request. The method always +// closes the http.Response Body. +func (client Client) CheckNotificationHubAvailabilityResponder(resp *http.Response) (result CheckAvailabilityResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// CreateOrUpdate creates/Update a NotificationHub in a namespace. +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// notificationHubName - the notification hub name. +// parameters - parameters supplied to the create/update a NotificationHub Resource. +func (client Client) CreateOrUpdate(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, parameters CreateOrUpdateParameters) (result ResourceType, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.Properties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("notificationhubs.Client", "CreateOrUpdate", err.Error()) + } + + req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, namespaceName, notificationHubName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client Client) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, parameters CreateOrUpdateParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "namespaceName": autorest.Encode("path", namespaceName), + "notificationHubName": autorest.Encode("path", notificationHubName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + 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.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client Client) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client Client) CreateOrUpdateResponder(resp *http.Response) (result ResourceType, 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 +} + +// CreateOrUpdateAuthorizationRule creates/Updates an authorization rule for a NotificationHub +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// notificationHubName - the notification hub name. +// authorizationRuleName - authorization Rule Name. +// parameters - the shared access authorization rule. +func (client Client) CreateOrUpdateAuthorizationRule(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string, parameters SharedAccessAuthorizationRuleCreateOrUpdateParameters) (result SharedAccessAuthorizationRuleResource, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.Properties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("notificationhubs.Client", "CreateOrUpdateAuthorizationRule", err.Error()) + } + + req, err := client.CreateOrUpdateAuthorizationRulePreparer(ctx, resourceGroupName, namespaceName, notificationHubName, authorizationRuleName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CreateOrUpdateAuthorizationRule", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateAuthorizationRuleSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CreateOrUpdateAuthorizationRule", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateAuthorizationRuleResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "CreateOrUpdateAuthorizationRule", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdateAuthorizationRulePreparer prepares the CreateOrUpdateAuthorizationRule request. +func (client Client) CreateOrUpdateAuthorizationRulePreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string, parameters SharedAccessAuthorizationRuleCreateOrUpdateParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationRuleName": autorest.Encode("path", authorizationRuleName), + "namespaceName": autorest.Encode("path", namespaceName), + "notificationHubName": autorest.Encode("path", notificationHubName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + 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.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}/AuthorizationRules/{authorizationRuleName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateAuthorizationRuleSender sends the CreateOrUpdateAuthorizationRule request. The method will close the +// http.Response Body if it receives an error. +func (client Client) CreateOrUpdateAuthorizationRuleSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateAuthorizationRuleResponder handles the response to the CreateOrUpdateAuthorizationRule request. The method always +// closes the http.Response Body. +func (client Client) CreateOrUpdateAuthorizationRuleResponder(resp *http.Response) (result SharedAccessAuthorizationRuleResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// DebugSend test send a push notification +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// notificationHubName - the notification hub name. +// parameters - debug send parameters +func (client Client) DebugSend(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, parameters *interface{}) (result DebugSendResponse, err error) { + req, err := client.DebugSendPreparer(ctx, resourceGroupName, namespaceName, notificationHubName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "DebugSend", nil, "Failure preparing request") + return + } + + resp, err := client.DebugSendSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "DebugSend", resp, "Failure sending request") + return + } + + result, err = client.DebugSendResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "DebugSend", resp, "Failure responding to request") + } + + return +} + +// DebugSendPreparer prepares the DebugSend request. +func (client Client) DebugSendPreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, parameters *interface{}) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "namespaceName": autorest.Encode("path", namespaceName), + "notificationHubName": autorest.Encode("path", notificationHubName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + 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.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}/debugsend", pathParameters), + autorest.WithQueryParameters(queryParameters)) + if parameters != nil { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithJSON(parameters)) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DebugSendSender sends the DebugSend request. The method will close the +// http.Response Body if it receives an error. +func (client Client) DebugSendSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// DebugSendResponder handles the response to the DebugSend request. The method always +// closes the http.Response Body. +func (client Client) DebugSendResponder(resp *http.Response) (result DebugSendResponse, 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 notification hub associated with a namespace. +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// notificationHubName - the notification hub name. +func (client Client) Delete(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (result autorest.Response, err error) { + req, err := client.DeletePreparer(ctx, resourceGroupName, namespaceName, notificationHubName) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client Client) DeletePreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "namespaceName": autorest.Encode("path", namespaceName), + "notificationHubName": autorest.Encode("path", notificationHubName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}", 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 Client) 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 Client) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.Response = resp + return +} + +// DeleteAuthorizationRule deletes a notificationHub authorization rule +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// notificationHubName - the notification hub name. +// authorizationRuleName - authorization Rule Name. +func (client Client) DeleteAuthorizationRule(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string) (result autorest.Response, err error) { + req, err := client.DeleteAuthorizationRulePreparer(ctx, resourceGroupName, namespaceName, notificationHubName, authorizationRuleName) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "DeleteAuthorizationRule", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteAuthorizationRuleSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "DeleteAuthorizationRule", resp, "Failure sending request") + return + } + + result, err = client.DeleteAuthorizationRuleResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "DeleteAuthorizationRule", resp, "Failure responding to request") + } + + return +} + +// DeleteAuthorizationRulePreparer prepares the DeleteAuthorizationRule request. +func (client Client) DeleteAuthorizationRulePreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationRuleName": autorest.Encode("path", authorizationRuleName), + "namespaceName": autorest.Encode("path", namespaceName), + "notificationHubName": autorest.Encode("path", notificationHubName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}/AuthorizationRules/{authorizationRuleName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteAuthorizationRuleSender sends the DeleteAuthorizationRule request. The method will close the +// http.Response Body if it receives an error. +func (client Client) DeleteAuthorizationRuleSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteAuthorizationRuleResponder handles the response to the DeleteAuthorizationRule request. The method always +// closes the http.Response Body. +func (client Client) DeleteAuthorizationRuleResponder(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 +} + +// Get lists the notification hubs associated with a namespace. +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// notificationHubName - the notification hub name. +func (client Client) Get(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (result ResourceType, err error) { + req, err := client.GetPreparer(ctx, resourceGroupName, namespaceName, notificationHubName) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client Client) GetPreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "namespaceName": autorest.Encode("path", namespaceName), + "notificationHubName": autorest.Encode("path", notificationHubName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client Client) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client Client) GetResponder(resp *http.Response) (result ResourceType, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetAuthorizationRule gets an authorization rule for a NotificationHub by name. +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name +// notificationHubName - the notification hub name. +// authorizationRuleName - authorization rule name. +func (client Client) GetAuthorizationRule(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string) (result SharedAccessAuthorizationRuleResource, err error) { + req, err := client.GetAuthorizationRulePreparer(ctx, resourceGroupName, namespaceName, notificationHubName, authorizationRuleName) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "GetAuthorizationRule", nil, "Failure preparing request") + return + } + + resp, err := client.GetAuthorizationRuleSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "GetAuthorizationRule", resp, "Failure sending request") + return + } + + result, err = client.GetAuthorizationRuleResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "GetAuthorizationRule", resp, "Failure responding to request") + } + + return +} + +// GetAuthorizationRulePreparer prepares the GetAuthorizationRule request. +func (client Client) GetAuthorizationRulePreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationRuleName": autorest.Encode("path", authorizationRuleName), + "namespaceName": autorest.Encode("path", namespaceName), + "notificationHubName": autorest.Encode("path", notificationHubName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}/AuthorizationRules/{authorizationRuleName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetAuthorizationRuleSender sends the GetAuthorizationRule request. The method will close the +// http.Response Body if it receives an error. +func (client Client) GetAuthorizationRuleSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// GetAuthorizationRuleResponder handles the response to the GetAuthorizationRule request. The method always +// closes the http.Response Body. +func (client Client) GetAuthorizationRuleResponder(resp *http.Response) (result SharedAccessAuthorizationRuleResource, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetPnsCredentials lists the PNS Credentials associated with a notification hub . +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// notificationHubName - the notification hub name. +func (client Client) GetPnsCredentials(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (result PnsCredentialsResource, err error) { + req, err := client.GetPnsCredentialsPreparer(ctx, resourceGroupName, namespaceName, notificationHubName) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "GetPnsCredentials", nil, "Failure preparing request") + return + } + + resp, err := client.GetPnsCredentialsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "GetPnsCredentials", resp, "Failure sending request") + return + } + + result, err = client.GetPnsCredentialsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "GetPnsCredentials", resp, "Failure responding to request") + } + + return +} + +// GetPnsCredentialsPreparer prepares the GetPnsCredentials request. +func (client Client) GetPnsCredentialsPreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "namespaceName": autorest.Encode("path", namespaceName), + "notificationHubName": autorest.Encode("path", notificationHubName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}/pnsCredentials", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetPnsCredentialsSender sends the GetPnsCredentials request. The method will close the +// http.Response Body if it receives an error. +func (client Client) GetPnsCredentialsSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// GetPnsCredentialsResponder handles the response to the GetPnsCredentials request. The method always +// closes the http.Response Body. +func (client Client) GetPnsCredentialsResponder(resp *http.Response) (result PnsCredentialsResource, 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 lists the notification hubs associated with a namespace. +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +func (client Client) List(ctx context.Context, resourceGroupName string, namespaceName string) (result ListResultPage, err error) { + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, resourceGroupName, namespaceName) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.lr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "List", resp, "Failure sending request") + return + } + + result.lr, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client Client) ListPreparer(ctx context.Context, resourceGroupName string, namespaceName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "namespaceName": autorest.Encode("path", namespaceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs", 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 Client) 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 Client) ListResponder(resp *http.Response) (result ListResult, 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 Client) listNextResults(lastResults ListResult) (result ListResult, err error) { + req, err := lastResults.listResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "notificationhubs.Client", "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, "notificationhubs.Client", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client Client) ListComplete(ctx context.Context, resourceGroupName string, namespaceName string) (result ListResultIterator, err error) { + result.page, err = client.List(ctx, resourceGroupName, namespaceName) + return +} + +// ListAuthorizationRules gets the authorization rules for a NotificationHub. +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name +// notificationHubName - the notification hub name. +func (client Client) ListAuthorizationRules(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (result SharedAccessAuthorizationRuleListResultPage, err error) { + result.fn = client.listAuthorizationRulesNextResults + req, err := client.ListAuthorizationRulesPreparer(ctx, resourceGroupName, namespaceName, notificationHubName) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "ListAuthorizationRules", nil, "Failure preparing request") + return + } + + resp, err := client.ListAuthorizationRulesSender(req) + if err != nil { + result.saarlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "ListAuthorizationRules", resp, "Failure sending request") + return + } + + result.saarlr, err = client.ListAuthorizationRulesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "ListAuthorizationRules", resp, "Failure responding to request") + } + + return +} + +// ListAuthorizationRulesPreparer prepares the ListAuthorizationRules request. +func (client Client) ListAuthorizationRulesPreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "namespaceName": autorest.Encode("path", namespaceName), + "notificationHubName": autorest.Encode("path", notificationHubName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}/AuthorizationRules", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListAuthorizationRulesSender sends the ListAuthorizationRules request. The method will close the +// http.Response Body if it receives an error. +func (client Client) ListAuthorizationRulesSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListAuthorizationRulesResponder handles the response to the ListAuthorizationRules request. The method always +// closes the http.Response Body. +func (client Client) ListAuthorizationRulesResponder(resp *http.Response) (result SharedAccessAuthorizationRuleListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listAuthorizationRulesNextResults retrieves the next set of results, if any. +func (client Client) listAuthorizationRulesNextResults(lastResults SharedAccessAuthorizationRuleListResult) (result SharedAccessAuthorizationRuleListResult, err error) { + req, err := lastResults.sharedAccessAuthorizationRuleListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "notificationhubs.Client", "listAuthorizationRulesNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListAuthorizationRulesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "notificationhubs.Client", "listAuthorizationRulesNextResults", resp, "Failure sending next results request") + } + result, err = client.ListAuthorizationRulesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "listAuthorizationRulesNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListAuthorizationRulesComplete enumerates all values, automatically crossing page boundaries as required. +func (client Client) ListAuthorizationRulesComplete(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string) (result SharedAccessAuthorizationRuleListResultIterator, err error) { + result.page, err = client.ListAuthorizationRules(ctx, resourceGroupName, namespaceName, notificationHubName) + return +} + +// ListKeys gets the Primary and Secondary ConnectionStrings to the NotificationHub +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// notificationHubName - the notification hub name. +// authorizationRuleName - the connection string of the NotificationHub for the specified authorizationRule. +func (client Client) ListKeys(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string) (result ResourceListKeys, err error) { + req, err := client.ListKeysPreparer(ctx, resourceGroupName, namespaceName, notificationHubName, authorizationRuleName) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "ListKeys", nil, "Failure preparing request") + return + } + + resp, err := client.ListKeysSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "ListKeys", resp, "Failure sending request") + return + } + + result, err = client.ListKeysResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "ListKeys", resp, "Failure responding to request") + } + + return +} + +// ListKeysPreparer prepares the ListKeys request. +func (client Client) ListKeysPreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationRuleName": autorest.Encode("path", authorizationRuleName), + "namespaceName": autorest.Encode("path", namespaceName), + "notificationHubName": autorest.Encode("path", notificationHubName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}/AuthorizationRules/{authorizationRuleName}/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 Client) 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 Client) ListKeysResponder(resp *http.Response) (result ResourceListKeys, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Patch patch a NotificationHub in a namespace. +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// notificationHubName - the notification hub name. +// parameters - parameters supplied to patch a NotificationHub Resource. +func (client Client) Patch(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, parameters *PatchParameters) (result ResourceType, err error) { + req, err := client.PatchPreparer(ctx, resourceGroupName, namespaceName, notificationHubName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Patch", nil, "Failure preparing request") + return + } + + resp, err := client.PatchSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Patch", resp, "Failure sending request") + return + } + + result, err = client.PatchResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "Patch", resp, "Failure responding to request") + } + + return +} + +// PatchPreparer prepares the Patch request. +func (client Client) PatchPreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, parameters *PatchParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "namespaceName": autorest.Encode("path", namespaceName), + "notificationHubName": autorest.Encode("path", notificationHubName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + 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.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + if parameters != nil { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithJSON(parameters)) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// PatchSender sends the Patch request. The method will close the +// http.Response Body if it receives an error. +func (client Client) PatchSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// PatchResponder handles the response to the Patch request. The method always +// closes the http.Response Body. +func (client Client) PatchResponder(resp *http.Response) (result ResourceType, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// RegenerateKeys regenerates the Primary/Secondary Keys to the NotificationHub Authorization Rule +// Parameters: +// resourceGroupName - the name of the resource group. +// namespaceName - the namespace name. +// notificationHubName - the notification hub name. +// authorizationRuleName - the connection string of the NotificationHub for the specified authorizationRule. +// parameters - parameters supplied to regenerate the NotificationHub Authorization Rule Key. +func (client Client) RegenerateKeys(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string, parameters PolicykeyResource) (result ResourceListKeys, err error) { + req, err := client.RegenerateKeysPreparer(ctx, resourceGroupName, namespaceName, notificationHubName, authorizationRuleName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "RegenerateKeys", nil, "Failure preparing request") + return + } + + resp, err := client.RegenerateKeysSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "RegenerateKeys", resp, "Failure sending request") + return + } + + result, err = client.RegenerateKeysResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.Client", "RegenerateKeys", resp, "Failure responding to request") + } + + return +} + +// RegenerateKeysPreparer prepares the RegenerateKeys request. +func (client Client) RegenerateKeysPreparer(ctx context.Context, resourceGroupName string, namespaceName string, notificationHubName string, authorizationRuleName string, parameters PolicykeyResource) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationRuleName": autorest.Encode("path", authorizationRuleName), + "namespaceName": autorest.Encode("path", namespaceName), + "notificationHubName": autorest.Encode("path", notificationHubName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-04-01" + 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.NotificationHubs/namespaces/{namespaceName}/notificationHubs/{notificationHubName}/AuthorizationRules/{authorizationRuleName}/regenerateKeys", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RegenerateKeysSender sends the RegenerateKeys request. The method will close the +// http.Response Body if it receives an error. +func (client Client) RegenerateKeysSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// RegenerateKeysResponder handles the response to the RegenerateKeys request. The method always +// closes the http.Response Body. +func (client Client) RegenerateKeysResponder(resp *http.Response) (result ResourceListKeys, 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/notificationhubs/mgmt/2017-04-01/notificationhubs/operations.go b/vendor/github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs/operations.go new file mode 100644 index 000000000000..259076cc3409 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs/operations.go @@ -0,0 +1,126 @@ +package notificationhubs + +// 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 azure NotificationHub 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 of the available NotificationHubs REST API operations. +func (client OperationsClient) List(ctx context.Context) (result OperationListResultPage, err error) { + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.OperationsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.olr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "notificationhubs.OperationsClient", "List", resp, "Failure sending request") + return + } + + result.olr, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.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-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/Microsoft.NotificationHubs/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 OperationListResult, 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 OperationListResult) (result OperationListResult, err error) { + req, err := lastResults.operationListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "notificationhubs.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, "notificationhubs.OperationsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "notificationhubs.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 OperationListResultIterator, err error) { + result.page, err = client.List(ctx) + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs/version.go b/vendor/github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs/version.go new file mode 100644 index 000000000000..ffc3623204c0 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs/version.go @@ -0,0 +1,30 @@ +package notificationhubs + +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 + " notificationhubs/2017-04-01" +} + +// 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 d039934f1ea0..28946871a685 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -154,6 +154,14 @@ "version": "=v18.0.0", "versionExact": "v18.0.0" }, + { + "checksumSHA1": "gKWc9f9h+qlpzYqyoG3CZR+7q/U=", + "path": "github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs", + "revision": "fbe7db0e3f9793ba3e5704efbab84f51436c136e", + "revisionTime": "2018-07-03T19:15:42Z", + "version": "=v18.0.0", + "versionExact": "v18.0.0" + }, { "checksumSHA1": "8LqtzWEGPooyQjmmalXjJvdRGvE=", "path": "github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql", diff --git a/website/azurerm.erb b/website/azurerm.erb index 79136d1caebd..313b5d32abc2 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -59,7 +59,6 @@ azurerm_cosmosdb_account -