Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Support the AWS_REGION env var #542

Closed
wants to merge 3 commits into from
Closed
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
14 changes: 7 additions & 7 deletions pkg/storage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ type S3BackendOptions struct {

// Apply apply s3 options on backup.S3.
func (options *S3BackendOptions) Apply(s3 *backup.S3) error {
if options.Region == "" {
options.Region = "us-east-1"
}
if options.Endpoint != "" {
u, err := url.Parse(options.Endpoint)
if err != nil {
Expand Down Expand Up @@ -176,10 +173,11 @@ func defineS3Flags(flags *pflag.FlagSet) {
// TODO: remove experimental tag if it's stable
flags.String(s3EndpointOption, "",
"(experimental) Set the S3 endpoint URL, please specify the http or https scheme explicitly")
flags.String(s3RegionOption, "", "(experimental) Set the S3 region, e.g. us-east-1")
flags.String(s3RegionOption, "", "(experimental) Set the S3 region, e.g. us-east-1, "+
"defaults to using the AWS_REGION env var")
flags.String(s3StorageClassOption, "", "(experimental) Set the S3 storage class, e.g. STANDARD")
flags.String(s3SseOption, "", "Set S3 server-side encryption, e.g. aws:kms")
flags.String(s3SseKmsKeyIDOption, "", "KMS CMK key id to use with S3 server-side encryption."+
flags.String(s3SseKmsKeyIDOption, "", "KMS CMK key id to use with S3 server-side encryption. "+
"Leave empty to use S3 owned key.")
flags.String(s3ACLOption, "", "(experimental) Set the S3 canned ACLs, e.g. authenticated-read")
flags.String(s3ProviderOption, "", "(experimental) Set the S3 provider, e.g. aws, alibaba, ceph")
Expand Down Expand Up @@ -228,8 +226,10 @@ func NewS3Storage( // revive:disable-line:flag-parameter
qs := *backend
awsConfig := aws.NewConfig().
WithMaxRetries(maxRetries).
WithS3ForcePathStyle(qs.ForcePathStyle).
WithRegion(qs.Region)
WithS3ForcePathStyle(qs.ForcePathStyle)
if qs.Region != "" {
awsConfig.WithRegion(qs.Region)
}
if qs.Endpoint != "" {
awsConfig.WithEndpoint(qs.Endpoint)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (r *testStorageSuite) TestApplyUpdate(c *C) {
Endpoint: "",
},
s3: &backup.S3{
Region: "us-east-1",
Region: "",
Bucket: "bucket",
Prefix: "prefix",
},
Expand All @@ -131,7 +131,7 @@ func (r *testStorageSuite) TestApplyUpdate(c *C) {
Endpoint: "https://s3.us-west-2",
},
s3: &backup.S3{
Region: "us-east-1",
Region: "",
Endpoint: "https://s3.us-west-2",
Bucket: "bucket",
Prefix: "prefix",
Expand All @@ -143,7 +143,7 @@ func (r *testStorageSuite) TestApplyUpdate(c *C) {
Endpoint: "http://s3.us-west-2",
},
s3: &backup.S3{
Region: "us-east-1",
Region: "",
Endpoint: "http://s3.us-west-2",
Bucket: "bucket",
Prefix: "prefix",
Expand Down