From: shahithya Date: Tue, 15 Oct 2024 08:01:44 +0000 (+0000) Subject: Fix get credentials from cluster and KSU delete with OKA X-Git-Tag: v17.0.0~17 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=8bded11b54f3786bf41f9f2174b9dfe49d179706;p=osm%2FNBI.git Fix get credentials from cluster and KSU delete with OKA Change-Id: I05f196143ab6185363256641f8d0a8b3a24ca022 Signed-off-by: yshah --- diff --git a/osm_nbi/k8s_topics.py b/osm_nbi/k8s_topics.py index 6e5e66a..ea18a58 100644 --- a/osm_nbi/k8s_topics.py +++ b/osm_nbi/k8s_topics.py @@ -465,9 +465,37 @@ class K8sTopic(BaseTopic): filter_db = self._get_project_filter(session) # To allow project&user addressing by name AS WELL AS _id filter_db[BaseTopic.id_field(self.topic, _id)] = _id - data = self.db.get_one(self.topic, filter_db) self._send_msg(item, {"_id": _id}) - return data + + data = self.db.get_one(self.topic, filter_db) + credentials = data["credentials"] + + file_pkg = None + current_path = _id + + self.fs.file_delete(current_path, ignore_non_exist=True) + self.fs.mkdir(current_path) + filename = "credentials.yaml" + + file_path = (current_path, filename) + self.logger.info("File path: {}".format(file_path)) + file_pkg = self.fs.file_open(file_path, "a+b") + + credentials_yaml = yaml.safe_dump( + credentials, indent=4, default_flow_style=False + ) + file_pkg.write(credentials_yaml.encode(encoding="utf-8")) + + if file_pkg: + file_pkg.close() + file_pkg = None + + self.fs.sync(from_path=current_path) + + return ( + self.fs.file_open((current_path, filename), "rb"), + "text/plain", + ) def update_cluster(self, session, _id, item, indata): if not self.multiproject: @@ -671,6 +699,7 @@ class KsusTopic(BaseTopic): oka_flag = "" if oka["_id"]: oka_flag = "_id" + oka["sw_catalog_path"] = "" elif oka["sw_catalog_path"]: oka_flag = "sw_catalog_path" @@ -924,7 +953,10 @@ class KsusTopic(BaseTopic): for ksus in data: if ksus["_id"] != _id: for okas in ksus["oka"]: - if okas["_id"] not in existing_oka: + self.logger.info("OKA: {}".format(okas)) + if okas.get("sw_catalog_path", ""): + continue + elif okas["_id"] not in existing_oka: existing_oka.append(okas["_id"]) if used_oka: diff --git a/osm_nbi/nbi.py b/osm_nbi/nbi.py index 1c8b035..3fd3745 100644 --- a/osm_nbi/nbi.py +++ b/osm_nbi/nbi.py @@ -1780,9 +1780,10 @@ class Server(object): api_req=True, ) elif topic == "clusters" and item == "get_creds": - outdata = self.engine.get_cluster_info( + file, _format = self.engine.get_cluster_info( engine_session, engine_topic, _id, item ) + outdata = file else: if item == "reports": # TODO check that project_id (_id in this context) has permissions