Fix encryption of VIM account credentials 98/14498/1
authoryshah <shahithya.y@tataelxsi.co.in>
Mon, 12 Aug 2024 09:13:28 +0000 (09:13 +0000)
committeryshah <shahithya.y@tataelxsi.co.in>
Mon, 12 Aug 2024 09:13:28 +0000 (09:13 +0000)
Change-Id: I7f6e5250f29941898390a9a874a845dce5a2b37e
Signed-off-by: yshah <shahithya.y@tataelxsi.co.in>
osm_nbi/admin_topics.py

index 53f40e9..788ae3e 100644 (file)
@@ -352,6 +352,24 @@ class CommonVimWimSdn(BaseTopic):
                             schema_version=schema_version,
                             salt=final_content["_id"],
                         )
+            if edit_content.get("config", {}).get("credentials"):
+                cloud_credentials = edit_content["config"]["credentials"]
+                if cloud_credentials.get("clientSecret"):
+                    edit_content["config"]["credentials"][
+                        "clientSecret"
+                    ] = self.db.encrypt(
+                        edit_content["config"]["credentials"]["clientSecret"],
+                        schema_version=schema_version,
+                        salt=edit_content["_id"],
+                    )
+                elif cloud_credentials.get("SecretAccessKey"):
+                    edit_content["config"]["credentials"][
+                        "SecretAccessKey"
+                    ] = self.db.encrypt(
+                        edit_content["config"]["credentials"]["SecretAccessKey"],
+                        schema_version=schema_version,
+                        salt=edit_content["_id"],
+                    )
 
         # create edit operation
         final_content["_admin"]["operations"].append(self._create_operation("edit"))
@@ -388,6 +406,20 @@ class CommonVimWimSdn(BaseTopic):
                         schema_version=schema_version,
                         salt=content["_id"],
                     )
+        if content.get("config", {}).get("credentials"):
+            cloud_credentials = content["config"]["credentials"]
+            if cloud_credentials.get("clientSecret"):
+                content["config"]["credentials"]["clientSecret"] = self.db.encrypt(
+                    content["config"]["credentials"]["clientSecret"],
+                    schema_version=schema_version,
+                    salt=content["_id"],
+                )
+            elif cloud_credentials.get("SecretAccessKey"):
+                content["config"]["credentials"]["SecretAccessKey"] = self.db.encrypt(
+                    content["config"]["credentials"]["SecretAccessKey"],
+                    schema_version=schema_version,
+                    salt=content["_id"],
+                )
 
         content["_admin"]["operationalState"] = "PROCESSING"