validate expression of rule in API

pull/42/MERGE
13621160019@163.com 2021-06-11 17:09:36 +08:00
parent 4a33acbbee
commit 1bee235c6d
1 changed files with 10 additions and 0 deletions

View File

@ -115,6 +115,11 @@ class RuleCollection:
title='API.BAD_REQUEST', title='API.BAD_REQUEST',
description='API.INVALID_EXPRESSION') description='API.INVALID_EXPRESSION')
expression = str.strip(new_values['data']['expression']) expression = str.strip(new_values['data']['expression'])
# validate expression in json
try:
json.loads(expression)
except Exception as ex:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description=ex)
if 'message_template' not in new_values['data'].keys() or \ if 'message_template' not in new_values['data'].keys() or \
not isinstance(new_values['data']['message_template'], str) or \ not isinstance(new_values['data']['message_template'], str) or \
@ -305,6 +310,11 @@ class RuleItem:
title='API.BAD_REQUEST', title='API.BAD_REQUEST',
description='API.INVALID_EXPRESSION') description='API.INVALID_EXPRESSION')
expression = str.strip(new_values['data']['expression']) expression = str.strip(new_values['data']['expression'])
# validate expression in json
try:
json.loads(expression)
except Exception as ex:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description=ex)
if 'message_template' not in new_values['data'].keys() or \ if 'message_template' not in new_values['data'].keys() or \
not isinstance(new_values['data']['message_template'], str) or \ not isinstance(new_values['data']['message_template'], str) or \