Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
11 changes: 10 additions & 1 deletion core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package config
import (
"context"
"fmt"
"log"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
32 changes: 24 additions & 8 deletions core/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading