From: Zhang Rong(Jon) Date: Wed, 2 Nov 2022 05:27:24 +0000 (+0800) Subject: Add wrong attributes check on selector X-Git-Tag: 2.0.0-rc1~9 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=e491f4c2a7a762eba966c77ae14b9ad6859220cc;p=pti%2Fo2.git Add wrong attributes check on selector Issue-ID: INF-302 Signed-off-by: Zhang Rong(Jon) Change-Id: I98c96532100373465ab9e0f66a0a6577a1943a2a --- diff --git a/o2common/views/pagination_route.py b/o2common/views/pagination_route.py index c595d9f..a6c5495 100644 --- a/o2common/views/pagination_route.py +++ b/o2common/views/pagination_route.py @@ -13,7 +13,8 @@ # limitations under the License. from urllib.parse import urlparse -from flask import abort + +from o2common.views.route_exception import BadRequestException from o2common.helper import o2logging logger = o2logging.get_logger(__name__) @@ -28,7 +29,8 @@ def link_header(full_path: str, ret): page_current = ret.pop('page_current') if page_current > page_total: - abort(400, "Page size {} bad request.".format(page_current)) + raise BadRequestException( + "Page size {} bad request.".format(page_current)) if 0 == count: return [], {'X-Total-Count': count} diff --git a/o2common/views/route.py b/o2common/views/route.py index 0941f58..08621ff 100644 --- a/o2common/views/route.py +++ b/o2common/views/route.py @@ -30,6 +30,8 @@ from flask_restx.model import Model from flask_restx.fields import List, Nested, String from flask_restx.utils import unpack +from o2common.views.route_exception import BadRequestException + from o2common.helper import o2logging logger = o2logging.get_logger(__name__) @@ -128,11 +130,13 @@ class o2_marshal_with(marshal_with): mask_val = '' if 'all_fields' in kwargs: all_fields_without_space = kwargs['all_fields'].replace(" ", "") - all_fields = all_fields_without_space.lower() - if 'true' == all_fields: - selector = self.__gen_selector_from_model_with_value( - self.fields) - mask_val = self.__gen_mask_from_selector(selector) + logger.info('all_fields selector value is {}'.format( + all_fields_without_space)) + # all_fields = all_fields_without_space.lower() + # if 'true' == all_fields: + selector = self.__gen_selector_from_model_with_value( + self.fields) + mask_val = self.__gen_mask_from_selector(selector) elif 'fields' in kwargs and kwargs['fields'] != '': fields_without_space = kwargs['fields'].replace(" ", "") @@ -211,6 +215,9 @@ class o2_marshal_with(marshal_with): if '/' in f: self.__update_selector_tree_value(selector, f, val) continue + if f not in self.fields: + raise BadRequestException( + 'Selector attribute {} not found'.format(f)) selector[f] = val def __update_selector_tree_value(self, m: dict, filter: str, val: bool):