diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 0cab26e74..1053a9d2e 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,3 +1,9 @@ +## v0.15.0 (2025-01-02) + +- **Breaking Change:**: `ConfigureRegion` returns an error if a region is specified for a global URL. + +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. + ## v0.14.0 (2024-10-10) - **Feature:**: Added `IntermediateStateReached` to `AsyncActionHandler` that can be used to check for an intermediate state when executing the wait function of a wait handler. diff --git a/core/config/config.go b/core/config/config.go index 82a7bac9d..7bf2ed069 100644 --- a/core/config/config.go +++ b/core/config/config.go @@ -5,6 +5,7 @@ package config import ( "context" "fmt" + "log" "net/http" "os" "strings" @@ -478,7 +479,10 @@ func (c *Configuration) ServerURLWithContext(ctx context.Context, endpoint strin // ConfigureRegion configures the API server urls with the user specified region. // Does nothing if a custom endpoint is provided. // Throws an error if no region is given or if the region is not valid +// Throws an error if a region is given for a global url. func ConfigureRegion(cfg *Configuration) error { + 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." + + " Once all services have migrated, the methods to specify the region in the client configuration will be removed.") if cfg.setCustomEndpoint { return nil } @@ -519,7 +523,12 @@ func ConfigureRegion(cfg *Configuration) error { // Region is not available. return fmt.Errorf("the provided region is not available for this API, available regions are: %s", availableRegions) } - // Global API. The provided region is ignored. + // Global API. + // If a region is provided by the user via WithRegion() or via environment variable return an error. + // The region is provided as a function argument instead of being set in the client configuration. + if cfg.Region != "" { + 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") + } // If the url is a template, generated using deprecated config.json, the region variable is replaced // If the url is already configured, there is no region variable and it remains the same cfgUrl := strings.Replace(servers[0].URL, "{region}", "", -1) diff --git a/core/config/config_test.go b/core/config/config_test.go index 2cb0f4404..6088aa507 100644 --- a/core/config/config_test.go +++ b/core/config/config_test.go @@ -113,28 +113,44 @@ func TestConfigureRegion(t *testing.T) { isValid: true, }, { - desc: "valid_deprecated_global_with_specified_region", + desc: "invalid_global_default_with_region", cfg: &Configuration{ Region: "eu01", Servers: ServerConfigurations{ ServerConfiguration{ - URL: "https://some-api.api.{region}stackit.cloud", + URL: "https://some-api.api.stackit.cloud", Variables: map[string]ServerVariable{ "region": { - DefaultValue: "", + DefaultValue: "global", EnumValues: []string{}, }, }, }, }, }, - regionEnvVar: "", - expectedServers: ServerConfigurations{ - ServerConfiguration{ - URL: "https://some-api.api.stackit.cloud", + regionEnvVar: "", + expectedServers: nil, + isValid: false, + }, + { + desc: "invalid_deprecated_global_with_specified_region", + cfg: &Configuration{ + Region: "eu01", + Servers: ServerConfigurations{ + ServerConfiguration{ + URL: "https://some-api.api.{region}stackit.cloud", + Variables: map[string]ServerVariable{ + "region": { + DefaultValue: "", + EnumValues: []string{}, + }, + }, + }, }, }, - isValid: true, + regionEnvVar: "", + expectedServers: nil, + isValid: false, }, { desc: "env_var_valid_region",