s3: use new Endpoint API

lint: s3/public.go#L136
SA1019: config.WithEndpointResolverWithOptions is deprecated: The global endpoint resolution interface is deprecated. See deprecation docs on [WithEndpointResolver]. (staticcheck)
lint: s3/public.go#L137
SA1019: aws.Endpoint is deprecated: This structure was used with the global [EndpointResolver] interface, which has been deprecated in favor of service-specific endpoint resolution. See the deprecation docs on that interface for more information.  (staticcheck)
lint: s3/public.go#L138
SA1019: aws.Endpoint is deprecated: This structure was used with the global [EndpointResolver] interface, which has been deprecated in favor of service-specific endpoint resolution. See the deprecation docs on that interface for more information.  (staticcheck)
This commit is contained in:
André Roth
2024-08-01 21:31:02 +02:00
parent 83a05a1900
commit 674f4f784b

View File

@@ -67,7 +67,7 @@ var (
func NewPublishedStorageRaw(
bucket, defaultACL, prefix, storageClass, encryptionMethod string,
plusWorkaround, disabledMultiDel, forceVirtualHostedStyle bool,
config *aws.Config,
config *aws.Config, endpoint string,
) (*PublishedStorage, error) {
var acl types.ObjectCannedACL
if defaultACL == "" || defaultACL == "private" {
@@ -82,10 +82,16 @@ func NewPublishedStorageRaw(
storageClass = ""
}
var baseEndpoint *string
if endpoint != "" {
baseEndpoint = aws.String(endpoint)
}
result := &PublishedStorage{
s3: s3.NewFromConfig(*config, func(o *s3.Options) {
o.UsePathStyle = !forceVirtualHostedStyle
o.HTTPSignerV4 = v4.NewSigner()
o.BaseEndpoint = baseEndpoint
}),
bucket: bucket,
config: config,
@@ -132,21 +138,13 @@ func NewPublishedStorage(
opts = append(opts, config.WithLogger(&logger{}))
}
if endpoint != "" {
opts = append(opts, config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(
func(_, _ string, _ ...interface{}) (aws.Endpoint, error) {
return aws.Endpoint{URL: endpoint}, nil
},
)))
}
config, err := config.LoadDefaultConfig(context.TODO(), opts...)
if err != nil {
return nil, err
}
result, err := NewPublishedStorageRaw(bucket, defaultACL, prefix, storageClass,
encryptionMethod, plusWorkaround, disableMultiDel, forceVirtualHostedStyle, &config)
encryptionMethod, plusWorkaround, disableMultiDel, forceVirtualHostedStyle, &config, endpoint)
return result, err
}