Skip to content

Commit 4c80ffd

Browse files
committed
Region adjustment
STACKIT will move to a new way of specifying regions, where the region is provided as a function argument instead of being set in the client configuration. Once all services have migrated, the methods to specify the region in the client configuration will be removed. Signed-off-by: Alexander Dahmen <[email protected]>
1 parent 058ca54 commit 4c80ffd

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

core/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v0.15.0 (2025-01-02)
2+
3+
- **Breaking Change:**: `ConfigureRegion` returns an error if a region is specified for a global URL.
4+
5+
STACKIT will move to a new way of specifying regions, where the region is provided as a function argument instead of being set in the client configuration. Once all services have migrated, the methods to specify the region in the client configuration will be removed.
6+
17
## v0.14.0 (2024-10-10)
28

39
- **Feature:**: Added `IntermediateStateReached` to `AsyncActionHandler` that can be used to check for an intermediate state when executing the wait function of a wait handler.

core/config/config.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package config
55
import (
66
"context"
77
"fmt"
8+
"log"
89
"net/http"
910
"os"
1011
"strings"
@@ -478,7 +479,10 @@ func (c *Configuration) ServerURLWithContext(ctx context.Context, endpoint strin
478479
// ConfigureRegion configures the API server urls with the user specified region.
479480
// Does nothing if a custom endpoint is provided.
480481
// Throws an error if no region is given or if the region is not valid
482+
// Throws an error if a region is given for a global url.
481483
func ConfigureRegion(cfg *Configuration) error {
484+
log.Println("WARNING: STACKIT will move to a new way of specifying regions, where the region is provided as a function argument instead of being set in the client configuration." +
485+
" Once all services have migrated, the methods to specify the region in the client configuration will be removed.")
482486
if cfg.setCustomEndpoint {
483487
return nil
484488
}
@@ -519,7 +523,12 @@ func ConfigureRegion(cfg *Configuration) error {
519523
// Region is not available.
520524
return fmt.Errorf("the provided region is not available for this API, available regions are: %s", availableRegions)
521525
}
522-
// Global API. The provided region is ignored.
526+
// Global API.
527+
// If a region is provided by the user via WithRegion() or via environment variable return an error.
528+
// The region is provided as a function argument instead of being set in the client configuration.
529+
if cfg.Region != "" {
530+
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")
531+
}
523532
// If the url is a template, generated using deprecated config.json, the region variable is replaced
524533
// If the url is already configured, there is no region variable and it remains the same
525534
cfgUrl := strings.Replace(servers[0].URL, "{region}", "", -1)

core/config/config_test.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestConfigureRegion(t *testing.T) {
4141
isValid: true,
4242
},
4343
{
44-
desc: "valid_deprecated_global",
44+
desc: "valid_global_with_region",
4545
cfg: &Configuration{
4646
Region: "",
4747
Servers: ServerConfigurations{
@@ -113,7 +113,7 @@ func TestConfigureRegion(t *testing.T) {
113113
isValid: true,
114114
},
115115
{
116-
desc: "valid_deprecated_global_with_specified_region",
116+
desc: "invalid_deprecated_global_with_specified_region",
117117
cfg: &Configuration{
118118
Region: "eu01",
119119
Servers: ServerConfigurations{
@@ -128,13 +128,9 @@ func TestConfigureRegion(t *testing.T) {
128128
},
129129
},
130130
},
131-
regionEnvVar: "",
132-
expectedServers: ServerConfigurations{
133-
ServerConfiguration{
134-
URL: "https://some-api.api.stackit.cloud",
135-
},
136-
},
137-
isValid: true,
131+
regionEnvVar: "",
132+
expectedServers: nil,
133+
isValid: false,
138134
},
139135
{
140136
desc: "env_var_valid_region",

0 commit comments

Comments
 (0)