Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a aws profile parameter to have an autorefreshing token. #86

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Expand Down
4 changes: 2 additions & 2 deletions cli/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 => ./
)
4 changes: 3 additions & 1 deletion storage/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}))
Expand All @@ -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 {
Expand Down