Skip to content

Commit

Permalink
Authentication: registering all clients consistently (hashicorp#1845)
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff authored Aug 30, 2018
1 parent f6e825c commit 346fa81
Showing 1 changed file with 25 additions and 99 deletions.
124 changes: 25 additions & 99 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,70 +444,43 @@ func getArmClient(c *authentication.Config) (*ArmClient, error) {

func (c *ArmClient) registerAppInsightsClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
ai := appinsights.NewComponentsClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&ai.Client)
ai.Authorizer = auth
ai.Sender = sender
ai.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&ai.Client, auth)
c.appInsightsClient = ai
}

func (c *ArmClient) registerAutomationClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
accountClient := automation.NewAccountClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&accountClient.Client)
accountClient.Authorizer = auth
accountClient.Sender = sender
accountClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&accountClient.Client, auth)
c.automationAccountClient = accountClient

credentialClient := automation.NewCredentialClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&credentialClient.Client)
credentialClient.Authorizer = auth
credentialClient.Sender = sender
credentialClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&credentialClient.Client, auth)
c.automationCredentialClient = credentialClient

runbookClient := automation.NewRunbookClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&runbookClient.Client)
runbookClient.Authorizer = auth
runbookClient.Sender = sender
runbookClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&runbookClient.Client, auth)
c.automationRunbookClient = runbookClient

scheduleClient := automation.NewScheduleClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&scheduleClient.Client)
scheduleClient.Authorizer = auth
scheduleClient.Sender = sender
scheduleClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&scheduleClient.Client, auth)
c.automationScheduleClient = scheduleClient
}

func (c *ArmClient) registerAuthentication(endpoint, graphEndpoint, subscriptionId, tenantId string, auth, graphAuth autorest.Authorizer, sender autorest.Sender) {
assignmentsClient := authorization.NewRoleAssignmentsClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&assignmentsClient.Client)
assignmentsClient.Authorizer = auth
assignmentsClient.Sender = sender
assignmentsClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&assignmentsClient.Client, auth)
c.roleAssignmentsClient = assignmentsClient

definitionsClient := authorization.NewRoleDefinitionsClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&definitionsClient.Client)
definitionsClient.Authorizer = auth
definitionsClient.Sender = sender
definitionsClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&definitionsClient.Client, auth)
c.roleDefinitionsClient = definitionsClient

applicationsClient := graphrbac.NewApplicationsClientWithBaseURI(graphEndpoint, tenantId)
setUserAgent(&applicationsClient.Client)
applicationsClient.Authorizer = graphAuth
applicationsClient.Sender = sender
applicationsClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&applicationsClient.Client, graphAuth)
c.applicationsClient = applicationsClient

servicePrincipalsClient := graphrbac.NewServicePrincipalsClientWithBaseURI(graphEndpoint, tenantId)
setUserAgent(&servicePrincipalsClient.Client)
servicePrincipalsClient.Authorizer = graphAuth
servicePrincipalsClient.Sender = sender
servicePrincipalsClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&servicePrincipalsClient.Client, graphAuth)
c.servicePrincipalsClient = servicePrincipalsClient
}

Expand Down Expand Up @@ -600,31 +573,19 @@ func (c *ArmClient) registerContainerServicesClients(endpoint, subscriptionId st
func (c *ArmClient) registerDatabases(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
// MySQL
mysqlConfigClient := mysql.NewConfigurationsClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&mysqlConfigClient.Client)
mysqlConfigClient.Authorizer = auth
mysqlConfigClient.Sender = sender
mysqlConfigClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&mysqlConfigClient.Client, auth)
c.mysqlConfigurationsClient = mysqlConfigClient

mysqlDBClient := mysql.NewDatabasesClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&mysqlDBClient.Client)
mysqlDBClient.Authorizer = auth
mysqlDBClient.Sender = sender
mysqlDBClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&mysqlDBClient.Client, auth)
c.mysqlDatabasesClient = mysqlDBClient

mysqlFWClient := mysql.NewFirewallRulesClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&mysqlFWClient.Client)
mysqlFWClient.Authorizer = auth
mysqlFWClient.Sender = sender
mysqlFWClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&mysqlFWClient.Client, auth)
c.mysqlFirewallRulesClient = mysqlFWClient

mysqlServersClient := mysql.NewServersClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&mysqlServersClient.Client)
mysqlServersClient.Authorizer = auth
mysqlServersClient.Sender = sender
mysqlServersClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&mysqlServersClient.Client, auth)
c.mysqlServersClient = mysqlServersClient

// PostgreSQL
Expand All @@ -646,38 +607,23 @@ func (c *ArmClient) registerDatabases(endpoint, subscriptionId string, auth auto

// SQL Azure
sqlDBClient := sql.NewDatabasesClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&sqlDBClient.Client)
sqlDBClient.Authorizer = auth
sqlDBClient.Sender = sender
sqlDBClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&sqlDBClient.Client, auth)
c.sqlDatabasesClient = sqlDBClient

sqlFWClient := sql.NewFirewallRulesClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&sqlFWClient.Client)
sqlFWClient.Authorizer = auth
sqlFWClient.Sender = sender
sqlFWClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&sqlFWClient.Client, auth)
c.sqlFirewallRulesClient = sqlFWClient

sqlEPClient := sql.NewElasticPoolsClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&sqlEPClient.Client)
sqlEPClient.Authorizer = auth
sqlEPClient.Sender = sender
sqlEPClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&sqlEPClient.Client, auth)
c.sqlElasticPoolsClient = sqlEPClient

sqlSrvClient := sql.NewServersClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&sqlSrvClient.Client)
sqlSrvClient.Authorizer = auth
sqlSrvClient.Sender = sender
sqlSrvClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&sqlSrvClient.Client, auth)
c.sqlServersClient = sqlSrvClient

sqlADClient := sql.NewServerAzureADAdministratorsClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&sqlADClient.Client)
sqlADClient.Authorizer = auth
sqlADClient.Sender = sender
sqlADClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&sqlADClient.Client, auth)
c.sqlServerAzureADAdministratorsClient = sqlADClient

sqlVNRClient := sql.NewVirtualNetworkRulesClientWithBaseURI(endpoint, subscriptionId)
Expand Down Expand Up @@ -725,49 +671,31 @@ func (c *ArmClient) registerDNSClients(endpoint, subscriptionId string, auth aut

func (c *ArmClient) registerEventGridClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
egtc := eventgrid.NewTopicsClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&egtc.Client)
egtc.Authorizer = auth
egtc.Sender = sender
egtc.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&egtc.Client, auth)
c.eventGridTopicsClient = egtc
}

func (c *ArmClient) registerEventHubClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
ehc := eventhub.NewEventHubsClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&ehc.Client)
ehc.Authorizer = auth
ehc.Sender = sender
ehc.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&ehc.Client, auth)
c.eventHubClient = ehc

chcgc := eventhub.NewConsumerGroupsClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&chcgc.Client)
chcgc.Authorizer = auth
chcgc.Sender = sender
chcgc.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&chcgc.Client, auth)
c.eventHubConsumerGroupClient = chcgc

ehnc := eventhub.NewNamespacesClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&ehnc.Client)
ehnc.Authorizer = auth
ehnc.Sender = sender
ehnc.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&ehnc.Client, auth)
c.eventHubNamespacesClient = ehnc
}

func (c *ArmClient) registerKeyVaultClients(endpoint, subscriptionId string, auth autorest.Authorizer, keyVaultAuth autorest.Authorizer, sender autorest.Sender) {
keyVaultClient := keyvault.NewVaultsClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&keyVaultClient.Client)
keyVaultClient.Authorizer = auth
keyVaultClient.Sender = sender
keyVaultClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&keyVaultClient.Client, auth)
c.keyVaultClient = keyVaultClient

keyVaultManagementClient := keyVault.New()
setUserAgent(&keyVaultManagementClient.Client)
keyVaultManagementClient.Authorizer = keyVaultAuth
keyVaultManagementClient.Sender = sender
keyVaultManagementClient.SkipResourceProviderRegistration = c.skipProviderRegistration
c.configureClient(&keyVaultManagementClient.Client, keyVaultAuth)
c.keyVaultManagementClient = keyVaultManagementClient
}

Expand All @@ -783,9 +711,7 @@ func (c *ArmClient) registerMonitorClients(endpoint, subscriptionId string, auth
c.actionGroupsClient = actionGroupsClient

arc := insights.NewAlertRulesClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&arc.Client)
arc.Authorizer = auth
arc.Sender = autorest.CreateSender(withRequestLogging())
c.configureClient(&arc.Client, auth)
c.monitorAlertRulesClient = arc

autoscaleSettingsClient := insights.NewAutoscaleSettingsClientWithBaseURI(endpoint, subscriptionId)
Expand Down

0 comments on commit 346fa81

Please sign in to comment.