Files

34 lines
930 B
Go
Raw Permalink Normal View History

2026-03-26 13:47:01 +01:00
package main
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/s3"
)
func createConfig(s3c CloudS3) (aws.Config, error) {
creds := credentials.NewStaticCredentialsProvider(s3c.AccessKey, s3c.SecretKey, "")
endpointResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, _ ...interface{}) (aws.Endpoint, error) {
if service == s3.ServiceID && s3c.EndpointURL != "" {
return aws.Endpoint{URL: s3c.EndpointURL, SigningRegion: s3c.Region}, nil
}
return aws.Endpoint{}, &aws.EndpointNotFoundError{}
})
cfg, err := config.LoadDefaultConfig(
context.Background(),
config.WithRegion(s3c.Region),
config.WithCredentialsProvider(creds),
config.WithEndpointResolverWithOptions(endpointResolver),
)
if err != nil {
return aws.Config{}, err
}
return cfg, nil
}