[Kimchi-devel] [PATCH] [Wok 2/3] Get root application name from plugin name and automatically import plugin sub_nodes

Aline Manera alinefm at linux.vnet.ibm.com
Fri Jan 22 12:31:34 UTC 2016


Before this patch, the application name and plugin sub_nodes information
was listed in the plugin configuration file. But those kind of
information must not be edited, otherwise the user can break the
application.

To allow removing those kind of information from plugin configuration
file, automatically get the application name from plugin name and import
plugin sub_nodes on server start up.

Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
 src/wok/server.py | 37 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/src/wok/server.py b/src/wok/server.py
index 59ecdc0..4fd380c 100644
--- a/src/wok/server.py
+++ b/src/wok/server.py
@@ -1,7 +1,7 @@
 #
 # Project Wok
 #
-# Copyright IBM, Corp. 2013-2015
+# Copyright IBM, Corp. 2013-2016
 #
 # Code derived from Project Kimchi
 #
@@ -146,9 +146,7 @@ class Server(object):
             try:
                 plugin_class = ('plugins.%s.%s' %
                                 (plugin_name,
-                                 plugin_config['wok']['plugin_class']))
-                extra_auth = plugin_config['wok'].get('extra_auth_api_class',
-                                                      None)
+                                 plugin_name[0].upper() + plugin_name[1:]))
                 script_name = plugin_config['wok']['uri']
                 del plugin_config['wok']
 
@@ -171,22 +169,21 @@ class Server(object):
                 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, e:
-                    cherrypy.log.error_log.error(
-                        "Failed to import subnodes for plugin %s, "
-                        "error: %s" % (plugin_class, e.message)
-                    )
-                    continue
-
-                urlSubNodes = {}
-                for ident, node in authed_apis.items():
-                    if node.url_auth:
-                        ident = "/%s" % ident
-                        urlSubNodes[ident] = {'tools.wokauth.on': True}
+            try:
+                sub_nodes = import_class('plugins.%s.control.sub_nodes' %
+                                         plugin_name)
+            except ImportError, e:
+                cherrypy.log.error_log.error(
+                    "Failed to import subnodes for plugin %s, "
+                    "error: %s" % (plugin_class, e.message)
+                )
+                continue
+
+            urlSubNodes = {}
+            for ident, node in sub_nodes.items():
+                if node.url_auth:
+                    ident = "/%s" % ident
+                    urlSubNodes[ident] = {'tools.wokauth.on': True}
 
                 plugin_config.update(urlSubNodes)
 
-- 
2.5.0




More information about the Kimchi-devel mailing list