From: Aashish Sharma Date: Tue, 1 Jun 2021 05:09:24 +0000 (+0530) Subject: mgr/dashboard: API Version changes do not apply to pre-defined methods (list, create... X-Git-Tag: v17.1.0~1790^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F41395%2Fhead;p=ceph.git mgr/dashboard: API Version changes do not apply to pre-defined methods (list, create etc.) Methods like list(), create(), get() etc doesn't get applied the version.Also for the endpoints that get the version changed, the docs and the request header has still the version v1.0+ in them. So with the version reduced it gives 415 error when trying to make the request. This PR fixes this issue. Fixes: https://tracker.ceph.com/issues/50855 Signed-off-by: Aashish Sharma --- diff --git a/src/pybind/mgr/dashboard/controllers/__init__.py b/src/pybind/mgr/dashboard/controllers/__init__.py index babfbb4296d..56cace368ce 100755 --- a/src/pybind/mgr/dashboard/controllers/__init__.py +++ b/src/pybind/mgr/dashboard/controllers/__init__.py @@ -858,10 +858,10 @@ class RESTController(BaseController): cls._update_endpoint_params_method_map( func, res_id_params, endpoint_params) - elif hasattr(func, "collection_method"): + elif hasattr(func, "__collection_method__"): cls._update_endpoint_params_collection_map(func, endpoint_params) - elif hasattr(func, "resource_method"): + elif hasattr(func, "__resource_method__"): cls._update_endpoint_params_resource_method( res_id_params, endpoint_params, func) @@ -900,27 +900,27 @@ class RESTController(BaseController): else: path_params = ["{{{}}}".format(p) for p in res_id_params] endpoint_params['path'] += "/{}".format("/".join(path_params)) - if func.resource_method['path']: - endpoint_params['path'] += func.resource_method['path'] + if func.__resource_method__['path']: + endpoint_params['path'] += func.__resource_method__['path'] else: endpoint_params['path'] += "/{}".format(func.__name__) - endpoint_params['status'] = func.resource_method['status'] - endpoint_params['method'] = func.resource_method['method'] - endpoint_params['version'] = func.resource_method['version'] - endpoint_params['query_params'] = func.resource_method['query_params'] + endpoint_params['status'] = func.__resource_method__['status'] + endpoint_params['method'] = func.__resource_method__['method'] + endpoint_params['version'] = func.__resource_method__['version'] + endpoint_params['query_params'] = func.__resource_method__['query_params'] if not endpoint_params['sec_permissions']: endpoint_params['permission'] = cls._permission_map[endpoint_params['method']] @classmethod def _update_endpoint_params_collection_map(cls, func, endpoint_params): - if func.collection_method['path']: - endpoint_params['path'] = func.collection_method['path'] + if func.__collection_method__['path']: + endpoint_params['path'] = func.__collection_method__['path'] else: endpoint_params['path'] = "/{}".format(func.__name__) - endpoint_params['status'] = func.collection_method['status'] - endpoint_params['method'] = func.collection_method['method'] - endpoint_params['query_params'] = func.collection_method['query_params'] - endpoint_params['version'] = func.collection_method['version'] + endpoint_params['status'] = func.__collection_method__['status'] + endpoint_params['method'] = func.__collection_method__['method'] + endpoint_params['query_params'] = func.__collection_method__['query_params'] + endpoint_params['version'] = func.__collection_method__['version'] if not endpoint_params['sec_permissions']: endpoint_params['permission'] = cls._permission_map[endpoint_params['method']] @@ -937,8 +937,8 @@ class RESTController(BaseController): endpoint_params['status'] = meth['status'] endpoint_params['method'] = meth['method'] - if hasattr(func, "method_map_method"): - endpoint_params['version'] = func.method_map_method['version'] + if hasattr(func, "__method_map_method__"): + endpoint_params['version'] = func.__method_map_method__['version'] if not endpoint_params['sec_permissions']: endpoint_params['permission'] = cls._permission_map[endpoint_params['method']] @@ -961,7 +961,7 @@ class RESTController(BaseController): status = 200 def _wrapper(func): - func.resource_method = { + func.__resource_method__ = { 'method': method, 'path': path, 'status': status, @@ -978,7 +978,7 @@ class RESTController(BaseController): status = 200 def _wrapper(func): - func.method_map_method = { + func.__method_map_method__ = { 'resource': resource, 'status': status, 'version': version @@ -996,7 +996,7 @@ class RESTController(BaseController): status = 200 def _wrapper(func): - func.collection_method = { + func.__collection_method__ = { 'method': method, 'path': path, 'status': status, diff --git a/src/pybind/mgr/dashboard/controllers/docs.py b/src/pybind/mgr/dashboard/controllers/docs.py index 368dbeb4240..f40747f6719 100644 --- a/src/pybind/mgr/dashboard/controllers/docs.py +++ b/src/pybind/mgr/dashboard/controllers/docs.py @@ -291,14 +291,14 @@ class Docs(BaseController): resp = {} p_info = [] - if hasattr(func, 'method_map_method'): - version = func.method_map_method['version'] + if hasattr(func, '__method_map_method__'): + version = func.__method_map_method__['version'] - elif hasattr(func, 'resource_method'): - version = func.resource_method['version'] + elif hasattr(func, '__resource_method__'): + version = func.__resource_method__['version'] - elif hasattr(func, 'collection_method'): - version = func.collection_method['version'] + elif hasattr(func, '__collection_method__'): + version = func.__collection_method__['version'] if hasattr(func, 'doc_info'): if func.doc_info['summary']: