diff --git a/Dockerfile b/Dockerfile index 8975b42..ea58a34 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,9 +3,10 @@ FROM golang:1.20.5-alpine as builder ENV CGO_ENABLED 0 WORKDIR /src/s3sync +COPY go.mod go.sum ./ +RUN go mod download COPY . ./ -RUN go mod vendor && \ - go build -o s3sync ./cli +RUN go build -o s3sync ./cli # Create s3sync image FROM alpine diff --git a/cli/cli.go b/cli/cli.go index b164801..fd47edb 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -46,6 +46,7 @@ type args struct { Source string `arg:"positional"` SourceNoSign bool `arg:"--sn" help:"Don't sign request to source AWS for anonymous access"` SourceKey string `arg:"--sk" help:"Source AWS key / Swift User"` + SourceProfile string `arg:"--sp" help:"Source Profile"` SourceSecret string `arg:"--ss" help:"Source AWS secret / Swift Key"` SourceToken string `arg:"--st" help:"Source AWS token / Swift Tenant"` SourceRegion string `arg:"--sr" help:"Source AWS Region / Swift Domain"` @@ -54,6 +55,7 @@ type args struct { Target string `arg:"positional"` TargetNoSign bool `arg:"--tn" help:"Don't sign request to target AWS for anonymous access"` TargetKey string `arg:"--tk" help:"Target AWS key"` + TargetProfile string `arg:"--tp" help:"Source Profile"` TargetSecret string `arg:"--ts" help:"Target AWS secret"` TargetToken string `arg:"--tt" help:"Target AWS session token"` TargetRegion string `arg:"--tr" help:"Target AWS Region"` diff --git a/cli/setup.go b/cli/setup.go index 4adab8f..049c010 100644 --- a/cli/setup.go +++ b/cli/setup.go @@ -20,7 +20,7 @@ func setupStorages(ctx context.Context, syncGroup *pipeline.Group, cli *argsPars switch cli.Source.Type { case storage.TypeS3: - sourceStorage = s3.NewS3Storage(cli.SourceNoSign, cli.SourceKey, cli.SourceSecret, cli.SourceToken, cli.SourceRegion, cli.SourceEndpoint, + sourceStorage = s3.NewS3Storage(cli.SourceNoSign, cli.SourceProfile, cli.SourceKey, cli.SourceSecret, cli.SourceToken, cli.SourceRegion, cli.SourceEndpoint, cli.Source.Bucket, cli.Source.Path, cli.S3KeysPerReq, cli.S3Retry, cli.S3RetryInterval, cli.SkipSSLVerify, ) case storage.TypeS3Stream: @@ -38,7 +38,7 @@ func setupStorages(ctx context.Context, syncGroup *pipeline.Group, cli *argsPars switch cli.Target.Type { case storage.TypeS3: - targetStorage = s3.NewS3Storage(cli.TargetNoSign, cli.TargetKey, cli.TargetSecret, cli.TargetToken, cli.TargetRegion, cli.TargetEndpoint, + targetStorage = s3.NewS3Storage(cli.TargetNoSign,cli.TargetProfile, cli.TargetKey, cli.TargetSecret, cli.TargetToken, cli.TargetRegion, cli.TargetEndpoint, cli.Target.Bucket, cli.Target.Path, cli.S3KeysPerReq, cli.S3Retry, cli.S3RetryInterval, cli.SkipSSLVerify, ) case storage.TypeS3Stream: diff --git a/go.mod b/go.mod index 913bba1..0f1c9a0 100644 --- a/go.mod +++ b/go.mod @@ -20,3 +20,7 @@ require ( github.com/jmespath/go-jmespath v0.4.0 // indirect golang.org/x/sys v0.1.0 // indirect ) + +replace ( + github.com/larrabee/s3sync => ./ +) \ No newline at end of file diff --git a/storage/s3/s3.go b/storage/s3/s3.go index a5a798f..178dc2a 100644 --- a/storage/s3/s3.go +++ b/storage/s3/s3.go @@ -39,7 +39,7 @@ type S3Storage struct { // NewS3Storage return new configured S3 storage. // // You should always create new storage with this constructor. -func NewS3Storage(awsNoSign bool, awsAccessKey, awsSecretKey, awsToken, awsRegion, endpoint, bucketName, prefix string, keysPerReq int64, retryCnt uint, retryDelay time.Duration, skipSSLVerify bool) *S3Storage { +func NewS3Storage(awsNoSign bool, awsProfile, awsAccessKey, awsSecretKey, awsToken, awsRegion, endpoint, bucketName, prefix string, keysPerReq int64, retryCnt uint, retryDelay time.Duration, skipSSLVerify bool) *S3Storage { sess := session.Must(session.NewSessionWithOptions(session.Options{ SharedConfigState: session.SharedConfigEnable, })) @@ -54,6 +54,8 @@ func NewS3Storage(awsNoSign bool, awsAccessKey, awsSecretKey, awsToken, awsRegio if awsNoSign { sess.Config.Credentials = credentials.AnonymousCredentials + } else if awsProfile != "" { + sess.Config.Credentials = credentials.NewSharedCredentials("", awsProfile) } else if awsAccessKey != "" || awsSecretKey != "" { sess.Config.Credentials = credentials.NewStaticCredentials(awsAccessKey, awsSecretKey, awsToken) } else if _, err := sess.Config.Credentials.Get(); err != nil {