50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package s3
|
|
|
|
import (
|
|
"context"
|
|
"file-system/internal/common"
|
|
"log"
|
|
|
|
"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"
|
|
)
|
|
|
|
type RustFSClient struct {
|
|
Client *s3.Client
|
|
PresignClient *s3.PresignClient
|
|
}
|
|
|
|
func NewRustFSClient(cfg *common.Config) *RustFSClient {
|
|
// Custom Endpoint Resolver
|
|
customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
|
|
return aws.Endpoint{
|
|
URL: cfg.RustFSEndpoint,
|
|
SigningRegion: cfg.RustFSRegion,
|
|
}, nil
|
|
})
|
|
|
|
awsCfg, err := config.LoadDefaultConfig(context.TODO(),
|
|
config.WithRegion(cfg.RustFSRegion),
|
|
config.WithEndpointResolverWithOptions(customResolver),
|
|
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(
|
|
cfg.RustFSAccessKeyID,
|
|
cfg.RustFSSecretAccessKey,
|
|
"",
|
|
)),
|
|
)
|
|
if err != nil {
|
|
log.Fatalf("unable to load SDK config, %v", err)
|
|
}
|
|
|
|
client := s3.NewFromConfig(awsCfg, func(o *s3.Options) {
|
|
o.UsePathStyle = true
|
|
})
|
|
|
|
return &RustFSClient{
|
|
Client: client,
|
|
PresignClient: s3.NewPresignClient(client),
|
|
}
|
|
}
|