1212 Do not edit the class manually.
1313""" # noqa: E501 docstring might be too long
1414
15+ import os
16+
1517
1618class HostConfiguration :
1719 def __init__ (
@@ -23,7 +25,14 @@ def __init__(
2325 server_operation_variables = None ,
2426 ignore_operation_servers = False ,
2527 ) -> None :
26- """Constructor"""
28+ print (
29+ "WARNING: STACKIT will move to a new way of specifying regions, where the region is provided\n " ,
30+ "as a function argument instead of being set in the client configuration.\n "
31+ "Once all services have migrated, the methods to specify the region in the client configuration "
32+ "will be removed." ,
33+ )
34+ """Constructor
35+ """
2736 self ._base_path = "https://dns.api.stackit.cloud"
2837 """Default Base url
2938 """
@@ -64,6 +73,7 @@ def get_host_from_settings(self, index, variables=None, servers=None):
6473 :param index: array index of the host settings
6574 :param variables: hash of variable and the corresponding value
6675 :param servers: an array of host settings or None
76+ :error: if a region is given for a global url
6777 :return: URL based on host settings
6878 """
6979 if index is None :
@@ -82,8 +92,25 @@ def get_host_from_settings(self, index, variables=None, servers=None):
8292
8393 url = server ["url" ]
8494
95+ # check if environment variable was provided for region
96+ # if nothing was set this is None
97+ region_env = os .environ .get ("STACKIT_REGION" )
98+
8599 # go through variables and replace placeholders
86100 for variable_name , variable in server .get ("variables" , {}).items ():
101+ # If a region is provided by the user for a global url
102+ # return an error (except for providing via environment variable).
103+ # The region is provided as a function argument instead of being set in the client configuration.
104+ if (
105+ variable_name == "region"
106+ and (variable ["default_value" ] == "global" or variable ["default_value" ] == "" )
107+ and region_env is None
108+ and variables .get (variable_name ) is not None
109+ ):
110+ raise ValueError (
111+ "this API does not support setting a region in the the client configuration, "
112+ "please check if the region can be specified as a function parameter"
113+ )
87114 used_value = variables .get (variable_name , variable ["default_value" ])
88115
89116 if "enum_values" in variable and used_value not in variable ["enum_values" ]:
0 commit comments