Skip to content

Commit 07ae963

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 <alexander.dahmen@inovex.de>
1 parent 59a929d commit 07ae963

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

templates/python/configuration.mustache

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class HostConfiguration:
88
server_operation_index=None, server_operation_variables=None,
99
ignore_operation_servers=False,
1010
) -> None:
11+
print("WARNING: STACKIT will move to a new way of specifying regions, where the region is provided\n",
12+
"as a function argument instead of being set in the client configuration.\n"
13+
"Once all services have migrated, the methods to specify the region in the client configuration "
14+
"will be removed.")
1115
"""Constructor
1216
"""
1317
self._base_path = "{{{basePath}}}"
@@ -67,6 +71,7 @@ class HostConfiguration:
6771
:param index: array index of the host settings
6872
:param variables: hash of variable and the corresponding value
6973
:param servers: an array of host settings or None
74+
:error: if a region is given for a global url
7075
:return: URL based on host settings
7176
"""
7277
if index is None:
@@ -84,8 +89,23 @@ class HostConfiguration:
8489

8590
url = server['url']
8691

92+
# check if environment variable was provided for region
93+
# if nothing was set this is None
94+
region_env = os.environ.get("STACKIT_REGION")
95+
8796
# go through variables and replace placeholders
8897
for variable_name, variable in server.get('variables', {}).items():
98+
# If a region is provided by the user for a global url
99+
# return an error (except for providing via environment variable).
100+
# The region is provided as a function argument instead of being set in the client configuration.
101+
if variable_name == 'region' and \
102+
(variable['default_value'] == 'global' or variable['default_value'] == '') and \
103+
region_env is None and \
104+
variables.get(variable_name) is not None:
105+
raise ValueError(
106+
"this API does not support setting a region in the the client configuration, "
107+
"please check if the region can be specified as a function parameter"
108+
)
89109
used_value = variables.get(
90110
variable_name, variable['default_value'])
91111

0 commit comments

Comments
 (0)