Skip to content

Commit

Permalink
add SDK version to useragent header
Browse files Browse the repository at this point in the history
  • Loading branch information
kmoe committed Sep 10, 2019
1 parent 2ae14ce commit 9f40692
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion httpclient/useragent.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"log"
"os"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/meta"
)

const uaEnvVar = "TF_APPEND_USER_AGENT"

func TerraformUserAgent(version string) string {
ua := fmt.Sprintf("HashiCorp Terraform/%s (+https://www.terraform.io)", version)
ua := fmt.Sprintf("HashiCorp Terraform/%s (+https://www.terraform.io) Terraform Plugin SDK/%s", version, meta.SDKVersionString())

if add := os.Getenv(uaEnvVar); add != "" {
add = strings.TrimSpace(add)
Expand Down
4 changes: 3 additions & 1 deletion httpclient/useragent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/meta"
)

func TestUserAgentAppendViaEnvVar(t *testing.T) {
Expand All @@ -13,7 +15,7 @@ func TestUserAgentAppendViaEnvVar(t *testing.T) {
defer os.Unsetenv(uaEnvVar)
}

expectedBase := "HashiCorp Terraform/0.0.0 (+https://www.terraform.io)"
expectedBase := "HashiCorp Terraform/0.0.0 (+https://www.terraform.io) Terraform Plugin SDK/" + meta.SDKVersionString()

testCases := []struct {
envVarValue string
Expand Down

0 comments on commit 9f40692

Please sign in to comment.