Skip to content

Commit 6031436

Browse files
committed
Centralize http transport logging config
1 parent 00f9ba0 commit 6031436

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

internal/client/client.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"log"
10-
"net/http"
1110
"net/url"
1211
"os"
1312
"sort"
@@ -16,7 +15,6 @@ import (
1615

1716
tfe "github.com/hashicorp/go-tfe"
1817
"github.com/hashicorp/go-version"
19-
"github.com/hashicorp/terraform-provider-tfe/internal/logging"
2018
providerVersion "github.com/hashicorp/terraform-provider-tfe/version"
2119
svchost "github.com/hashicorp/terraform-svchost"
2220
"github.com/hashicorp/terraform-svchost/disco"
@@ -143,19 +141,12 @@ func GetClient(tfeHost, token string, insecure bool) (*tfe.Client, error) {
143141
return nil, discoErr
144142
}
145143

146-
// Wrap the configured transport to enable logging.
147-
transport := config.HTTPClient.Transport.(*http.Transport)
148-
config.HTTPClient.Transport = logging.NewLoggingTransport("TFE", transport)
149-
150-
// Create a new TFE client config
151-
cfg := &tfe.Config{
144+
// Create a new TFE client.
145+
client, err := tfe.NewClient(&tfe.Config{
152146
Address: address.String(),
153147
Token: token,
154148
HTTPClient: config.HTTPClient,
155-
}
156-
157-
// Create a new TFE client.
158-
client, err := tfe.NewClient(cfg)
149+
})
159150
if err != nil {
160151
return nil, err
161152
}

internal/client/config.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import (
2121
"github.com/hashicorp/terraform-svchost/disco"
2222
)
2323

24+
var (
25+
// TFEUserAgent is the user agent string sent with all requests made by the provider
26+
TFEUserAgent = fmt.Sprintf("terraform-provider-tfe/%s", providerVersion.ProviderVersion)
27+
)
28+
2429
type CredentialsMap map[string]map[string]interface{}
2530

2631
// CLIHostConfig is the structure of the configuration for the Terraform CLI.
@@ -210,8 +215,8 @@ func configure(tfeHost, token string, insecure bool) (*ClientConfiguration, erro
210215
// Create a new credential source and service discovery object.
211216
credsSrc := credentialsSource(config.Credentials)
212217
services := disco.NewWithCredentialsSource(credsSrc)
213-
services.SetUserAgent(fmt.Sprintf("terraform-provider-tfe/%s", providerVersion.ProviderVersion))
214-
services.Transport = logging.NewLoggingTransport("TFE Discovery", transport)
218+
services.SetUserAgent(TFEUserAgent)
219+
services.Transport = logging.NewLoggingTransport("TFE", transport)
215220

216221
// Add any static host configurations service discovery object.
217222
for userHost, hostConfig := range config.Hosts {

0 commit comments

Comments
 (0)