From a896b3660b467e7df2584c536ef6d6fbb226f52e Mon Sep 17 00:00:00 2001 From: Ben McClelland Date: Mon, 3 Jun 2024 21:07:16 -0700 Subject: [PATCH] fix: remove deprecated WithEndpointResolver s3 client option --- auth/iam_s3_object.go | 22 +++++++--------------- backend/s3proxy/client.go | 21 ++++++--------------- tests/integration/s3conf.go | 22 ++++++++-------------- 3 files changed, 21 insertions(+), 44 deletions(-) diff --git a/auth/iam_s3_object.go b/auth/iam_s3_object.go index 6714fcfe..b8b6a607 100644 --- a/auth/iam_s3_object.go +++ b/auth/iam_s3_object.go @@ -85,6 +85,13 @@ func NewS3(access, secret, region, bucket, endpoint string, sslSkipVerify, debug return nil, fmt.Errorf("init s3 IAM: %v", err) } + if endpoint != "" { + i.client = s3.NewFromConfig(cfg, func(o *s3.Options) { + o.BaseEndpoint = &endpoint + }) + return i, nil + } + i.client = s3.NewFromConfig(cfg) return i, nil } @@ -159,16 +166,6 @@ func (s *IAMServiceS3) ListUserAccounts() ([]Account, error) { return accs, nil } -// ResolveEndpoint is used for on prem or non-aws endpoints -func (s *IAMServiceS3) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { - return aws.Endpoint{ - PartitionID: "aws", - URL: s.endpoint, - SigningRegion: s.region, - HostnameImmutable: true, - }, nil -} - func (s *IAMServiceS3) Shutdown() error { return nil } @@ -187,11 +184,6 @@ func (s *IAMServiceS3) getConfig() (aws.Config, error) { config.WithHTTPClient(client), } - if s.endpoint != "" { - opts = append(opts, - config.WithEndpointResolverWithOptions(s)) - } - if s.debug { opts = append(opts, config.WithClientLogMode(aws.LogSigning|aws.LogRetries|aws.LogRequest|aws.LogResponse|aws.LogRequestEventMessage|aws.LogResponseEventMessage)) diff --git a/backend/s3proxy/client.go b/backend/s3proxy/client.go index d0f7bdad..b88e50aa 100644 --- a/backend/s3proxy/client.go +++ b/backend/s3proxy/client.go @@ -33,6 +33,12 @@ func (s *S3Proxy) getClientWithCtx(ctx context.Context) (*s3.Client, error) { return nil, err } + if s.endpoint != "" { + return s3.NewFromConfig(cfg, func(o *s3.Options) { + o.BaseEndpoint = &s.endpoint + }), nil + } + return s3.NewFromConfig(cfg), nil } @@ -50,11 +56,6 @@ func (s *S3Proxy) getConfig(ctx context.Context, access, secret string) (aws.Con config.WithHTTPClient(client), } - if s.endpoint != "" { - opts = append(opts, - config.WithEndpointResolverWithOptions(s)) - } - if s.disableChecksum { opts = append(opts, config.WithAPIOptions([]func(*middleware.Stack) error{v4.SwapComputePayloadSHA256ForUnsignedPayloadMiddleware})) @@ -67,13 +68,3 @@ func (s *S3Proxy) getConfig(ctx context.Context, access, secret string) (aws.Con return config.LoadDefaultConfig(ctx, opts...) } - -// ResolveEndpoint is used for on prem or non-aws endpoints -func (s *S3Proxy) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { - return aws.Endpoint{ - PartitionID: "aws", - URL: s.endpoint, - SigningRegion: s.awsRegion, - HostnameImmutable: true, - }, nil -} diff --git a/tests/integration/s3conf.go b/tests/integration/s3conf.go index 34e14572..c547e8d2 100644 --- a/tests/integration/s3conf.go +++ b/tests/integration/s3conf.go @@ -93,13 +93,8 @@ func (c *S3Conf) getCreds() credentials.StaticCredentialsProvider { return credentials.NewStaticCredentialsProvider(c.awsID, c.awsSecret, "") } -func (c *S3Conf) ResolveEndpoint(service, region string, options ...interface{}) (aws.Endpoint, error) { - return aws.Endpoint{ - PartitionID: "aws", - URL: c.endpoint, - SigningRegion: c.awsRegion, - HostnameImmutable: true, - }, nil +func (c *S3Conf) GetClient() *s3.Client { + return s3.NewFromConfig(c.Config()) } func (c *S3Conf) Config() aws.Config { @@ -114,11 +109,6 @@ func (c *S3Conf) Config() aws.Config { config.WithHTTPClient(client), } - if c.endpoint != "" && c.endpoint != "aws" { - opts = append(opts, - config.WithEndpointResolverWithOptions(c)) - } - if c.checksumDisable { opts = append(opts, config.WithAPIOptions([]func(*middleware.Stack) error{v4.SwapComputePayloadSHA256ForUnsignedPayloadMiddleware})) @@ -135,11 +125,15 @@ func (c *S3Conf) Config() aws.Config { log.Fatalln("error:", err) } + if c.endpoint != "" && c.endpoint != "aws" { + cfg.BaseEndpoint = &c.endpoint + } + return cfg } func (c *S3Conf) UploadData(r io.Reader, bucket, object string) error { - uploader := manager.NewUploader(s3.NewFromConfig(c.Config())) + uploader := manager.NewUploader(c.GetClient()) uploader.PartSize = c.PartSize uploader.Concurrency = c.Concurrency @@ -154,7 +148,7 @@ func (c *S3Conf) UploadData(r io.Reader, bucket, object string) error { } func (c *S3Conf) DownloadData(w io.WriterAt, bucket, object string) (int64, error) { - downloader := manager.NewDownloader(s3.NewFromConfig(c.Config())) + downloader := manager.NewDownloader(c.GetClient()) downloader.PartSize = c.PartSize downloader.Concurrency = c.Concurrency