Skip to content

Commit f713b31

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 f713b31

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-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, 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: 12 additions & 5 deletions
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,13 +523,16 @@ 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.
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)
526+
527+
// Global API. If a region is provided return an error.
528+
// The region is provided as a function argument instead of being set in the client configuration.
529+
if strings.Contains(servers[0].URL, "{region}") {
530+
return fmt.Errorf("this API does not support setting a region in the server URL, please check if the region can be specified as a function parameter")
531+
}
532+
526533
cfg.Servers = ServerConfigurations{
527534
{
528-
URL: cfgUrl,
535+
URL: servers[0].URL,
529536
Description: servers[0].Description,
530537
},
531538
}

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)