From: Ricardo Dias Date: Wed, 30 May 2018 09:38:34 +0000 (+0100) Subject: mgr/dashboard: rest: add support for query params X-Git-Tag: v14.0.1~1229^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=547fdf96f82a4ea12f965f3f82cf9f3e0a469bb7;p=ceph.git mgr/dashboard: rest: add support for query params This change adds the support for query params in the @RESTController.Resource nd @RESTController.Collection decorators Signed-off-by: Ricardo Dias --- diff --git a/src/pybind/mgr/dashboard/controllers/__init__.py b/src/pybind/mgr/dashboard/controllers/__init__.py index ff82a4c86ba8..f9519baed2a5 100644 --- a/src/pybind/mgr/dashboard/controllers/__init__.py +++ b/src/pybind/mgr/dashboard/controllers/__init__.py @@ -580,6 +580,7 @@ class RESTController(BaseController): no_resource_id_params = False status = 200 method = None + query_params = None path = "" if func.__name__ in cls._method_mapping: @@ -598,7 +599,8 @@ class RESTController(BaseController): elif hasattr(func, "_collection_method_"): path = "/{}".format(func.__name__) - method = func._collection_method_ + method = func._collection_method_['method'] + query_params = func._collection_method_['query_params'] elif hasattr(func, "_resource_method_"): res_id_params = cls.infer_resource_id() @@ -609,7 +611,8 @@ class RESTController(BaseController): path += "/{}".format("/".join(res_id_params)) path += "/{}".format(func.__name__) - method = func._resource_method_ + method = func._resource_method_['method'] + query_params = func._resource_method_['query_params'] else: continue @@ -622,7 +625,8 @@ class RESTController(BaseController): .format(func.__name__)) func = cls._status_code_wrapper(func, status) - endp_func = Endpoint(method, path=path)(func) + endp_func = Endpoint(method, path=path, + query_params=query_params)(func) result.append(cls.Endpoint(cls, endp_func)) return result @@ -637,21 +641,27 @@ class RESTController(BaseController): return wrapper @staticmethod - def Resource(method=None): + def Resource(method=None, query_params=None): if not method: method = 'GET' def _wrapper(func): - func._resource_method_ = method + func._resource_method_ = { + 'method': method, + 'query_params': query_params + } return func return _wrapper @staticmethod - def Collection(method=None): + def Collection(method=None, query_params=None): if not method: method = 'GET' def _wrapper(func): - func._collection_method_ = method + func._collection_method_ = { + 'method': method, + 'query_params': query_params + } return func return _wrapper