From 68d8130c4eed3a1e2e75720668c0e5eb9d4fdeec Mon Sep 17 00:00:00 2001 From: nyanotech Date: Mon, 8 Apr 2024 22:03:07 -0700 Subject: [PATCH] accept region via flag, use default aws endpoint if unspecified --- main.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 3e8e4e1..e96d94b 100644 --- a/main.go +++ b/main.go @@ -15,13 +15,14 @@ import ( ) var endpoint = flag.String("endpoint", "", "s3 endpoint") -var bucket = flag.String("bucket", "", "bucket name") -var prefix = flag.String("prefix", "", "only operate on objects starting with this prefix") +var region = flag.String("region", "us-east-1", "s3 region") -// todo - default to other credentials providers var accessKeyId = flag.String("access-key-id", "", "aws access key") var secretAccessKey = flag.String("secret-access-key", "", "aws secret key") +var bucket = flag.String("bucket", "", "bucket name") +var prefix = flag.String("prefix", "", "only operate on objects starting with this prefix") + var updateExpiresWithin = flag.Int("update-expires-within", 0, "only update objects whose lock expires within this many seconds (default 0)") var lockFor = flag.Int("lock-for", 90*24*3600, "how many seconds to renew the object lock for (default 90 days)") @@ -32,25 +33,25 @@ func main() { options := []func(*config.LoadOptions) error{} - options = append(options, - // TODO: figure out what to do with this - config.WithRegion("us-east-1"), - config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc( + if *region != "" { + options = append(options, config.WithRegion(*region)) + } + + if *endpoint != "" { + options = append(options, config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc( func(service, region string, options ...interface{}) (aws.Endpoint, error) { return aws.Endpoint{ URL: *endpoint, }, nil }, - )), - ) + ))) + } if *accessKeyId != "" && *secretAccessKey != "" { options = append(options, config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(*accessKeyId, *secretAccessKey, ""))) } - cfg, err := config.LoadDefaultConfig(context.TODO(), - options..., - ) + cfg, err := config.LoadDefaultConfig(context.TODO(), options...) if err != nil { log.Fatalln("Failed to create AWS config", err) }