[Kimchi-devel] [PATCH V3 18/34] Dynamically add authed URLs to plugin conf

Lucio Correia luciojhc at linux.vnet.ibm.com
Wed Jul 8 19:17:50 UTC 2015


This patch implements the loading of URL subnodes in Kimchi
plugin and makes it available to any plugin that wants to use
it, through the extra_auth_api_class conf attribute.

Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
Signed-off-by: Gustavo Y. Ribeiro <gyr at linux.vnet.ibm.com>
---
 plugins/kimchi/kimchi.conf |    1 +
 src/wok/server.py          |   20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/plugins/kimchi/kimchi.conf b/plugins/kimchi/kimchi.conf
index 1e0ee6b..bf5efc5 100644
--- a/plugins/kimchi/kimchi.conf
+++ b/plugins/kimchi/kimchi.conf
@@ -2,6 +2,7 @@
 enable = True
 plugin_class = "KimchiRoot"
 uri = "/plugins/kimchi"
+extra_auth_api_class = "control.sub_nodes"
 
 [/]
 tools.trailing_slash.on = False
diff --git a/src/wok/server.py b/src/wok/server.py
index ba81308..0a836a2 100644
--- a/src/wok/server.py
+++ b/src/wok/server.py
@@ -145,6 +145,8 @@ class Server(object):
                 plugin_class = ('plugins.%s.%s' %
                                 (plugin_name,
                                  plugin_config['wok']['plugin_class']))
+                extra_auth = plugin_config['wok'].get('extra_auth_api_class',
+                                                      None)
                 script_name = plugin_config['wok']['uri']
                 del plugin_config['wok']
 
@@ -164,6 +166,24 @@ class Server(object):
             if get_custom_conf is not None:
                 plugin_config.update(get_custom_conf())
 
+            # dynamically add tools.wokauth.on = True to extra plugin APIs
+            if extra_auth:
+                try:
+                    authed_apis = import_class(('plugins.%s.%s' % (plugin_name,
+                                              extra_auth)))
+                except ImportError:
+                    cherrypy.log.error_log.error("Failed to import subnodes "
+                                                 "for plugin %s" % plugin_class)
+                    continue
+
+                urlSubNodes = {}
+                for ident, node in authed_apis.items():
+                    if node.url_auth:
+                        ident = "/%s" % ident
+                        urlSubNodes[ident] = {'tools.wokauth.on': True}
+
+                plugin_config.update(urlSubNodes)
+
             cherrypy.tree.mount(plugin_app, script_name, plugin_config)
 
     def start(self):
-- 
1.7.1




More information about the Kimchi-devel mailing list