Skip to content

Commit

Permalink
feat: DM variables are now optional in the environments file (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: Alan Christie <[email protected]>
  • Loading branch information
alanbchristie and Alan Christie authored Mar 6, 2024
1 parent 14dd91b commit c0c9d86
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/developer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ And uninstall with::

.. note::
If you've set ``PYTHONPATH`` (see testing below) you will need to unset it
(``unset PYTHONPATH``). Otherrwise you will get a
(``unset PYTHONPATH``). Otherwise you will get a
**No files were found to uninstall.** error from ``pip``.

*******
Expand Down
22 changes: 13 additions & 9 deletions src/squonk2/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
# Keys required in each environment.
_KEYCLOAK_HOSTNAME_KEY: str = "keycloak-hostname"
_KEYCLOAK_REALM_KEY: str = "keycloak-realm"
_KEYCLOAK_DM_CLIENT_ID_KEY: str = "keycloak-dm-client-id"
_DM_HOSTNAME_KEY: str = "dm-hostname"
# Optional keys (extracted from ENV if not present)
_ADMIN_USER_KEY: str = "admin-user"
_ADMIN_PASSWORD_KEY: str = "admin-password"
# Optional keys
_KEYCLOAK_AS_CLIENT_ID_KEY: str = "keycloak-as-client-id"
_AS_HOSTNAME_KEY: str = "as-hostname"
_KEYCLOAK_DM_CLIENT_ID_KEY: str = "keycloak-dm-client-id"
_DM_HOSTNAME_KEY: str = "dm-hostname"


class Environment:
Expand Down Expand Up @@ -177,10 +177,6 @@ def __init__(self, environment: Optional[str]):
self.__get_config_value(_KEYCLOAK_HOSTNAME_KEY)
)
self.__keycloak_realm: str = str(self.__get_config_value(_KEYCLOAK_REALM_KEY))
self.__keycloak_dm_client_id: str = str(
self.__get_config_value(_KEYCLOAK_DM_CLIENT_ID_KEY)
)
self.__dm_hostname: str = str(self.__get_config_value(_DM_HOSTNAME_KEY))

# Get required keys, but allowing environment variables
# if not present in the file...
Expand All @@ -200,6 +196,12 @@ def __init__(self, environment: Optional[str]):
self.__as_hostname: Optional[str] = self.__get_config_value(
_AS_HOSTNAME_KEY, optional=True
)
self.__keycloak_dm_client_id: Optional[str] = self.__get_config_value(
_KEYCLOAK_DM_CLIENT_ID_KEY, optional=True
)
self.__dm_hostname: Optional[str] = self.__get_config_value(
_DM_HOSTNAME_KEY, optional=True
)

@property
def environment(self) -> str:
Expand Down Expand Up @@ -237,7 +239,7 @@ def keycloak_as_client_id(self) -> Optional[str]:
return self.__keycloak_as_client_id

@property
def keycloak_dm_client_id(self) -> str:
def keycloak_dm_client_id(self) -> Optional[str]:
"""Return the keycloak Data Manager client ID."""
return self.__keycloak_dm_client_id

Expand Down Expand Up @@ -274,17 +276,19 @@ def as_api(self) -> Optional[str]:
return ret_val

@property
def dm_hostname(self) -> str:
def dm_hostname(self) -> Optional[str]:
"""Return the keycloak hostname. This is the unmodified
value found in the environment.
"""
return self.__dm_hostname

@property
def dm_api(self) -> str:
def dm_api(self) -> Optional[str]:
"""Return the DM API. This is the environment hostname
with a 'http' prefix and '/data-manager-api' postfix.
"""
if not self.__dm_hostname:
return None
if not self.__dm_hostname.startswith("http"):
ret_val: str = f"https://{self.__dm_hostname}"
else:
Expand Down

0 comments on commit c0c9d86

Please sign in to comment.