Skip to content

Region adjustment #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2025
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
20 changes: 20 additions & 0 deletions templates/python/configuration.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class HostConfiguration:
server_operation_index=None, server_operation_variables=None,
ignore_operation_servers=False,
) -> None:
print("WARNING: STACKIT will move to a new way of specifying regions, where the region is provided\n",
"as a function argument instead of being set in the client configuration.\n"
"Once all services have migrated, the methods to specify the region in the client configuration "
"will be removed.")
"""Constructor
"""
self._base_path = "{{{basePath}}}"
Expand Down Expand Up @@ -67,6 +71,7 @@ class HostConfiguration:
:param index: array index of the host settings
:param variables: hash of variable and the corresponding value
:param servers: an array of host settings or None
:error: if a region is given for a global url
:return: URL based on host settings
"""
if index is None:
Expand All @@ -84,8 +89,23 @@ class HostConfiguration:

url = server['url']

# check if environment variable was provided for region
# if nothing was set this is None
region_env = os.environ.get("STACKIT_REGION")

# go through variables and replace placeholders
for variable_name, variable in server.get('variables', {}).items():
# If a region is provided by the user for a global url
# return an error (except for providing via environment variable).
# The region is provided as a function argument instead of being set in the client configuration.
if variable_name == 'region' and \
(variable['default_value'] == 'global' or variable['default_value'] == '') and \
region_env is None and \
variables.get(variable_name) is not None:
raise ValueError(
"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"
)
used_value = variables.get(
variable_name, variable['default_value'])

Expand Down
3 changes: 3 additions & 0 deletions templates/python/pyproject.mustache
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[project]
name = "{{{pythonPackageName}}}"

[tool.poetry]
name = "{{{pythonPackageName}}}"
version = "v0.0.1a"
Expand Down
Loading