Fix get credentials from cluster and KSU delete with OKA

Change-Id: I05f196143ab6185363256641f8d0a8b3a24ca022
Signed-off-by: yshah <shahithya.y@tataelxsi.co.in>
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 @@
             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 @@
             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 @@
                 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: