Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 42 additions & 16 deletions fs/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
package s3

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
s3 "github.com/fclairamb/afero-s3"
"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"
aferos3 "github.com/fclairamb/afero-s3"
"github.com/spf13/afero"

"github.com/fclairamb/ftpserver/config/confpar"
Expand All @@ -18,30 +21,53 @@ func LoadFs(access *confpar.Access) (afero.Fs, error) {
bucket := access.Params["bucket"]
keyID := access.Params["access_key_id"]
secretAccessKey := access.Params["secret_access_key"]
disableSSL := access.Params["disable_ssl"] == "true"
pathStyle := access.Params["path_style"] == "true"

// Build config options for AWS SDK v2
var configOpts []func(*config.LoadOptions) error

conf := aws.Config{
Region: aws.String(region),
DisableSSL: aws.Bool(access.Params["disable_ssl"] == "true"),
S3ForcePathStyle: aws.Bool(access.Params["path_style"] == "true"),
if region != "" {
configOpts = append(configOpts, config.WithRegion(region))
}

if keyID != "" && secretAccessKey != "" {
conf.Credentials = credentials.NewStaticCredentials(keyID, secretAccessKey, "")
configOpts = append(configOpts, config.WithCredentialsProvider(
credentials.NewStaticCredentialsProvider(keyID, secretAccessKey, ""),
))
}

if endpoint != "" {
conf.Endpoint = aws.String(endpoint)
cfg, err := config.LoadDefaultConfig(context.Background(), configOpts...)
if err != nil {
return nil, err
}

sess, errSession := session.NewSession(&conf)
// Build S3 client options
var s3Opts []func(*s3.Options)

if endpoint != "" {
endpointURL := endpoint
if disableSSL {
// Ensure HTTP scheme if SSL is disabled
if len(endpointURL) > 0 && endpointURL[0] != 'h' {
endpointURL = "http://" + endpointURL
}
}
s3Opts = append(s3Opts, func(o *s3.Options) {
o.BaseEndpoint = aws.String(endpointURL)
})
}

if errSession != nil {
return nil, errSession
if pathStyle {
s3Opts = append(s3Opts, func(o *s3.Options) {
o.UsePathStyle = true
})
}

s3Fs := s3.NewFs(bucket, sess)
// Create S3 client with options
client := s3.NewFromConfig(cfg, s3Opts...)

// s3Fs = stripprefix.NewStripPrefixFs(s3Fs, 1)
s3Fs := aferos3.NewFsFromClient(bucket, client)

return s3Fs, nil
}
24 changes: 21 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ toolchain go1.25.6
require (
cloud.google.com/go/storage v1.59.1
github.com/Nerzal/gocloak/v13 v13.9.0
github.com/aws/aws-sdk-go v1.55.8
github.com/aws/aws-sdk-go-v2 v1.41.1
github.com/aws/aws-sdk-go-v2/config v1.32.7
github.com/aws/aws-sdk-go-v2/credentials v1.19.7
github.com/aws/aws-sdk-go-v2/service/s3 v1.95.1
github.com/fclairamb/afero-dropbox v0.1.0
github.com/fclairamb/afero-gdrive v0.3.0
github.com/fclairamb/afero-s3 v0.3.1
github.com/fclairamb/afero-s3 v0.4.0
github.com/fclairamb/afero-snd v0.2.0
github.com/fclairamb/ftpserverlib v0.29.0
github.com/go-crypt/crypt v0.4.7
Expand Down Expand Up @@ -75,11 +78,26 @@ require (
)

require (
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.17 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.20.19 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.17 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.17 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.17 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.8 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.17 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.17 // indirect
github.com/aws/aws-sdk-go-v2/service/signin v1.0.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.30.9 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.13 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.41.6 // indirect
github.com/aws/smithy-go v1.24.0 // indirect
github.com/dropbox/dropbox-sdk-go-unofficial v5.6.0+incompatible // indirect
github.com/fclairamb/go-log v0.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.11 // indirect
github.com/googleapis/gax-go/v2 v2.16.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kr/fs v0.1.0 // indirect
golang.org/x/net v0.49.0 // indirect
golang.org/x/sys v0.40.0 // indirect
Expand Down
Loading