Update user-agent from go-tfe to opentofu where go-tfe is used (#807)

This commit is contained in:
Igor Savchenko 2023-11-02 04:11:13 -07:00 committed by GitHub
parent a1e110c679
commit 572d8d95d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import (
"github.com/mitchellh/colorstring"
"github.com/opentofu/opentofu/internal/backend"
"github.com/opentofu/opentofu/internal/configs/configschema"
"github.com/opentofu/opentofu/internal/httpclient"
"github.com/opentofu/opentofu/internal/logging"
"github.com/opentofu/opentofu/internal/states/remote"
"github.com/opentofu/opentofu/internal/states/statemgr"
@ -334,6 +335,9 @@ func (b *Remote) Configure(ctx context.Context, obj cty.Value) tfdiags.Diagnosti
// Set the version header to the current version.
cfg.Headers.Set(tfversion.Header, tfversion.Version)
// Update user-agent from 'go-tfe' to opentofu
cfg.Headers.Set("User-Agent", httpclient.OpenTofuUserAgent(tfversion.String()))
// Create the remote backend API client.
b.client, err = tfe.NewClient(cfg)
if err != nil {

View File

@ -28,6 +28,7 @@ import (
"github.com/opentofu/opentofu/internal/backend"
"github.com/opentofu/opentofu/internal/command/jsonformat"
"github.com/opentofu/opentofu/internal/configs/configschema"
"github.com/opentofu/opentofu/internal/httpclient"
"github.com/opentofu/opentofu/internal/plans"
"github.com/opentofu/opentofu/internal/states/statemgr"
"github.com/opentofu/opentofu/internal/tfdiags"
@ -307,6 +308,9 @@ func (b *Cloud) Configure(ctx context.Context, obj cty.Value) tfdiags.Diagnostic
cfg.Headers.Set(tfversion.Header, tfversion.Version)
cfg.Headers.Set(headerSourceKey, headerSourceValue)
// Update user-agent from 'go-tfe' to opentofu
cfg.Headers.Set("User-Agent", httpclient.OpenTofuUserAgent(tfversion.String()))
// Create the TFC/E API client.
b.client, err = tfe.NewClient(cfg)
if err != nil {

View File

@ -29,6 +29,7 @@ import (
"github.com/opentofu/opentofu/internal/logging"
"github.com/opentofu/opentofu/internal/tfdiags"
"github.com/opentofu/opentofu/internal/tofu"
"github.com/opentofu/opentofu/version"
uuid "github.com/hashicorp/go-uuid"
"golang.org/x/oauth2"
@ -648,6 +649,10 @@ func (c *LoginCommand) interactiveGetTokenByUI(hostname svchost.Hostname, credsC
Token: token,
Headers: make(http.Header),
}
// Update user-agent from 'go-tfe' to opentofu
cfg.Headers.Set("User-Agent", httpclient.OpenTofuUserAgent(version.String()))
client, err := tfe.NewClient(cfg)
if err != nil {
diags = diags.Append(fmt.Errorf("Failed to create API client: %w", err))