]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Add UiApiController decorator
authorRicardo Marques <rimarques@suse.com>
Mon, 28 May 2018 16:34:59 +0000 (17:34 +0100)
committerRicardo Marques <rimarques@suse.com>
Tue, 29 May 2018 09:46:12 +0000 (10:46 +0100)
Should be used for UI specific requests.

Signed-off-by: Ricardo Marques <rimarques@suse.com>
src/pybind/mgr/dashboard/HACKING.rst
src/pybind/mgr/dashboard/controllers/__init__.py
src/pybind/mgr/dashboard/frontend/proxy.conf.json.sample

index d11e27e69f717f58ca36c2eaed7b3d108a08b172..5c06293a330a6eef06cb05c804c2a676880cf4ac 100644 (file)
@@ -246,15 +246,18 @@ How to add a new controller?
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 A controller is a Python class that extends from the ``BaseController`` class
-and is decorated with either the ``@Controller`` or ``@ApiController``
-decorators. The Python class must be stored inside a Python file located under
-the ``controllers`` directory. The Dashboard module will automatically load
-your new controller upon start.
+and is decorated with either the ``@Controller``, ``@ApiController`` or
+``@UiApiController`` decorators. The Python class must be stored inside a Python
+file located under the ``controllers`` directory. The Dashboard module will
+automatically load your new controller upon start.
 
-The ``@ApiController`` decorator is a specialization of the ``@Controller``
-decorator, and should be used for controllers that provide an API-like REST
-interface. For any other kinds of controllers the ``@Controller`` decorator
-should be used.
+``@ApiController`` and ``@UiApiController`` are both specializations of the
+``@Controller`` decorator.
+
+The ``@ApiController`` should be used for controllers that provide an API-like
+REST interface and the ``@UiApiController`` should be used for endpoints consumed
+by the UI but that are not part of the 'public' API. For any other kinds of
+controllers the ``@Controller`` decorator should be used.
 
 A controller has a URL prefix path associated that is specified in the
 controller decorator, and all endpoints exposed by the controller will share
@@ -268,7 +271,7 @@ following code:
 
 .. code-block:: python
 
-  from ..tools import Controller, ApiController, BaseController, Endpoint
+  from ..tools import Controller, ApiController, UiApiController, BaseController, Endpoint
 
   @Controller('/ping')
   class Ping(BaseController):
@@ -282,6 +285,11 @@ following code:
     def hello(self):
       return {'msg': "Hello"}
 
+  @UiApiController('/ping')
+  class UiApiPing(BaseController):
+    @Endpoint()
+    def hello(self):
+      return {'msg': "Hello"}
 
 The ``hello`` endpoint of the ``Ping`` controller can be reached by the
 following URL: https://mgr_hostname:8080/ping/hello using HTTP GET requests.
@@ -298,6 +306,12 @@ decorator by passing an additional decorator parameter called ``base_url``::
 
   @ApiController('/ping') <=> @Controller('/ping', base_url="/api")
 
+``UiApiPing`` works in a similar way than the ``ApiPing``, but the URL will be
+prefixed by ``/ui-api``: https://mgr_hostname:8080/ui-api/ping/hello. ``UiApiPing`` is
+also a ``@Controller`` extension::
+
+  @UiApiController('/ping') <=> @Controller('/ping', base_url="/ui-api")
+
 The ``@Endpoint`` decorator also supports many parameters to customize the
 endpoint:
 
index ff82a4c86ba82353fdf03a806d3496619b93a251..b0dd84e18f33a7f82066cdafe5b1ccd51b2380bf 100644 (file)
@@ -64,6 +64,11 @@ class ApiController(Controller):
         return cls
 
 
+class UiApiController(Controller):
+    def __init__(self, path):
+        super(UiApiController, self).__init__(path, base_url="/ui-api")
+
+
 def AuthRequired(enabled=True):
     def decorate(cls):
         if not hasattr(cls, '_cp_config'):
index d70abbd2c93e40516151d0df27a384ef0ac9a5c3..1b4f52de52a0364e220615807b78b60f0ae44c41 100644 (file)
@@ -3,5 +3,10 @@
     "target": "https://localhost:8080",
     "secure": false,
     "logLevel": "debug"
+  },
+  "/ui-api/": {
+    "target": "https://localhost:8080",
+    "secure": false,
+    "logLevel": "debug"
   }
 }