|
1 | 1 | package external |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "fmt" |
4 | 5 | "io/ioutil" |
5 | 6 | "os" |
| 7 | + "strings" |
6 | 8 |
|
7 | 9 | "github.com/aws/aws-sdk-go-v2/aws" |
8 | 10 | ) |
@@ -37,6 +39,8 @@ const ( |
37 | 39 | AWSConfigFileEnvVar = "AWS_CONFIG_FILE" |
38 | 40 |
|
39 | 41 | AWSCustomCABundleEnvVar = "AWS_CA_BUNDLE" |
| 42 | + |
| 43 | + S3UseARNRegionEnvVar = "AWS_S3_USE_ARN_REGION" |
40 | 44 | ) |
41 | 45 |
|
42 | 46 | var ( |
@@ -134,6 +138,12 @@ type EnvConfig struct { |
134 | 138 | // |
135 | 139 | // AWS_CA_BUNDLE=$HOME/my_custom_ca_bundle |
136 | 140 | CustomCABundle string |
| 141 | + |
| 142 | + // Specifies if the S3 service should allow ARNs to direct the region |
| 143 | + // the client's requests are sent to. |
| 144 | + // |
| 145 | + // AWS_S3_USE_ARN_REGION=true |
| 146 | + S3UseARNRegion *bool |
137 | 147 | } |
138 | 148 |
|
139 | 149 | // LoadEnvConfig reads configuration values from the OS's environment variables. |
@@ -168,6 +178,24 @@ func NewEnvConfig() (EnvConfig, error) { |
168 | 178 |
|
169 | 179 | cfg.CustomCABundle = os.Getenv(AWSCustomCABundleEnvVar) |
170 | 180 |
|
| 181 | + s3UseARNRegion := os.Getenv(S3UseARNRegionEnvVar) |
| 182 | + if len(s3UseARNRegion) != 0 { |
| 183 | + var v bool |
| 184 | + |
| 185 | + switch { |
| 186 | + case strings.EqualFold(s3UseARNRegion, "false"): |
| 187 | + v = false |
| 188 | + case strings.EqualFold(s3UseARNRegion, "true"): |
| 189 | + v = true |
| 190 | + default: |
| 191 | + return cfg, fmt.Errorf( |
| 192 | + "invalid value for environment variable, %s=%s, need true or false", |
| 193 | + S3UseARNRegionEnvVar, s3UseARNRegion) |
| 194 | + } |
| 195 | + |
| 196 | + cfg.S3UseARNRegion = &v |
| 197 | + } |
| 198 | + |
171 | 199 | return cfg, nil |
172 | 200 | } |
173 | 201 |
|
@@ -226,6 +254,16 @@ func (c EnvConfig) GetCustomCABundle() ([]byte, error) { |
226 | 254 | return ioutil.ReadFile(c.CustomCABundle) |
227 | 255 | } |
228 | 256 |
|
| 257 | +// GetS3UseARNRegion returns whether to allow ARNs to direct the region |
| 258 | +// the S3 client's requests are sent to. |
| 259 | +func (c EnvConfig) GetS3UseARNRegion() (value, ok bool, err error) { |
| 260 | + if c.S3UseARNRegion == nil { |
| 261 | + return false, false, nil |
| 262 | + } |
| 263 | + |
| 264 | + return *c.S3UseARNRegion, true, nil |
| 265 | +} |
| 266 | + |
229 | 267 | func setFromEnvVal(dst *string, keys []string) { |
230 | 268 | for _, k := range keys { |
231 | 269 | if v := os.Getenv(k); len(v) > 0 { |
|
0 commit comments