34 lines
930 B
Go
34 lines
930 B
Go
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
|
|
}
|