Support base64 encoded credentials for VIM creation 64/14564/1
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 16 Sep 2024 07:37:20 +0000 (09:37 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 16 Sep 2024 07:39:11 +0000 (09:39 +0200)
Change-Id: Iba58c3d71f2337af955b239fe43f5b96e9f8ca0e
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osm_lcm/lcm.py
osm_lcm/odu_libs/vim_mgmt.py

index f1770f5..5982250 100644 (file)
@@ -657,7 +657,7 @@ class Lcm:
             self.logger.debug("Db Vim: {}".format(db_vim))
             if command in ("create", "created"):
                 self.logger.debug("Main config: {}".format(self.main_config.to_dict()))
-                if "credentials" in vim_config:
+                if "credentials" or "credentials_base64" in vim_config:
                     self.logger.info("Vim add cloud credentials")
                     task = asyncio.ensure_future(
                         self.cloud_credentials.add(op_id, op_params, db_vim)
index 3f7a5e7..e82bc34 100644 (file)
 #######################################################################################
 
 
-import yaml
+import base64
 import json
+import yaml
+from osm_lcm.lcm_utils import LcmException
 
 
 async def create_cloud_credentials(self, op_id, op_params, content):
@@ -37,7 +39,15 @@ async def create_cloud_credentials(self, op_id, op_params, content):
     secret_name = workflow_name
     secret_namespace = "osm-workflows"
     secret_key = "creds"
-    secret_value = json.dumps(content["config"]["credentials"], indent=2)
+    cloud_config = content.get("config", {})
+    if "credentials_base64" in cloud_config:
+        secret_value = base64.b64decode(cloud_config["credentials_base64"]).decode(
+            "utf-8"
+        )
+    elif "credentials" in cloud_config:
+        secret_value = json.dumps(cloud_config["credentials"], indent=2)
+    else:
+        raise LcmException("No credentials in VIM/cloud config")
     await self.create_secret(
         secret_name,
         secret_namespace,
@@ -139,7 +149,15 @@ async def update_cloud_credentials(self, op_id, op_params, content):
     secret_name = workflow_name
     secret_namespace = "osm-workflows"
     secret_key = "creds"
-    secret_value = json.dumps(content["config"]["credentials"], indent=2)
+    cloud_config = content.get("config", {})
+    if "credentials_base64" in cloud_config:
+        secret_value = base64.b64decode(cloud_config["credentials_base64"]).decode(
+            "utf-8"
+        )
+    elif "credentials" in cloud_config:
+        secret_value = json.dumps(cloud_config["credentials"], indent=2)
+    else:
+        raise LcmException("No credentials in VIM/cloud config")
     await self.create_secret(
         secret_name,
         secret_namespace,