Merge pull request #4533 from hashicorp/f-azurerm-user-agent

provider/azurerm: Set user agent
This commit is contained in:
James Nugent 2016-01-06 14:40:56 -08:00
commit f995651573
1 changed files with 38 additions and 1 deletions

View File

@ -1,16 +1,18 @@
package azurerm package azurerm
import ( import (
"fmt"
"log" "log"
"net/http" "net/http"
"github.com/Azure/azure-sdk-for-go/Godeps/_workspace/src/github.com/Azure/go-autorest/autorest"
"github.com/Azure/azure-sdk-for-go/Godeps/_workspace/src/github.com/Azure/go-autorest/autorest/azure" "github.com/Azure/azure-sdk-for-go/Godeps/_workspace/src/github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/Azure/azure-sdk-for-go/arm/compute"
"github.com/Azure/azure-sdk-for-go/arm/network" "github.com/Azure/azure-sdk-for-go/arm/network"
"github.com/Azure/azure-sdk-for-go/arm/resources" "github.com/Azure/azure-sdk-for-go/arm/resources"
"github.com/Azure/azure-sdk-for-go/arm/scheduler" "github.com/Azure/azure-sdk-for-go/arm/scheduler"
"github.com/Azure/azure-sdk-for-go/arm/storage" "github.com/Azure/azure-sdk-for-go/arm/storage"
"github.com/Azure/go-autorest/autorest" "github.com/hashicorp/terraform/terraform"
) )
// ArmClient contains the handles to all the specific Azure Resource Manager // ArmClient contains the handles to all the specific Azure Resource Manager
@ -58,6 +60,17 @@ func withRequestLogging() autorest.SendDecorator {
} }
} }
func setUserAgent(client *autorest.Client) {
var version string
if terraform.VersionPrerelease != "" {
version = fmt.Sprintf("%s-%s", terraform.Version, terraform.VersionPrerelease)
} else {
version = terraform.Version
}
client.UserAgent = fmt.Sprintf("HashiCorp-Terraform-v%s", version)
}
// getArmClient is a helper method which returns a fully instantiated // getArmClient is a helper method which returns a fully instantiated
// *ArmClient based on the Config's current settings. // *ArmClient based on the Config's current settings.
func (c *Config) getArmClient() (*ArmClient, error) { func (c *Config) getArmClient() (*ArmClient, error) {
@ -72,121 +85,145 @@ func (c *Config) getArmClient() (*ArmClient, error) {
// NOTE: these declarations should be left separate for clarity should the // NOTE: these declarations should be left separate for clarity should the
// clients be wished to be configured with custom Responders/PollingModess etc... // clients be wished to be configured with custom Responders/PollingModess etc...
asc := compute.NewAvailabilitySetsClient(c.SubscriptionID) asc := compute.NewAvailabilitySetsClient(c.SubscriptionID)
setUserAgent(&asc.Client)
asc.Authorizer = spt asc.Authorizer = spt
asc.Sender = autorest.CreateSender(withRequestLogging()) asc.Sender = autorest.CreateSender(withRequestLogging())
client.availSetClient = asc client.availSetClient = asc
uoc := compute.NewUsageOperationsClient(c.SubscriptionID) uoc := compute.NewUsageOperationsClient(c.SubscriptionID)
setUserAgent(&uoc.Client)
uoc.Authorizer = spt uoc.Authorizer = spt
uoc.Sender = autorest.CreateSender(withRequestLogging()) uoc.Sender = autorest.CreateSender(withRequestLogging())
client.usageOpsClient = uoc client.usageOpsClient = uoc
vmeic := compute.NewVirtualMachineExtensionImagesClient(c.SubscriptionID) vmeic := compute.NewVirtualMachineExtensionImagesClient(c.SubscriptionID)
setUserAgent(&vmeic.Client)
vmeic.Authorizer = spt vmeic.Authorizer = spt
vmeic.Sender = autorest.CreateSender(withRequestLogging()) vmeic.Sender = autorest.CreateSender(withRequestLogging())
client.vmExtensionImageClient = vmeic client.vmExtensionImageClient = vmeic
vmec := compute.NewVirtualMachineExtensionsClient(c.SubscriptionID) vmec := compute.NewVirtualMachineExtensionsClient(c.SubscriptionID)
setUserAgent(&vmec.Client)
vmec.Authorizer = spt vmec.Authorizer = spt
vmec.Sender = autorest.CreateSender(withRequestLogging()) vmec.Sender = autorest.CreateSender(withRequestLogging())
client.vmExtensionClient = vmec client.vmExtensionClient = vmec
vmic := compute.NewVirtualMachineImagesClient(c.SubscriptionID) vmic := compute.NewVirtualMachineImagesClient(c.SubscriptionID)
setUserAgent(&vmic.Client)
vmic.Authorizer = spt vmic.Authorizer = spt
vmic.Sender = autorest.CreateSender(withRequestLogging()) vmic.Sender = autorest.CreateSender(withRequestLogging())
client.vmImageClient = vmic client.vmImageClient = vmic
vmc := compute.NewVirtualMachinesClient(c.SubscriptionID) vmc := compute.NewVirtualMachinesClient(c.SubscriptionID)
setUserAgent(&vmc.Client)
vmc.Authorizer = spt vmc.Authorizer = spt
vmc.Sender = autorest.CreateSender(withRequestLogging()) vmc.Sender = autorest.CreateSender(withRequestLogging())
client.vmClient = vmc client.vmClient = vmc
agc := network.NewApplicationGatewaysClient(c.SubscriptionID) agc := network.NewApplicationGatewaysClient(c.SubscriptionID)
setUserAgent(&agc.Client)
agc.Authorizer = spt agc.Authorizer = spt
agc.Sender = autorest.CreateSender(withRequestLogging()) agc.Sender = autorest.CreateSender(withRequestLogging())
client.appGatewayClient = agc client.appGatewayClient = agc
ifc := network.NewInterfacesClient(c.SubscriptionID) ifc := network.NewInterfacesClient(c.SubscriptionID)
setUserAgent(&ifc.Client)
ifc.Authorizer = spt ifc.Authorizer = spt
ifc.Sender = autorest.CreateSender(withRequestLogging()) ifc.Sender = autorest.CreateSender(withRequestLogging())
client.ifaceClient = ifc client.ifaceClient = ifc
lbc := network.NewLoadBalancersClient(c.SubscriptionID) lbc := network.NewLoadBalancersClient(c.SubscriptionID)
setUserAgent(&lbc.Client)
lbc.Authorizer = spt lbc.Authorizer = spt
lbc.Sender = autorest.CreateSender(withRequestLogging()) lbc.Sender = autorest.CreateSender(withRequestLogging())
client.loadBalancerClient = lbc client.loadBalancerClient = lbc
lgc := network.NewLocalNetworkGatewaysClient(c.SubscriptionID) lgc := network.NewLocalNetworkGatewaysClient(c.SubscriptionID)
setUserAgent(&lgc.Client)
lgc.Authorizer = spt lgc.Authorizer = spt
lgc.Sender = autorest.CreateSender(withRequestLogging()) lgc.Sender = autorest.CreateSender(withRequestLogging())
client.localNetConnClient = lgc client.localNetConnClient = lgc
pipc := network.NewPublicIPAddressesClient(c.SubscriptionID) pipc := network.NewPublicIPAddressesClient(c.SubscriptionID)
setUserAgent(&pipc.Client)
pipc.Authorizer = spt pipc.Authorizer = spt
pipc.Sender = autorest.CreateSender(withRequestLogging()) pipc.Sender = autorest.CreateSender(withRequestLogging())
client.publicIPClient = pipc client.publicIPClient = pipc
sgc := network.NewSecurityGroupsClient(c.SubscriptionID) sgc := network.NewSecurityGroupsClient(c.SubscriptionID)
setUserAgent(&sgc.Client)
sgc.Authorizer = spt sgc.Authorizer = spt
sgc.Sender = autorest.CreateSender(withRequestLogging()) sgc.Sender = autorest.CreateSender(withRequestLogging())
client.secGroupClient = sgc client.secGroupClient = sgc
src := network.NewSecurityRulesClient(c.SubscriptionID) src := network.NewSecurityRulesClient(c.SubscriptionID)
setUserAgent(&src.Client)
src.Authorizer = spt src.Authorizer = spt
src.Sender = autorest.CreateSender(withRequestLogging()) src.Sender = autorest.CreateSender(withRequestLogging())
client.secRuleClient = src client.secRuleClient = src
snc := network.NewSubnetsClient(c.SubscriptionID) snc := network.NewSubnetsClient(c.SubscriptionID)
setUserAgent(&snc.Client)
snc.Authorizer = spt snc.Authorizer = spt
snc.Sender = autorest.CreateSender(withRequestLogging()) snc.Sender = autorest.CreateSender(withRequestLogging())
client.subnetClient = snc client.subnetClient = snc
vgcc := network.NewVirtualNetworkGatewayConnectionsClient(c.SubscriptionID) vgcc := network.NewVirtualNetworkGatewayConnectionsClient(c.SubscriptionID)
setUserAgent(&vgcc.Client)
vgcc.Authorizer = spt vgcc.Authorizer = spt
vgcc.Sender = autorest.CreateSender(withRequestLogging()) vgcc.Sender = autorest.CreateSender(withRequestLogging())
client.vnetGatewayConnectionsClient = vgcc client.vnetGatewayConnectionsClient = vgcc
vgc := network.NewVirtualNetworkGatewaysClient(c.SubscriptionID) vgc := network.NewVirtualNetworkGatewaysClient(c.SubscriptionID)
setUserAgent(&vgc.Client)
vgc.Authorizer = spt vgc.Authorizer = spt
vgc.Sender = autorest.CreateSender(withRequestLogging()) vgc.Sender = autorest.CreateSender(withRequestLogging())
client.vnetGatewayClient = vgc client.vnetGatewayClient = vgc
vnc := network.NewVirtualNetworksClient(c.SubscriptionID) vnc := network.NewVirtualNetworksClient(c.SubscriptionID)
setUserAgent(&vnc.Client)
vnc.Authorizer = spt vnc.Authorizer = spt
vnc.Sender = autorest.CreateSender(withRequestLogging()) vnc.Sender = autorest.CreateSender(withRequestLogging())
client.vnetClient = vnc client.vnetClient = vnc
rgc := resources.NewGroupsClient(c.SubscriptionID) rgc := resources.NewGroupsClient(c.SubscriptionID)
setUserAgent(&rgc.Client)
rgc.Authorizer = spt rgc.Authorizer = spt
rgc.Sender = autorest.CreateSender(withRequestLogging()) rgc.Sender = autorest.CreateSender(withRequestLogging())
client.resourceGroupClient = rgc client.resourceGroupClient = rgc
pc := resources.NewProvidersClient(c.SubscriptionID) pc := resources.NewProvidersClient(c.SubscriptionID)
setUserAgent(&pc.Client)
pc.Authorizer = spt pc.Authorizer = spt
pc.Sender = autorest.CreateSender(withRequestLogging()) pc.Sender = autorest.CreateSender(withRequestLogging())
client.providers = pc client.providers = pc
tc := resources.NewTagsClient(c.SubscriptionID) tc := resources.NewTagsClient(c.SubscriptionID)
setUserAgent(&tc.Client)
tc.Authorizer = spt tc.Authorizer = spt
tc.Sender = autorest.CreateSender(withRequestLogging()) tc.Sender = autorest.CreateSender(withRequestLogging())
client.tagsClient = tc client.tagsClient = tc
jc := scheduler.NewJobsClient(c.SubscriptionID) jc := scheduler.NewJobsClient(c.SubscriptionID)
setUserAgent(&jc.Client)
jc.Authorizer = spt jc.Authorizer = spt
jc.Sender = autorest.CreateSender(withRequestLogging()) jc.Sender = autorest.CreateSender(withRequestLogging())
client.jobsClient = jc client.jobsClient = jc
jcc := scheduler.NewJobCollectionsClient(c.SubscriptionID) jcc := scheduler.NewJobCollectionsClient(c.SubscriptionID)
setUserAgent(&jcc.Client)
jcc.Authorizer = spt jcc.Authorizer = spt
jcc.Sender = autorest.CreateSender(withRequestLogging()) jcc.Sender = autorest.CreateSender(withRequestLogging())
client.jobsCollectionsClient = jcc client.jobsCollectionsClient = jcc
ssc := storage.NewAccountsClient(c.SubscriptionID) ssc := storage.NewAccountsClient(c.SubscriptionID)
setUserAgent(&ssc.Client)
ssc.Authorizer = spt ssc.Authorizer = spt
ssc.Sender = autorest.CreateSender(withRequestLogging()) ssc.Sender = autorest.CreateSender(withRequestLogging())
client.storageServiceClient = ssc client.storageServiceClient = ssc
suc := storage.NewUsageOperationsClient(c.SubscriptionID) suc := storage.NewUsageOperationsClient(c.SubscriptionID)
setUserAgent(&suc.Client)
suc.Authorizer = spt suc.Authorizer = spt
suc.Sender = autorest.CreateSender(withRequestLogging()) suc.Sender = autorest.CreateSender(withRequestLogging())
client.storageUsageClient = suc client.storageUsageClient = suc