export more commons

This commit is contained in:
Elbaz 2023-08-27 13:55:04 +03:00
parent 7078034160
commit 7723d93946
4 changed files with 12 additions and 7 deletions

View File

@ -439,7 +439,7 @@ func (b *Backend) getOSSEndpointByRegion(access_key, secret_key, security_token,
return nil, fmt.Errorf("unable to initialize the location client: %#v", err)
}
locationClient.AppendUserAgent(httpclient.TerraformUA, TerraformVersion)
locationClient.AppendUserAgent(httpclient.OpenTFUserAgent, TerraformVersion)
endpointsResponse, err := locationClient.DescribeEndpoints(args)
if err != nil {
return nil, fmt.Errorf("describe oss endpoint using region: %#v got an error: %#v", region, err)

View File

@ -6,6 +6,7 @@ package s3
import (
"encoding/base64"
"fmt"
"github.com/placeholderplaceholderplaceholder/opentf/internal/httpclient"
"os"
"strings"
@ -394,8 +395,8 @@ func (b *Backend) Configure(obj cty.Value) tfdiags.Diagnostics {
Token: stringAttr(obj, "token"),
UserAgentProducts: []*awsbase.UserAgentProduct{
{Name: "APN", Version: "1.0"},
{Name: "placeholderplaceholderplaceholder", Version: "1.0"},
{Name: "OpenTF", Version: version.String()},
{Name: httpclient.OpenTFUserAgent, Version: "1.0"},
{Name: httpclient.Organization, Version: version.String()},
},
}

View File

@ -11,8 +11,12 @@ import (
"strings"
)
const uaEnvVar = "TF_APPEND_USER_AGENT"
const TerraformUA = "placeholderplaceholderplaceholder-OpenTF"
const (
uaEnvVar = "TF_APPEND_USER_AGENT"
Organization = "placeholderplaceholderplaceholder"
Application = "OpenTF"
OpenTFUserAgent = Organization + "-" + Application
)
type userAgentRoundTripper struct {
inner http.RoundTripper
@ -28,7 +32,7 @@ func (rt *userAgentRoundTripper) RoundTrip(req *http.Request) (*http.Response, e
}
func TerraformUserAgent(version string) string {
ua := fmt.Sprintf("%s/%s (+https://www.opentf.org)", TerraformUA, version)
ua := fmt.Sprintf("%s/%s (+https://www.opentf.org)", OpenTFUserAgent, version)
if add := os.Getenv(uaEnvVar); add != "" {
add = strings.TrimSpace(add)

View File

@ -12,7 +12,7 @@ import (
)
func TestUserAgentString_env(t *testing.T) {
expectedBase := fmt.Sprintf("%s/%s (+https://www.opentf.org)", TerraformUA, version.Version)
expectedBase := fmt.Sprintf("%s/%s (+https://www.opentf.org)", OpenTFUserAgent, version.Version)
if oldenv, isSet := os.LookupEnv(uaEnvVar); isSet {
defer os.Setenv(uaEnvVar, oldenv)
} else {