Skip to content

Commit

Permalink
fix: remove deprecated WithEndpointResolver s3 client option
Browse files Browse the repository at this point in the history
  • Loading branch information
benmcclelland committed Jun 4, 2024
1 parent ab0feac commit a896b36
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 44 deletions.
22 changes: 7 additions & 15 deletions auth/iam_s3_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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))
Expand Down
21 changes: 6 additions & 15 deletions backend/s3proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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}))
Expand All @@ -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
}
22 changes: 8 additions & 14 deletions tests/integration/s3conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}))
Expand All @@ -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

Expand All @@ -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

Expand Down

0 comments on commit a896b36

Please sign in to comment.