From: Volker Theile Date: Mon, 4 Mar 2019 12:46:59 +0000 (+0100) Subject: mgr/dashboard: Fix issues in controllers/docs X-Git-Tag: v14.2.0~20^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0da1b2bf8ffa5c3581360db4a1e6c2a4ae26575f;p=ceph.git mgr/dashboard: Fix issues in controllers/docs Signed-off-by: Volker Theile --- diff --git a/src/pybind/mgr/dashboard/controllers/docs.py b/src/pybind/mgr/dashboard/controllers/docs.py index edf7624d4bc4..06d4f977698e 100644 --- a/src/pybind/mgr/dashboard/controllers/docs.py +++ b/src/pybind/mgr/dashboard/controllers/docs.py @@ -6,6 +6,8 @@ import cherrypy from . import Controller, BaseController, Endpoint, ENDPOINT_MAP from .. import logger, mgr +from ..tools import str_to_bool + @Controller('/docs', secure=False) class Docs(BaseController): @@ -16,7 +18,7 @@ class Docs(BaseController): # Scenarios to consider: # * Intentionally make up a new tag name at controller => New tag name displayed. # * Misspell or make up a new tag name at endpoint => Neither tag or endpoint displayed. - # * Misspell tag name at controller (when refering to another controller) => + # * Misspell tag name at controller (when referring to another controller) => # Tag displayed but no endpoints assigned # * Description for a tag added at multiple locations => Only one description displayed. list_of_ctrl = set() @@ -80,7 +82,7 @@ class Docs(BaseController): @classmethod # isinstance doesn't work: input is always . def _type_to_str(cls, type_as_type): - """ Used if type is explcitly defined. """ + """ Used if type is explicitly defined. """ if type_as_type is str: type_as_str = 'string' elif type_as_type is int: @@ -99,17 +101,17 @@ class Docs(BaseController): def _add_param_info(cls, parameters, p_info): # Cases to consider: # * Parameter name (if not nested) misspelt in decorator => parameter not displayed - # * Sometime a parameter is used for several endpoints (e.g. fs_id in CephFS). - # Currently, there is no possiblity of reuse. Should there be? + # * Sometimes a parameter is used for several endpoints (e.g. fs_id in CephFS). + # Currently, there is no possibility of reuse. Should there be? # But what if there are two parameters with same name but different functionality? """ - Adds explicitly desrcibed information for parameters of an endpoint. + Adds explicitly described information for parameters of an endpoint. There are two cases: * Either the parameter in p_info corresponds to an endpoint parameter. Implicit information has higher priority, so only information that doesn't already exist is added. * Or the parameter in p_info describes a nested parameter inside an endpoint parameter. - In that case there is no implcit information at all so all explicitly described info needs + In that case there is no implicit information at all so all explicitly described info needs to be added. """ for p in p_info: @@ -306,21 +308,21 @@ class Docs(BaseController): return paths - def _gen_spec(self, all_endpoints=False, baseUrl=""): + def _gen_spec(self, all_endpoints=False, base_url=""): if all_endpoints: - baseUrl = "" + base_url = "" host = cherrypy.request.base host = host[host.index(':')+3:] logger.debug("DOCS: Host: %s", host) - paths = self._gen_paths(all_endpoints, baseUrl) + paths = self._gen_paths(all_endpoints, base_url) - if not baseUrl: - baseUrl = "/" + if not base_url: + base_url = "/" scheme = 'https' - ssl = mgr.get_localized_module_option('ssl', 'True') + ssl = str_to_bool(mgr.get_localized_module_option('ssl', True)) if not ssl: scheme = 'http' @@ -337,8 +339,8 @@ class Docs(BaseController): 'title': "Ceph-Dashboard REST API" }, 'host': host, - 'basePath': baseUrl, - 'servers': [{'url': "{}{}".format(cherrypy.request.base, baseUrl)}], + 'basePath': base_url, + 'servers': [{'url': "{}{}".format(cherrypy.request.base, base_url)}], 'tags': self._gen_tags(all_endpoints), 'schemes': [scheme], 'paths': paths, @@ -380,7 +382,7 @@ class Docs(BaseController): if token is not None: jwt_token = token - apiKeyCallback = """, onComplete: () => {{ + api_key_callback = """, onComplete: () => {{ ui.preauthorizeApiKey('jwt', '{}'); }} """.format(jwt_token) @@ -435,7 +437,7 @@ class Docs(BaseController): - """.format(spec_url, apiKeyCallback) + """.format(spec_url, api_key_callback) return page diff --git a/src/pybind/mgr/dashboard/tests/test_docs.py b/src/pybind/mgr/dashboard/tests/test_docs.py index 65da8d345fe6..18347bd34a3e 100644 --- a/src/pybind/mgr/dashboard/tests/test_docs.py +++ b/src/pybind/mgr/dashboard/tests/test_docs.py @@ -34,19 +34,19 @@ class DocDecoratorsTest(ControllerTestCase): cls.setup_controllers([DecoratedController, Docs], "/test") def test_group_info_attr(self): - testCtrl = DecoratedController() - self.assertTrue(hasattr(testCtrl, 'doc_info')) - self.assertIn('tag_descr', testCtrl.doc_info) - self.assertIn('tag', testCtrl.doc_info) + test_ctrl = DecoratedController() + self.assertTrue(hasattr(test_ctrl, 'doc_info')) + self.assertIn('tag_descr', test_ctrl.doc_info) + self.assertIn('tag', test_ctrl.doc_info) def test_endpoint_info_attr(self): - testCtrl = DecoratedController() - testEndpoint = testCtrl.decorated_func - self.assertTrue(hasattr(testEndpoint, 'doc_info')) - self.assertIn('summary', testEndpoint.doc_info) - self.assertIn('tag', testEndpoint.doc_info) - self.assertIn('parameters', testEndpoint.doc_info) - self.assertIn('response', testEndpoint.doc_info) + test_ctrl = DecoratedController() + test_endpoint = test_ctrl.decorated_func + self.assertTrue(hasattr(test_endpoint, 'doc_info')) + self.assertIn('summary', test_endpoint.doc_info) + self.assertIn('tag', test_endpoint.doc_info) + self.assertIn('parameters', test_endpoint.doc_info) + self.assertIn('response', test_endpoint.doc_info) # To assure functionality of Docs.py