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://mongodb-flex-service.api.eu01.stackit.cloud"
2837 """Default Base url
2938 """
@@ -65,6 +74,7 @@ def get_host_from_settings(self, index, variables=None, servers=None):
6574 :param index: array index of the host settings
6675 :param variables: hash of variable and the corresponding value
6776 :param servers: an array of host settings or None
77+ :error: if a region is given for a global url
6878 :return: URL based on host settings
6979 """
7080 if index is None :
@@ -83,8 +93,25 @@ def get_host_from_settings(self, index, variables=None, servers=None):
8393
8494 url = server ["url" ]
8595
96+ # check if environment variable was provided for region
97+ # if nothing was set this is None
98+ region_env = os .environ .get ("STACKIT_REGION" )
99+
86100 # go through variables and replace placeholders
87101 for variable_name , variable in server .get ("variables" , {}).items ():
102+ # If a region is provided by the user for a global url
103+ # return an error (except for providing via environment variable).
104+ # The region is provided as a function argument instead of being set in the client configuration.
105+ if (
106+ variable_name == "region"
107+ and (variable ["default_value" ] == "global" or variable ["default_value" ] == "" )
108+ and region_env is None
109+ and variables .get (variable_name ) is not None
110+ ):
111+ raise ValueError (
112+ "this API does not support setting a region in the the client configuration, "
113+ "please check if the region can be specified as a function parameter"
114+ )
88115 used_value = variables .get (variable_name , variable ["default_value" ])
89116
90117 if "enum_values" in variable and used_value not in variable ["enum_values" ]:
0 commit comments