From 5fbd7a97d9a006b78c4f88cb3e206bf5e1f92411 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Wed, 1 Nov 2017 19:04:17 -0700 Subject: [PATCH 1/3] Append AZURE_HTTP_USER_AGENT environment variable to UserAgent string. --- azurerm/config.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/azurerm/config.go b/azurerm/config.go index 82a87e867c32..b5d6ec8e38a7 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -6,6 +6,8 @@ import ( "log" "net/http" "net/http/httputil" + "os" + "strings" "github.com/Azure/azure-sdk-for-go/arm/appinsights" "github.com/Azure/azure-sdk-for-go/arm/authorization" @@ -189,7 +191,15 @@ func withRequestLogging() autorest.SendDecorator { func setUserAgent(client *autorest.Client) { version := terraform.VersionString() + azureAgent := os.Getenv("AZURE_HTTP_USER_AGENT") client.UserAgent = fmt.Sprintf("HashiCorp-Terraform-v%s", version) + + if azureAgent != "" { + s := []string{client.UserAgent, azureAgent} + client.UserAgent = strings.Join(s, ";") + } + + log.Printf("[DEBUG] User Agent: %s", client.UserAgent) } func (c *Config) getAuthorizationToken(oauthConfig *adal.OAuthConfig, endpoint string) (*autorest.BearerAuthorizer, error) { From 216681eecd829c995ef7ef1c55b221d29e6845c8 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline Date: Thu, 2 Nov 2017 12:19:26 -0700 Subject: [PATCH 2/3] Updated code per PR. --- azurerm/config.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/azurerm/config.go b/azurerm/config.go index b5d6ec8e38a7..0e11c57a5aea 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -7,7 +7,6 @@ import ( "net/http" "net/http/httputil" "os" - "strings" "github.com/Azure/azure-sdk-for-go/arm/appinsights" "github.com/Azure/azure-sdk-for-go/arm/authorization" @@ -191,12 +190,10 @@ func withRequestLogging() autorest.SendDecorator { func setUserAgent(client *autorest.Client) { version := terraform.VersionString() - azureAgent := os.Getenv("AZURE_HTTP_USER_AGENT") client.UserAgent = fmt.Sprintf("HashiCorp-Terraform-v%s", version) - if azureAgent != "" { - s := []string{client.UserAgent, azureAgent} - client.UserAgent = strings.Join(s, ";") + if azureAgent := os.Getenv("AZURE_HTTP_USER_AGENT"); azureAgent != "" { + client.UserAgent = fmt.Sprintf("%s;%s", client.UserAgent, azureAgent) } log.Printf("[DEBUG] User Agent: %s", client.UserAgent) From 80053f78b0b6f72a62b7674de4aaa14a75e8a1ba Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Sat, 4 Nov 2017 09:01:28 +0000 Subject: [PATCH 3/3] Documenting the cloudshell user agent change --- azurerm/config.go | 1 + 1 file changed, 1 insertion(+) diff --git a/azurerm/config.go b/azurerm/config.go index 0e11c57a5aea..12d33e910a83 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -192,6 +192,7 @@ func setUserAgent(client *autorest.Client) { version := terraform.VersionString() client.UserAgent = fmt.Sprintf("HashiCorp-Terraform-v%s", version) + // append the CloudShell version to the user agent if azureAgent := os.Getenv("AZURE_HTTP_USER_AGENT"); azureAgent != "" { client.UserAgent = fmt.Sprintf("%s;%s", client.UserAgent, azureAgent) }