Validate nfdeployment descriptor params
[pti/o2.git] / o2dms / api / dms_lcm_nfdeploymentdesc.py
index 5ed98b7..8024574 100644 (file)
@@ -12,6 +12,7 @@
 #  See the License for the specific language governing permissions and\r
 #  limitations under the License.\r
 \r
+import json\r
 from sqlalchemy import select\r
 import uuid\r
 from o2common.service import unit_of_work\r
@@ -56,12 +57,35 @@ def lcm_nfdeploymentdesc_create(
         id = str(uuid.uuid4())\r
         entity = NfDeploymentDesc(\r
             id, input['name'], deploymentManagerId, input['description'],\r
-            input['inputParams'], input['outputParams'], input['artifactUrl'])\r
+            input['inputParams'], input['outputParams'],\r
+            input['artifactRepoUrl'], input['artifactName'])\r
+        _nfdeploymentdesc_validate(entity)\r
         uow.nfdeployment_descs.add(entity)\r
         uow.commit()\r
     return id\r
 \r
 \r
+def _nfdeploymentdesc_validate(desc: NfDeploymentDesc):\r
+    try:\r
+        if desc.inputParams:\r
+            json.loads(desc.inputParams)\r
+        if desc.outputParams:\r
+            json.loads(desc.outputParams)\r
+        if not desc.deploymentManagerId:\r
+            raise Exception("Invalid deploymentManager Id")\r
+        if not desc.artifactRepoUrl:\r
+            raise Exception("Invalid artifactRepoUrl")\r
+        if not desc.artifactName:\r
+            raise Exception("Invalid artifactName")\r
+        return\r
+    except json.decoder.JSONDecodeError as e:\r
+        logger.debug("NfDeploymentDesc json error with: %s" % (str(e)))\r
+        raise e\r
+    except Exception as e:\r
+        logger.debug("NfDeploymentDesc validate error with: %s" % (str(e)))\r
+        raise e\r
+\r
+\r
 def lcm_nfdeploymentdesc_update(\r
         nfdeploymentdescriptorid: str,\r
         input: DmsLcmNfDeploymentDescriptorDTO.NfDeploymentDescriptor_update,\r
@@ -73,7 +97,8 @@ def lcm_nfdeploymentdesc_update(
         entity.description = input['description']\r
         entity.inputParams = input['inputParams']\r
         entity.outputParams = input['outputParams']\r
-        entity.artifactUrl = input['artifactUrl']\r
+        entity.artifactRepoUrl = input['artifactRepoUrl']\r
+        entity.artifactName = input['artifactName']\r
         uow.commit()\r
     return True\r
 \r