From: Ernesto Puerta Date: Thu, 10 Oct 2019 09:21:52 +0000 (+0200) Subject: mgr/dashboard: add new plugin hooks X-Git-Tag: v15.1.0~1274^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f439a760bba2b0b2d7035f8ffbaa097e27c96fb1;p=ceph.git mgr/dashboard: add new plugin hooks New plugin hooks are: `init` and `update_cherrypy_config`. Fixes: https://tracker.ceph.com/issues/41990 Signed-off-by: Ernesto Puerta --- diff --git a/src/pybind/mgr/dashboard/module.py b/src/pybind/mgr/dashboard/module.py index b080d17b0acd..7286ecfbf3aa 100644 --- a/src/pybind/mgr/dashboard/module.py +++ b/src/pybind/mgr/dashboard/module.py @@ -83,7 +83,10 @@ from .settings import options_command_list, options_schema_list, \ handle_option_command from .plugins import PLUGIN_MANAGER -from .plugins import feature_toggles # noqa # pylint: disable=unused-import +from .plugins import feature_toggles, debug # noqa # pylint: disable=unused-import + + +PLUGIN_MANAGER.hook.init() # cherrypy likes to sys.exit on error. don't let it take us down too! @@ -116,6 +119,11 @@ class CherryPyConfig(object): def url_prefix(self): return self._url_prefix + @staticmethod + def update_cherrypy_config(config): + PLUGIN_MANAGER.hook.configure_cherrypy(config=config) + cherrypy.config.update(config) + # pylint: disable=too-many-branches def _configure(self): """ @@ -141,10 +149,10 @@ class CherryPyConfig(object): # Initialize custom handlers. cherrypy.tools.authenticate = AuthManagerTool() - cherrypy.tools.plugin_hooks = cherrypy.Tool( + cherrypy.tools.plugin_hooks_filter_request = cherrypy.Tool( 'before_handler', lambda: PLUGIN_MANAGER.hook.filter_request_before_handler(request=cherrypy.request), - priority=10) + priority=1) cherrypy.tools.request_logging = RequestLoggingTool() cherrypy.tools.dashboard_exception_handler = HandlerWrapperTool(dashboard_exception_handler, priority=31) @@ -166,7 +174,7 @@ class CherryPyConfig(object): ], 'tools.json_in.on': True, 'tools.json_in.force': False, - 'tools.plugin_hooks.on': True, + 'tools.plugin_hooks_filter_request.on': True, } if ssl: @@ -195,7 +203,7 @@ class CherryPyConfig(object): config['server.ssl_certificate'] = cert_fname config['server.ssl_private_key'] = pkey_fname - cherrypy.config.update(config) + self.update_cherrypy_config(config) self._url_prefix = prepare_url_prefix(self.get_module_option('url_prefix', default='')) @@ -338,6 +346,7 @@ class Module(MgrModule, CherryPyConfig): config[purl] = { 'request.dispatch': mapper } + cherrypy.tree.mount(None, config=config) PLUGIN_MANAGER.hook.setup()