s3: minor code cleanups

This commit is contained in:
Michael Eischer 2024-01-06 21:44:53 +01:00
parent 20cf4777cb
commit 02bc73f5eb
1 changed files with 3 additions and 5 deletions

View File

@ -138,7 +138,7 @@ func getCredentials(cfg Config) (*credentials.Credentials, error) {
// use the region provided by the configuration by default // use the region provided by the configuration by default
awsRegion := cfg.Region awsRegion := cfg.Region
// allow the region to be overridden if for some reason it is required // allow the region to be overridden if for some reason it is required
if len(os.Getenv("RESTIC_AWS_ASSUME_ROLE_REGION")) > 0 { if os.Getenv("RESTIC_AWS_ASSUME_ROLE_REGION") != "" {
awsRegion = os.Getenv("RESTIC_AWS_ASSUME_ROLE_REGION") awsRegion = os.Getenv("RESTIC_AWS_ASSUME_ROLE_REGION")
} }
@ -148,7 +148,7 @@ func getCredentials(cfg Config) (*credentials.Credentials, error) {
stsEndpoint := os.Getenv("RESTIC_AWS_ASSUME_ROLE_STS_ENDPOINT") stsEndpoint := os.Getenv("RESTIC_AWS_ASSUME_ROLE_STS_ENDPOINT")
if stsEndpoint == "" { if stsEndpoint == "" {
if len(awsRegion) > 0 { if awsRegion != "" {
if strings.HasPrefix(awsRegion, "cn-") { if strings.HasPrefix(awsRegion, "cn-") {
stsEndpoint = "https://sts." + awsRegion + ".amazonaws.com.cn" stsEndpoint = "https://sts." + awsRegion + ".amazonaws.com.cn"
} else { } else {
@ -167,9 +167,7 @@ func getCredentials(cfg Config) (*credentials.Credentials, error) {
RoleSessionName: sessionName, RoleSessionName: sessionName,
ExternalID: externalID, ExternalID: externalID,
Policy: policy, Policy: policy,
} Location: awsRegion,
if len(awsRegion) > 0 {
opts.Location = awsRegion
} }
creds, err = credentials.NewSTSAssumeRole(stsEndpoint, opts) creds, err = credentials.NewSTSAssumeRole(stsEndpoint, opts)