From fa7aec1936e0459567526cea43ae377b18b9839a Mon Sep 17 00:00:00 2001
From: Karel van Klink <karel.vanklink@geant.org>
Date: Mon, 26 May 2025 11:35:40 +0200
Subject: [PATCH] Move GSO service version config into oss-params

---
 gso/gso-services-config.json                  | 16 --------
 gso/oss-params-example.json                   | 16 ++++++++
 gso/settings.py                               | 37 ++++++++-----------
 gso/workflows/iptrunk/create_iptrunk.py       |  4 +-
 .../iptrunk/modify_trunk_interface.py         |  4 +-
 5 files changed, 35 insertions(+), 42 deletions(-)
 delete mode 100644 gso/gso-services-config.json

diff --git a/gso/gso-services-config.json b/gso/gso-services-config.json
deleted file mode 100644
index 364ec44e6..000000000
--- a/gso/gso-services-config.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-  "IP_TRUNK": {
-    "version": {
-      "1.0": "Base Version",
-      "1.1": "Minor Upgrade"
-    },
-    "default_version": "1.0"
-  },
-  "GEANT_IP": {
-    "version": {
-      "1.0": "Base Version",
-      "2.0": "Major Upgrade"
-    },
-    "default_version": "1.0"
-  }
-}
diff --git a/gso/oss-params-example.json b/gso/oss-params-example.json
index ea85bf24e..2b60d84c8 100644
--- a/gso/oss-params-example.json
+++ b/gso/oss-params-example.json
@@ -130,5 +130,21 @@
   "MOODI": {
     "host": "moodi.test.gap.geant.org",
     "moodi_enabled": true
+  },
+  "SERVICE_VERSIONS": {
+    "IP_TRUNK": {
+      "version": {
+        "1.0": "Base Version",
+        "1.1": "Minor Upgrade"
+      },
+      "default_version": "1.0"
+    },
+    "GEANT_IP": {
+      "version": {
+        "1.0": "Base Version",
+        "2.0": "Major Upgrade"
+      },
+      "default_version": "1.0"
+    }
   }
 }
diff --git a/gso/settings.py b/gso/settings.py
index 65af78ac8..8c1b0ec8e 100644
--- a/gso/settings.py
+++ b/gso/settings.py
@@ -228,6 +228,20 @@ class MoodiParams(BaseSettings):
     moodi_enabled: bool = False
 
 
+class ServiceConfig(BaseSettings):
+    """Base configuration object for setting version information of a service."""
+
+    version: dict[str, str]
+    default_version: str
+
+
+class ServiceVersionConfig(BaseSettings):
+    """Services offered by GSO that support multiple versions."""
+
+    IP_TRUNK: ServiceConfig
+    GEANT_IP: ServiceConfig
+
+
 class OSSParams(BaseSettings):
     """The set of parameters required for running GSO."""
 
@@ -242,6 +256,7 @@ class OSSParams(BaseSettings):
     KENTIK: KentikParams
     SENTRY: SentryParams | None = None
     MOODI: MoodiParams
+    SERVICE_VERSIONS: ServiceVersionConfig
 
 
 def load_oss_params() -> OSSParams:
@@ -250,29 +265,7 @@ def load_oss_params() -> OSSParams:
         return OSSParams(**json.loads(file.read()))
 
 
-class ServiceConfig(BaseSettings):
-    """Configurations for base gso service."""
-
-    version: dict[str, str]
-    default_version: str
-
-
-class GSOServiceConfig(BaseSettings):
-    """Configuration for the GSO service."""
-
-    IP_TRUNK: ServiceConfig
-    GEANT_IP: ServiceConfig
-
-
-def load_gso_service_config() -> GSOServiceConfig:
-    """Load the GSO service configuration from the environment variable."""
-    """Look for ``GSO_SERVICE_CONFIG`` in the environment and load the parameters from that file."""
-    with Path(os.environ["GSO_SERVICE_CONFIG"]).open(encoding="utf-8") as file:
-        return GSOServiceConfig(**json.loads(file.read()))
-
-
 celery_settings = CelerySettings()
 
 if __name__ == "__main__":
     logger.debug(load_oss_params())
-    logger.debug(load_gso_service_config())
diff --git a/gso/workflows/iptrunk/create_iptrunk.py b/gso/workflows/iptrunk/create_iptrunk.py
index cb9f83231..04b0d1459 100644
--- a/gso/workflows/iptrunk/create_iptrunk.py
+++ b/gso/workflows/iptrunk/create_iptrunk.py
@@ -62,7 +62,7 @@ from gso.services.subscriptions import (
     generate_unique_id,
     get_non_terminated_iptrunk_subscriptions,
 )
-from gso.settings import load_gso_service_config, load_oss_params
+from gso.settings import load_oss_params
 from gso.utils.helpers import (
     available_interfaces_choices,
     available_lags_choices,
@@ -86,7 +86,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator:
     routers = {str(router["subscription_id"]): router["description"] for router in active_and_provisioning_routers}
 
     # Get version choices from config
-    iptrunk_versions = list(load_gso_service_config().IP_TRUNK.version.keys())
+    iptrunk_versions = list(load_oss_params().SERVICE_VERSIONS.IP_TRUNK.version.keys())
     iptrunk_version_choices = Choice("Select version", [(v, v) for v in iptrunk_versions])  # type: ignore[arg-type]
 
     class CreateIptrunkForm(FormPage):
diff --git a/gso/workflows/iptrunk/modify_trunk_interface.py b/gso/workflows/iptrunk/modify_trunk_interface.py
index 391832078..1f3e9f543 100644
--- a/gso/workflows/iptrunk/modify_trunk_interface.py
+++ b/gso/workflows/iptrunk/modify_trunk_interface.py
@@ -30,7 +30,7 @@ from gso.products.product_blocks.iptrunk import (
 from gso.products.product_types.iptrunk import Iptrunk
 from gso.services.lso_client import LSOState, lso_interaction
 from gso.services.netbox_client import NetboxClient
-from gso.settings import load_gso_service_config
+from gso.settings import load_oss_params
 from gso.utils.helpers import (
     available_interfaces_choices,
     available_interfaces_choices_including_current_members,
@@ -88,7 +88,7 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
     subscription = Iptrunk.from_subscription(subscription_id)
 
     # Get version choices from config (single-select dropdown)
-    iptrunk_versions = list(load_gso_service_config().IP_TRUNK.version.keys())
+    iptrunk_versions = list(load_oss_params().SERVICE_VERSIONS.IP_TRUNK.version.keys())
     iptrunk_version_choices = Choice("Select version", [(v, v) for v in iptrunk_versions])  # type: ignore[arg-type]
 
     class ModifyIptrunkForm(FormPage):
-- 
GitLab