Skip to content

Commit

Permalink
change provider client User-Agent (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyangyu authored Oct 14, 2022
1 parent 2d63b5a commit 4a8cbb4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (p *tidbcloudProvider) Configure(ctx context.Context, req provider.Configur
}

// Create a new tidb client and set it to the provider client
c, err := tidbcloud.NewTiDBCloudClient(publicKey, privateKey)
c, err := tidbcloud.NewTiDBCloudClient(publicKey, privateKey, p.version)
if err != nil {
resp.Diagnostics.AddError(
"Unable to create client",
Expand Down
4 changes: 2 additions & 2 deletions tidbcloud/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
type TiDBCloudClient struct {
}

func NewTiDBCloudClient(publicKey, privateKey string) (*TiDBCloudClient, error) {
initClient(publicKey, privateKey)
func NewTiDBCloudClient(publicKey, privateKey, providerVersion string) (*TiDBCloudClient, error) {
initClient(publicKey, privateKey, providerVersion)
c := TiDBCloudClient{}
return &c, nil
}
Expand Down
8 changes: 5 additions & 3 deletions tidbcloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package tidbcloud
import (
"encoding/json"
"fmt"
"github.com/go-resty/resty/v2"
"github.com/icholy/digest"
"log"
"net/http"
"os"
"sync"

"github.com/go-resty/resty/v2"
"github.com/icholy/digest"
)

var (
Expand All @@ -19,13 +20,14 @@ var (

var host = "https://api.tidbcloud.com"

func initClient(publicKey, privateKey string) {
func initClient(publicKey, privateKey, providerVersion string) {
clientInitOnce.Do(func() {
restClient = resty.New()
restClient.SetTransport(&digest.Transport{
Username: publicKey,
Password: privateKey,
})
restClient.SetHeader(http.CanonicalHeaderKey("User-Agent"), fmt.Sprintf("terraform-provider-tidbcloud/%s - go-resty/%s", providerVersion, resty.Version))
})
// only for test
if os.Getenv("TIDBCLOUD_HOST") != "" {
Expand Down

0 comments on commit 4a8cbb4

Please sign in to comment.