remove deprecated function

This commit is contained in:
Elbaz 2023-08-27 12:21:19 +03:00
parent 77c668de0c
commit 7563a92e1e
5 changed files with 8 additions and 23 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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)