+def _check_subscription_filter(filter: str):
+ if not filter:
+ return
+
+ def _sub_filter_checking(sub_filter: str):
+ exprs = sub_filter.split(';')
+ objectType = False
+ objectTypeValue = ''
+ for expr in exprs:
+ expr_strip = expr.strip(' ()')
+ items = expr_strip.split(',')
+ if len(items) < 3:
+ raise BadRequestException("invalid filter {}".format(expr))
+ item_key = items[1].strip()
+ if item_key != 'objectType':
+ continue
+ item_op = items[0].strip()
+ if item_op != 'eq':
+ raise BadRequestException(
+ "Filter objectType only support 'eq' operation")
+ objectType = True
+ objectTypeValue = items[2].strip()
+ if not objectType:
+ # if there has no objectType specific, by default is ResourceInfo
+ check_filter(ocloud.Resource, sub_filter)
+ # return 'ResourceInfo'
+ return
+ if objectTypeValue == 'ResourceTypeInfo':
+ check_filter(ocloud.ResourceType, sub_filter)
+ elif objectTypeValue == 'ResourcePoolInfo':
+ check_filter(ocloud.ResourcePool, sub_filter)
+ elif objectTypeValue == 'DeploymentManagerInfo':
+ check_filter(ocloud.DeploymentManager, sub_filter)
+ elif objectTypeValue == 'CloudInfo':
+ check_filter(ocloud.Ocloud, sub_filter)
+ elif objectTypeValue == 'ResourceInfo':
+ check_filter(ocloud.Resource, sub_filter)
+ else:
+ raise BadRequestException(
+ "Filter ObjectType {} not support.".format(items[2]))
+ # return objectTypeValue
+ filter_strip = filter.strip(' []')
+ filter_list = filter_strip.split('|')
+ # check_duplication = dict()
+ for sub_filter in filter_list:
+ _sub_filter_checking(sub_filter)
+ # obj_type = _sub_filter_checking(sub_filter)
+ # if obj_type not in check_duplication:
+ # check_duplication[obj_type] = 0
+ # check_duplication[obj_type] += 1
+ # if check_duplication[obj_type] > 1:
+ # raise BadRequestException(
+ # "Filter objectType {} only support one in each."
+ # .format(obj_type))
+
+