From e0e98d8c53a14158105375aa84f489602caa93a8 Mon Sep 17 00:00:00 2001 From: Bin Yang Date: Mon, 24 Jan 2022 14:15:55 +0800 Subject: [PATCH] Validate nfdeployment descriptor params Issue-ID: INF-258 Signed-off-by: Bin Yang Change-Id: I8c8891c4236272f273fc66446770e02857728853 --- o2dms/api/dms_lcm_nfdeploymentdesc.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/o2dms/api/dms_lcm_nfdeploymentdesc.py b/o2dms/api/dms_lcm_nfdeploymentdesc.py index 02621d6..e5b66ca 100644 --- a/o2dms/api/dms_lcm_nfdeploymentdesc.py +++ b/o2dms/api/dms_lcm_nfdeploymentdesc.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import json from sqlalchemy import select import uuid from o2common.service import unit_of_work @@ -58,11 +59,27 @@ def lcm_nfdeploymentdesc_create( id, input['name'], deploymentManagerId, input['description'], input['inputParams'], input['outputParams'], input['artifactRepoUrl'], input['artifactName']) + _nfdeploymentdesc_validate(entity) uow.nfdeployment_descs.add(entity) uow.commit() return id +def _nfdeploymentdesc_validate(desc: NfDeploymentDesc): + try: + json.loads( + desc['inputParams']) if desc['inputParams'] else None + json.loads( + desc['outputParams']) if desc['outputParams'] else None + return + except json.decoder.JSONDecodeError as e: + logger.debug("NfDeploymentDesc validate error with: %s" % (str(e))) + raise e + except Exception as e: + logger.debug("NfDeploymentDesc validate error with: %s" % (str(e))) + raise e + + def lcm_nfdeploymentdesc_update( nfdeploymentdescriptorid: str, input: DmsLcmNfDeploymentDescriptorDTO.NfDeploymentDescriptor_update, -- 2.16.6