Validate nfdeployment descriptor params
[pti/o2.git] / o2dms / api / dms_lcm_nfdeploymentdesc.py
index 02621d6..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
@@ -58,11 +59,33 @@ def lcm_nfdeploymentdesc_create(
             id, input['name'], deploymentManagerId, input['description'],\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