Currently get_plugin_from_request() assumes plugin's
root URI is always /plugins/<plugin_name>, which is
in fact configurable by each plugin.
This patch fixes it by mapping plugins' root URI
on load time, and replacing get_plugin_from_request()
by a more generic get_plugin_from_uri() to be used
also in AsyncTask.
Signed-off-by: Lucio Correia <luciojhc(a)linux.vnet.ibm.com>
---
src/wok/control/base.py | 4 ++--
src/wok/utils.py | 14 +++++++++-----
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/wok/control/base.py b/src/wok/control/base.py
index f4443c8..213e6b5 100644
--- a/src/wok/control/base.py
+++ b/src/wok/control/base.py
@@ -33,7 +33,7 @@ from wok.control.utils import validate_params
from wok.exception import InvalidOperation, UnauthorizedError, WokException
from wok.reqlogger import RequestRecord
from wok.stringutils import encode_value, utf8_dict
-from wok.utils import get_plugin_from_request, wok_log
+from wok.utils import get_plugin_from_uri, wok_log
# Default request log messages
@@ -47,7 +47,7 @@ def log_request(code, params, exception, method, status, user=None):
log_id = RequestRecord(
{'code': code, 'params': params},
exception,
- app=get_plugin_from_request(),
+ app=get_plugin_from_uri(cherrypy.request.script_name),
req=method,
status=status,
user=user or cherrypy.session.get(USER_NAME, 'N/A'),
diff --git a/src/wok/utils.py b/src/wok/utils.py
index 7599e85..b3d252c 100644
--- a/src/wok/utils.py
+++ b/src/wok/utils.py
@@ -44,6 +44,7 @@ from wok.exception import InvalidParameter, TimeoutExpired
from wok.stringutils import decode_value
+plugin_root = {}
wok_log = cherrypy.log.error_log
@@ -82,6 +83,10 @@ def get_enabled_plugins():
plugin_config = _load_plugin_conf(name)
try:
if plugin_config['wok']['enable']:
+ # update plugin lookup dict
+ uri = plugin_config['wok']['uri']
+ plugin_root[name] = uri
+
yield (name, plugin_config)
except (TypeError, KeyError):
continue
@@ -106,14 +111,13 @@ def get_all_tabs():
return tabs
-def get_plugin_from_request():
+def get_plugin_from_uri(uri):
"""
Returns name of plugin being requested. If no plugin, returns 'wok'.
"""
- script_name = cherrypy.request.script_name
- split = script_name.split('/')
- if len(split) > 2 and split[1] == 'plugins':
- return split[2]
+ for plugin, root in plugin_root.iteritems():
+ if uri.startswith(root):
+ return plugin
return 'wok'
--
1.9.1