Skip to content

Commit 74bfb3d

Browse files
authored
Fix: ConfigureRegion() throws error if the region is set by environment variable (#1262)
* Fix: ConfigureRegion() throws error if the region is set by environment variable
1 parent 0f45891 commit 74bfb3d

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Release (2025-XX-XX)
2+
3+
- `core`: [v0.15.1](core/CHANGELOG.md#v0151-2025-01-08)
4+
- **Bugfix:** `ConfigureRegion` does not return an error if a region is set by an enviroment variable.
5+
16
## Release (2025-01-07)
27

38
- `postgresflex`: [0.16.1](services/postgresflex/CHANGELOG.md#v0161-2025-xx-yy)

core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v0.15.1 (2025-01-08)
2+
3+
- **Bugfix:** `ConfigureRegion` does not return an error if a region is set by an enviroment variable.
4+
15
## v0.15.0 (2025-01-02)
26

37
- **Breaking Change:**: `ConfigureRegion` returns an error if a region is specified for a global URL.

core/config/config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,12 @@ func ConfigureRegion(cfg *Configuration) error {
499499
availableRegions = append(availableRegions, strings.TrimSuffix(regionWithDotSuffix, "."))
500500
}
501501

502+
isRegionSetByEnv := false
502503
if cfg.Region == "" {
503504
// Check region
504505
envVarRegion, _ := os.LookupEnv("STACKIT_REGION")
505506
cfg.Region = envVarRegion
507+
isRegionSetByEnv = true
506508
}
507509

508510
if oasRegion.DefaultValue != "" && oasRegion.DefaultValue != global {
@@ -524,9 +526,9 @@ func ConfigureRegion(cfg *Configuration) error {
524526
return fmt.Errorf("the provided region is not available for this API, available regions are: %s", availableRegions)
525527
}
526528
// Global API.
527-
// If a region is provided by the user via WithRegion() or via environment variable return an error.
529+
// If a region is provided by the user via WithRegion() return an error.
528530
// The region is provided as a function argument instead of being set in the client configuration.
529-
if cfg.Region != "" {
531+
if cfg.Region != "" && !isRegionSetByEnv {
530532
return fmt.Errorf("this API does not support setting a region in the the client configuration, please check if the region can be specified as a function parameter")
531533
}
532534
// If the url is a template, generated using deprecated config.json, the region variable is replaced

0 commit comments

Comments
 (0)