mirror of
https://github.com/nyanotech/object-holder.git
synced 2025-12-16 11:30:24 -08:00
accept region via flag, use default aws endpoint if unspecified
This commit is contained in:
parent
fbf4229e96
commit
68d8130c4e
25
main.go
25
main.go
@ -15,13 +15,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var endpoint = flag.String("endpoint", "", "s3 endpoint")
|
var endpoint = flag.String("endpoint", "", "s3 endpoint")
|
||||||
var bucket = flag.String("bucket", "", "bucket name")
|
var region = flag.String("region", "us-east-1", "s3 region")
|
||||||
var prefix = flag.String("prefix", "", "only operate on objects starting with this prefix")
|
|
||||||
|
|
||||||
// todo - default to other credentials providers
|
|
||||||
var accessKeyId = flag.String("access-key-id", "", "aws access key")
|
var accessKeyId = flag.String("access-key-id", "", "aws access key")
|
||||||
var secretAccessKey = flag.String("secret-access-key", "", "aws secret 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 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)")
|
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 := []func(*config.LoadOptions) error{}
|
||||||
|
|
||||||
options = append(options,
|
if *region != "" {
|
||||||
// TODO: figure out what to do with this
|
options = append(options, config.WithRegion(*region))
|
||||||
config.WithRegion("us-east-1"),
|
}
|
||||||
config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(
|
|
||||||
|
if *endpoint != "" {
|
||||||
|
options = append(options, config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(
|
||||||
func(service, region string, options ...interface{}) (aws.Endpoint, error) {
|
func(service, region string, options ...interface{}) (aws.Endpoint, error) {
|
||||||
return aws.Endpoint{
|
return aws.Endpoint{
|
||||||
URL: *endpoint,
|
URL: *endpoint,
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
)),
|
)))
|
||||||
)
|
}
|
||||||
|
|
||||||
if *accessKeyId != "" && *secretAccessKey != "" {
|
if *accessKeyId != "" && *secretAccessKey != "" {
|
||||||
options = append(options, config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(*accessKeyId, *secretAccessKey, "")))
|
options = append(options, config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(*accessKeyId, *secretAccessKey, "")))
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := config.LoadDefaultConfig(context.TODO(),
|
cfg, err := config.LoadDefaultConfig(context.TODO(), options...)
|
||||||
options...,
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("Failed to create AWS config", err)
|
log.Fatalln("Failed to create AWS config", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user