From: garciadeblas Date: Mon, 16 Sep 2024 07:37:20 +0000 (+0200) Subject: Support base64 encoded credentials for VIM creation X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F64%2F14564%2F1;p=osm%2FLCM.git Support base64 encoded credentials for VIM creation Change-Id: Iba58c3d71f2337af955b239fe43f5b96e9f8ca0e Signed-off-by: garciadeblas --- diff --git a/osm_lcm/lcm.py b/osm_lcm/lcm.py index f1770f5..5982250 100644 --- a/osm_lcm/lcm.py +++ b/osm_lcm/lcm.py @@ -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) diff --git a/osm_lcm/odu_libs/vim_mgmt.py b/osm_lcm/odu_libs/vim_mgmt.py index 3f7a5e7..e82bc34 100644 --- a/osm_lcm/odu_libs/vim_mgmt.py +++ b/osm_lcm/odu_libs/vim_mgmt.py @@ -16,8 +16,10 @@ ####################################################################################### -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,