diff --git a/internal/backend/remote-state/gcs/backend.go b/internal/backend/remote-state/gcs/backend.go index b6523a65aa..727b52a8ec 100644 --- a/internal/backend/remote-state/gcs/backend.go +++ b/internal/backend/remote-state/gcs/backend.go @@ -9,6 +9,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "github.com/placeholderplaceholderplaceholder/opentf/version" "os" "strings" @@ -207,7 +208,7 @@ func (b *Backend) configure(ctx context.Context) error { opts = append(opts, credOptions...) } - opts = append(opts, option.WithUserAgent(httpclient.UserAgentString())) + opts = append(opts, option.WithUserAgent(httpclient.TerraformUserAgent(version.Version))) // Custom endpoint for storage API if storageEndpoint, ok := data.GetOk("storage_custom_endpoint"); ok { diff --git a/internal/backend/remote-state/gcs/backend_test.go b/internal/backend/remote-state/gcs/backend_test.go index 75a9686e0d..483b5af3c2 100644 --- a/internal/backend/remote-state/gcs/backend_test.go +++ b/internal/backend/remote-state/gcs/backend_test.go @@ -7,6 +7,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/placeholderplaceholderplaceholder/opentf/version" "log" "os" "strings" @@ -438,7 +439,7 @@ func testGetClientOptions(t *testing.T) ([]option.ClientOption, error) { } credOptions = append(credOptions, option.WithCredentialsJSON([]byte(contents))) opts = append(opts, credOptions...) - opts = append(opts, option.WithUserAgent(httpclient.UserAgentString())) + opts = append(opts, option.WithUserAgent(httpclient.TerraformUserAgent(version.Version))) return opts, nil } diff --git a/internal/httpclient/client.go b/internal/httpclient/client.go index 60a6551e14..0237caff32 100644 --- a/internal/httpclient/client.go +++ b/internal/httpclient/client.go @@ -4,6 +4,7 @@ package httpclient import ( + "github.com/placeholderplaceholderplaceholder/opentf/version" "net/http" cleanhttp "github.com/hashicorp/go-cleanhttp" @@ -14,7 +15,7 @@ import ( func New() *http.Client { cli := cleanhttp.DefaultPooledClient() cli.Transport = &userAgentRoundTripper{ - userAgent: UserAgentString(), + userAgent: TerraformUserAgent(version.Version), inner: cli.Transport, } return cli diff --git a/internal/httpclient/useragent.go b/internal/httpclient/useragent.go index 604c10ee9f..dd811ddccb 100644 --- a/internal/httpclient/useragent.go +++ b/internal/httpclient/useragent.go @@ -9,29 +9,11 @@ import ( "net/http" "os" "strings" - - "github.com/placeholderplaceholderplaceholder/opentf/version" ) -const userAgentFormat = "OpenTF/%s" const uaEnvVar = "TF_APPEND_USER_AGENT" const TerraformUA = "placeholderplaceholderplaceholder-OpenTF" -// Deprecated: Use TerraformUserAgent(version) instead -func UserAgentString() string { - ua := fmt.Sprintf(userAgentFormat, version.Version) - - if add := os.Getenv(uaEnvVar); add != "" { - add = strings.TrimSpace(add) - if len(add) > 0 { - ua += " " + add - log.Printf("[DEBUG] Using modified User-Agent: %s", ua) - } - } - - return ua -} - type userAgentRoundTripper struct { inner http.RoundTripper userAgent string diff --git a/internal/httpclient/useragent_test.go b/internal/httpclient/useragent_test.go index 11ff64d413..ac0d5f9b7c 100644 --- a/internal/httpclient/useragent_test.go +++ b/internal/httpclient/useragent_test.go @@ -12,7 +12,7 @@ import ( ) func TestUserAgentString_env(t *testing.T) { - expectedBase := fmt.Sprintf(userAgentFormat, version.Version) + expectedBase := fmt.Sprintf("%s/%s (+https://www.opentf.org)", TerraformUA, version.Version) if oldenv, isSet := os.LookupEnv(uaEnvVar); isSet { defer os.Setenv(uaEnvVar, oldenv) } else { @@ -39,7 +39,7 @@ func TestUserAgentString_env(t *testing.T) { os.Setenv(uaEnvVar, c.additional) } - actual := UserAgentString() + actual := TerraformUserAgent(version.Version) if c.expected != actual { t.Fatalf("Expected User-Agent '%s' does not match '%s'", c.expected, actual)