11
11
Do not edit the class manually.
12
12
""" # noqa: E501 docstring might be too long
13
13
14
+ import os
15
+
14
16
15
17
class HostConfiguration :
16
18
def __init__ (
@@ -22,7 +24,14 @@ def __init__(
22
24
server_operation_variables = None ,
23
25
ignore_operation_servers = False ,
24
26
) -> None :
25
- """Constructor"""
27
+ print (
28
+ "WARNING: STACKIT will move to a new way of specifying regions, where the region is provided\n " ,
29
+ "as a function argument instead of being set in the client configuration.\n "
30
+ "Once all services have migrated, the methods to specify the region in the client configuration "
31
+ "will be removed." ,
32
+ )
33
+ """Constructor
34
+ """
26
35
self ._base_path = "https://resource-manager.api.stackit.cloud"
27
36
"""Default Base url
28
37
"""
@@ -63,6 +72,7 @@ def get_host_from_settings(self, index, variables=None, servers=None):
63
72
:param index: array index of the host settings
64
73
:param variables: hash of variable and the corresponding value
65
74
:param servers: an array of host settings or None
75
+ :error: if a region is given for a global url
66
76
:return: URL based on host settings
67
77
"""
68
78
if index is None :
@@ -81,8 +91,25 @@ def get_host_from_settings(self, index, variables=None, servers=None):
81
91
82
92
url = server ["url" ]
83
93
94
+ # check if environment variable was provided for region
95
+ # if nothing was set this is None
96
+ region_env = os .environ .get ("STACKIT_REGION" )
97
+
84
98
# go through variables and replace placeholders
85
99
for variable_name , variable in server .get ("variables" , {}).items ():
100
+ # If a region is provided by the user for a global url
101
+ # return an error (except for providing via environment variable).
102
+ # The region is provided as a function argument instead of being set in the client configuration.
103
+ if (
104
+ variable_name == "region"
105
+ and (variable ["default_value" ] == "global" or variable ["default_value" ] == "" )
106
+ and region_env is None
107
+ and variables .get (variable_name ) is not None
108
+ ):
109
+ raise ValueError (
110
+ "this API does not support setting a region in the the client configuration, "
111
+ "please check if the region can be specified as a function parameter"
112
+ )
86
113
used_value = variables .get (variable_name , variable ["default_value" ])
87
114
88
115
if "enum_values" in variable and used_value not in variable ["enum_values" ]:
0 commit comments