Skip to content

Commit

Permalink
fix user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Laure-di committed Feb 10, 2025
1 parent b6023e2 commit e6c83be
Show file tree
Hide file tree
Showing 39 changed files with 19,790 additions and 19,758 deletions.
36 changes: 34 additions & 2 deletions internal/services/object/helpers_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"runtime"
"runtime/debug"
"strings"
"time"

Expand Down Expand Up @@ -52,8 +53,39 @@ type userAgentRoundTripper struct {
userAgent string
}

const (
defaultVersion = "v2.49.0"
path = "https://github.com/scaleway/terraform-provider-scaleway"
)

var cachedVersion = (*string)(nil)

func getVersion() string {
if cachedVersion == nil {
debugVersion := ""
b, ok := debug.ReadBuildInfo()
if ok {
for _, dep := range b.Deps {
if dep.Path == path {
debugVersion = dep.Version
}
}
}

cachedVersion = &debugVersion
}

if *cachedVersion != "" {
return *cachedVersion
}

return defaultVersion
}

var userAgent = fmt.Sprintf("scaleway-terraform-provider/%s (%s; %s; %s)", getVersion(), runtime.Version(), runtime.GOOS, runtime.GOARCH)

func (r *userAgentRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
req.Header.Set("User-Agent", r.userAgent)
req.Header.Set("User-Agent", userAgent)

return r.defaultRoundTripper.RoundTrip(req)
}
Expand All @@ -62,7 +94,7 @@ func newS3Client(ctx context.Context, region, accessKey, secretKey string, httpC
endpoint := "https://s3." + region + ".scw.cloud"
httpClient.Transport = &userAgentRoundTripper{
defaultRoundTripper: httpClient.Transport,
userAgent: "Scaleway Terraform Provider",
userAgent: userAgent,
}
cfg, err := config.LoadDefaultConfig(ctx,
config.WithRegion(region),
Expand Down
Loading

0 comments on commit e6c83be

Please sign in to comment.