From a448945a5ea860dd35e4a9f4249d633dae86d933 Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Tue, 6 Aug 2024 09:31:53 +0200 Subject: [PATCH] Add public hostname and environment to general OSS params --- gso/__init__.py | 4 ++-- gso/oss-params-example.json | 7 ++++--- gso/settings.py | 25 +++++++++++++------------ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/gso/__init__.py b/gso/__init__.py index 2df27bcb..a3abcf10 100644 --- a/gso/__init__.py +++ b/gso/__init__.py @@ -47,8 +47,8 @@ def init_cli_app() -> typer.Typer: def init_sentry() -> None: """Only initialize Sentry if not in testing mode.""" - if os.getenv("TESTING", "false").lower() == "false" and (sentry_config := load_oss_params().SENTRY): - sentry_sdk.init(dsn=sentry_config.DSN, environment=sentry_config.environment, traces_sample_rate=1.0) + if os.getenv("TESTING", "false").lower() == "false" and (oss_params := load_oss_params()): + sentry_sdk.init(dsn=oss_params.SENTRY.DSN, environment=oss_params.GENERAL.environment, traces_sample_rate=1.0) init_sentry() diff --git a/gso/oss-params-example.json b/gso/oss-params-example.json index f9523a72..069672ff 100644 --- a/gso/oss-params-example.json +++ b/gso/oss-params-example.json @@ -1,7 +1,9 @@ { "GENERAL": { "public_hostname": "https://gap.geant.org", - "isis_high_metric": 999999 + "internal_hostname": "http://gso-api:9000", + "isis_high_metric": 999999, + "environment": "development" }, "NETBOX": { "api": "https://127.0.0.1:8000", @@ -119,7 +121,6 @@ "md5_password": "snmp password" }, "SENTRY": { - "DSN": "https://sentry-dsn-url", - "environment": "development" + "DSN": "https://sentry-dsn-url" } } diff --git a/gso/settings.py b/gso/settings.py index c105fffc..6c6378dd 100644 --- a/gso/settings.py +++ b/gso/settings.py @@ -21,13 +21,24 @@ from gso.utils.shared_enums import PortNumber logger = logging.getLogger(__name__) +class EnvironmentEnum(strEnum): + """The different environments in which the GSO system can run.""" + + DEVELOPMENT = "development" + TEST = "test" + UAT = "uat" + PRODUCTION = "production" + + class GeneralParams(BaseSettings): """General parameters for a :term:`GSO` configuration file.""" public_hostname: str - """The hostname that :term:`GSO` is publicly served at, used for building the callback URL that the provisioning - proxy uses.""" + """The hostname that :term:`GSO` is publicly served at, used for building callback URLs for public use.""" + internal_hostname: str + """The hostname of :term:`GSO` that is for internal use, such as the provisioning proxy.""" isis_high_metric: int + environment: EnvironmentEnum class CeleryParams(BaseSettings): @@ -192,20 +203,10 @@ class KentikParams(BaseSettings): md5_password: str -class EnvironmentEnum(strEnum): - """The different environments in which the GSO system can run.""" - - DEVELOPMENT = "development" - TEST = "test" - UAT = "uat" - PRODUCTION = "production" - - class SentryParams(BaseSettings): """Settings for Sentry.""" DSN: str - environment: EnvironmentEnum class OSSParams(BaseSettings): -- GitLab