Fix age key generation to convert pubkey to string
[osm/NBI.git] / osm_nbi / admin_topics.py
index 8960961..02a9737 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"))
@@ -369,6 +387,7 @@ class CommonVimWimSdn(BaseTopic):
         """
         super().format_on_new(content, project_id=project_id, make_public=make_public)
         content["schema_version"] = schema_version = "1.11"
+        content["key"] = "registered"
 
         # encrypt passwords
         if content.get(self.password_to_encrypt):
@@ -388,6 +407,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"
 
@@ -988,6 +1021,7 @@ class UserTopicAuth(UserTopic):
         try:
             if not content:
                 content = self.show(session, _id)
+
             indata = self._validate_input_edit(indata, content, force=session["force"])
             content = self.check_conflict_on_edit(session, content, indata, _id=_id)
             # self.format_on_edit(content, indata)
@@ -1000,6 +1034,8 @@ class UserTopicAuth(UserTopic):
                 or indata.get("project_role_mappings")
                 or indata.get("projects")
                 or indata.get("add_projects")
+                or indata.get("unlock")
+                or indata.get("renew")
             ):
                 return _id
             if indata.get("project_role_mappings") and (
@@ -1122,6 +1158,10 @@ class UserTopicAuth(UserTopic):
                     "old_password": indata.get("old_password"),
                     "add_project_role_mappings": mappings_to_add,
                     "remove_project_role_mappings": mappings_to_remove,
+                    "system_admin_id": indata.get("system_admin_id"),
+                    "unlock": indata.get("unlock"),
+                    "renew": indata.get("renew"),
+                    "session_user": session.get("username"),
                 }
             )
             data_to_send = {"_id": _id, "changes": indata}
@@ -1311,6 +1351,7 @@ class ProjectTopicAuth(ProjectTopic):
             self.format_on_new(
                 content, project_id=session["project_id"], make_public=session["public"]
             )
+            self.create_gitname(content, session)
             _id = self.auth.create_project(content)
             rollback.append({"topic": self.topic, "_id": _id})
             self._send_msg("created", content, not_send_msg=None)