Skip to content

Commit 0915ef4

Browse files
authored
Region adjustment (#1256)
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 0915ef4

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
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: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,28 +113,44 @@ func TestConfigureRegion(t *testing.T) {
113113
isValid: true,
114114
},
115115
{
116-
desc: "valid_deprecated_global_with_specified_region",
116+
desc: "invalid_global_default_with_region",
117117
cfg: &Configuration{
118118
Region: "eu01",
119119
Servers: ServerConfigurations{
120120
ServerConfiguration{
121-
URL: "https://some-api.api.{region}stackit.cloud",
121+
URL: "https://some-api.api.stackit.cloud",
122122
Variables: map[string]ServerVariable{
123123
"region": {
124-
DefaultValue: "",
124+
DefaultValue: "global",
125125
EnumValues: []string{},
126126
},
127127
},
128128
},
129129
},
130130
},
131-
regionEnvVar: "",
132-
expectedServers: ServerConfigurations{
133-
ServerConfiguration{
134-
URL: "https://some-api.api.stackit.cloud",
131+
regionEnvVar: "",
132+
expectedServers: nil,
133+
isValid: false,
134+
},
135+
{
136+
desc: "invalid_deprecated_global_with_specified_region",
137+
cfg: &Configuration{
138+
Region: "eu01",
139+
Servers: ServerConfigurations{
140+
ServerConfiguration{
141+
URL: "https://some-api.api.{region}stackit.cloud",
142+
Variables: map[string]ServerVariable{
143+
"region": {
144+
DefaultValue: "",
145+
EnumValues: []string{},
146+
},
147+
},
148+
},
135149
},
136150
},
137-
isValid: true,
151+
regionEnvVar: "",
152+
expectedServers: nil,
153+
isValid: false,
138154
},
139155
{
140156
desc: "env_var_valid_region",

0 commit comments

Comments
 (0)