Skip to content

Commit 3e8ce8e

Browse files
committed
Region adjustment
STACKIT will move to a new way of specifying regions with v1. Instead of providing the region in the URL directly it is provided via path parameter. 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 3e8ce8e

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
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 with v1. Instead of providing the region in the URL directly it is provided via path parameter. 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: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,10 @@ func (c *Configuration) ServerURLWithContext(ctx context.Context, endpoint strin
478478
// ConfigureRegion configures the API server urls with the user specified region.
479479
// Does nothing if a custom endpoint is provided.
480480
// Throws an error if no region is given or if the region is not valid
481+
// Throws an error if a region is given for a global url.
481482
func ConfigureRegion(cfg *Configuration) error {
483+
fmt.Println("Warning: STACKIT will move to a new way of specifying regions with v1. Instead of providing the region in the URL directly it is provided via path parameter." +
484+
" Once all services have migrated, the methods to specify the region in the client configuration will be removed.")
482485
if cfg.setCustomEndpoint {
483486
return nil
484487
}
@@ -519,13 +522,16 @@ func ConfigureRegion(cfg *Configuration) error {
519522
// Region is not available.
520523
return fmt.Errorf("the provided region is not available for this API, available regions are: %s", availableRegions)
521524
}
522-
// Global API. The provided region is ignored.
523-
// If the url is a template, generated using deprecated config.json, the region variable is replaced
524-
// If the url is already configured, there is no region variable and it remains the same
525-
cfgUrl := strings.Replace(servers[0].URL, "{region}", "", -1)
525+
526+
// Global API. If a region is provided return an error.
527+
// The region is not part of the url anymore instead the region is provided via path parameter.
528+
if strings.Contains(servers[0].URL, "{region}") {
529+
return fmt.Errorf("a region was provided in the url for a global api but has to be specified in the individual methods; STACKIT will move to a new way of specifying regions with v1")
530+
}
531+
526532
cfg.Servers = ServerConfigurations{
527533
{
528-
URL: cfgUrl,
534+
URL: servers[0].URL,
529535
Description: servers[0].Description,
530536
},
531537
}

core/config/config_test.go

Lines changed: 8 additions & 16 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: "invalid_global_with_region",
4545
cfg: &Configuration{
4646
Region: "",
4747
Servers: ServerConfigurations{
@@ -56,13 +56,9 @@ func TestConfigureRegion(t *testing.T) {
5656
},
5757
},
5858
},
59-
regionEnvVar: "",
60-
expectedServers: ServerConfigurations{
61-
ServerConfiguration{
62-
URL: "https://some-api.api.stackit.cloud",
63-
},
64-
},
65-
isValid: true,
59+
regionEnvVar: "",
60+
expectedServers: nil,
61+
isValid: false,
6662
},
6763
{
6864
desc: "valid_global_empty_default",
@@ -113,7 +109,7 @@ func TestConfigureRegion(t *testing.T) {
113109
isValid: true,
114110
},
115111
{
116-
desc: "valid_deprecated_global_with_specified_region",
112+
desc: "invalid_deprecated_global_with_specified_region",
117113
cfg: &Configuration{
118114
Region: "eu01",
119115
Servers: ServerConfigurations{
@@ -128,13 +124,9 @@ func TestConfigureRegion(t *testing.T) {
128124
},
129125
},
130126
},
131-
regionEnvVar: "",
132-
expectedServers: ServerConfigurations{
133-
ServerConfiguration{
134-
URL: "https://some-api.api.stackit.cloud",
135-
},
136-
},
137-
isValid: true,
127+
regionEnvVar: "",
128+
expectedServers: nil,
129+
isValid: false,
138130
},
139131
{
140132
desc: "env_var_valid_region",

0 commit comments

Comments
 (0)