Skip to content

fix(object): change user-agent #2919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions internal/services/object/helpers_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (
maxObjectVersionDeletionWorkers = 8

ErrCodeForbidden = "Forbidden"

defaultVersion = "v2.49.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how will this string get maintained through time?

)

type scalewayResolver struct {
Expand All @@ -47,8 +49,25 @@ func (r *scalewayResolver) ResolveEndpoint(ctx context.Context, params s3.Endpoi
return s3.NewDefaultEndpointResolverV2().ResolveEndpoint(ctx, params)
}

type userAgentRoundTripper struct {
defaultRoundTripper http.RoundTripper
userAgent string
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also add the version of terraform as well.
here is an example of what we currently have:

scaleway-sdk-go/v1.0.0-beta.30.0.20241129094524-023aa8142bc1 (go1.23.1; linux; amd64) terraform-provider/2.49.0 terraform/1.10.4


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

return r.defaultRoundTripper.RoundTrip(req)
}

func newS3Client(ctx context.Context, region, accessKey, secretKey string, httpClient *http.Client) (*s3.Client, error) {
endpoint := "https://s3." + region + ".scw.cloud"
httpClient.Transport = &userAgentRoundTripper{
defaultRoundTripper: httpClient.Transport,
userAgent: userAgent,
}

cfg, err := config.LoadDefaultConfig(ctx,
config.WithRegion(region),
Expand Down
2,658 changes: 1,332 additions & 1,326 deletions internal/services/object/testdata/data-source-object-bucket-basic.cassette.yaml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1,638 changes: 819 additions & 819 deletions internal/services/object/testdata/object-basic.cassette.yaml

Large diffs are not rendered by default.

788 changes: 398 additions & 390 deletions internal/services/object/testdata/object-bucket-acl-basic.cassette.yaml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1,540 changes: 774 additions & 766 deletions internal/services/object/testdata/object-bucket-acl-remove.cassette.yaml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading
Loading