From 6487b4babf329b1d41ae36863d265b7efe418ac7 Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Thu, 26 Apr 2018 12:20:09 +0200 Subject: [PATCH] mgr/dashboard: Fix duplicate params error * Remove params, if they use the `{name:regex}` syntax. * Fixes http://tracker.ceph.com/issues/23823 Signed-off-by: Sebastian Wagner --- .../mgr/dashboard/controllers/__init__.py | 5 +++++ src/pybind/mgr/dashboard/tests/test_tools.py | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/dashboard/controllers/__init__.py b/src/pybind/mgr/dashboard/controllers/__init__.py index b8ae52f5ea8a..4e00f981b24d 100644 --- a/src/pybind/mgr/dashboard/controllers/__init__.py +++ b/src/pybind/mgr/dashboard/controllers/__init__.py @@ -395,8 +395,13 @@ class BaseController(object): # filter out controller path params for idx, step in enumerate(cls._cp_path_.split('/')): + param = None if step[0] == ':': param = step[1:] + if step[0] == '{' and step[-1] == '}' and ':' in step[1:-1]: + param, _, _regex = step[1:-1].partition(':') + + if param: if param not in cargs: raise Exception("function '{}' does not have the" " positional argument '{}' in the {} " diff --git a/src/pybind/mgr/dashboard/tests/test_tools.py b/src/pybind/mgr/dashboard/tests/test_tools.py index 33ab223935fd..b45e16913d58 100644 --- a/src/pybind/mgr/dashboard/tests/test_tools.py +++ b/src/pybind/mgr/dashboard/tests/test_tools.py @@ -9,7 +9,7 @@ from mock import patch from ..services.exception import handle_rados_error from .helper import ControllerTestCase -from ..controllers import RESTController, ApiController +from ..controllers import RESTController, ApiController, BaseController from ..tools import is_valid_ipv6_address, dict_contains_path @@ -44,6 +44,13 @@ class FooResourceDetail(RESTController): return {'detail': (key, [method])} +@ApiController('rgw/proxy/{path:.*}') +class GenerateControllerRoutesController(BaseController): + @cherrypy.expose + def __call__(self, path, **params): + pass + + @ApiController('fooargs') class FooArgs(RESTController): def set(self, code, name=None, opt1=None, opt2=None): @@ -67,7 +74,8 @@ class RESTControllerTest(ControllerTestCase): @classmethod def setup_server(cls): - cls.setup_controllers([FooResource, FooResourceDetail, FooArgs]) + cls.setup_controllers( + [FooResource, FooResourceDetail, FooArgs, GenerateControllerRoutesController]) def test_empty(self): self._delete("/foo") @@ -147,6 +155,12 @@ class RESTControllerTest(ControllerTestCase): self.getPage('/fooargs', headers=[('Accept', 'text/html')]) self.assertIn('my_arg_name', self.body.decode('utf-8')) + def test_generate_controller_routes(self): + # We just need to add this controller in setup_server(): + # noinspection PyStatementEffect + # pylint: disable=pointless-statement + GenerateControllerRoutesController + class TestFunctions(unittest.TestCase): -- 2.47.3