From: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
kimchisession hook is heavy overhead.
root.get just return the kimchi-ui.html, it is not a restful API.
consider root.get is the only entry of UI.
So move the logic code to root.get.
Signed-off-by: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
---
src/kimchi/auth.py | 13 -------------
src/kimchi/config.py.in | 5 -----
src/kimchi/root.py | 8 ++++++++
src/kimchi/server.py | 2 --
tests/test_config.py.in | 8 --------
5 files changed, 8 insertions(+), 28 deletions(-)
diff --git a/src/kimchi/auth.py b/src/kimchi/auth.py
index c7f94a7..6a4a610 100644
--- a/src/kimchi/auth.py
+++ b/src/kimchi/auth.py
@@ -269,16 +269,3 @@ def kimchiauth(admin_methods=None):
e = InvalidOperation('KCHAUTH0002E')
raise cherrypy.HTTPError(401, e.message.encode('utf-8'))
-
-
-def kimchisession(admin_methods=None):
- session = cherrypy.request.cookie.get("kimchi")
- last_page = cherrypy.request.cookie.get("lastPage")
- headers = cherrypy.request.headers
- authheader = headers.get('AUTHORIZATION')
- # when client browser first login in, both the session and lastPage cookie
- # are None.
- # when session timeout, only session cookie is None.
- if (session is None and last_page is None and authheader is None and
- ("Accept" in headers and not
template.can_accept('application/json'))):
- redirect_login()
diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in
index 4be767e..3aef8cf 100644
--- a/src/kimchi/config.py.in
+++ b/src/kimchi/config.py.in
@@ -154,7 +154,6 @@ class UIConfig(dict):
ui_configs['/' + sub_dir] = {
'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.join(paths.ui_dir, sub_dir),
- 'tools.kimchisession.on': False,
'tools.nocache.on': False}
if sub_dir != 'images':
ui_configs['/' + sub_dir].update({
@@ -180,7 +179,6 @@ class KimchiConfig(dict):
'tools.sessions.locking': 'explicit',
'tools.sessions.storage_type': 'ram',
'tools.sessions.timeout': SESSIONSTIMEOUT,
- 'tools.kimchisession.on': True,
'tools.kimchiauth.on': False
},
'/vnc_auto.html': {
@@ -192,9 +190,6 @@ class KimchiConfig(dict):
'/kimchi-ui.html': {
'tools.kimchiauth.on': True
},
- '/login.html': {
- 'tools.kimchisession.on': False,
- },
'/data/screenshots': {
'tools.staticdir.on': True,
'tools.staticdir.dir': get_screenshot_path(),
diff --git a/src/kimchi/root.py b/src/kimchi/root.py
index 82bd97b..6d1bd19 100644
--- a/src/kimchi/root.py
+++ b/src/kimchi/root.py
@@ -77,6 +77,14 @@ def error_development_handler(self, status, message, traceback,
version):
return res
def get(self):
+ last_page = cherrypy.request.cookie.get("lastPage")
+ # when session timeout, only session cookie is None.
+ # when first login, both session and lastPage are None.
+ if (cherrypy.session.originalid is None and last_page is None and
+ not template.can_accept('application/json') and
+ template.can_accept_html()):
+ raise cherrypy.HTTPRedirect("/login.html", 303)
+
return self.default(self.default_page)
@cherrypy.expose
diff --git a/src/kimchi/server.py b/src/kimchi/server.py
index 30140ce..7344349 100644
--- a/src/kimchi/server.py
+++ b/src/kimchi/server.py
@@ -77,8 +77,6 @@ def __init__(self, options):
cherrypy.tools.nocache = cherrypy.Tool('on_end_resource', set_no_cache)
cherrypy.tools.kimchiauth = cherrypy.Tool('before_handler',
auth.kimchiauth)
- cherrypy.tools.kimchisession = cherrypy.Tool('before_request_body',
- auth.kimchisession)
# Setting host to 127.0.0.1. This makes kimchi runs
# as a localhost app, inaccessible to the outside
# directly. You must go through the proxy.
diff --git a/tests/test_config.py.in b/tests/test_config.py.in
index 1ca8d9e..f349419 100644
--- a/tests/test_config.py.in
+++ b/tests/test_config.py.in
@@ -104,7 +104,6 @@ class ConfigTests(unittest.TestCase):
'tools.sessions.locking': 'explicit',
'tools.sessions.storage_type': 'ram',
'tools.sessions.timeout': SESSIONSTIMEOUT,
- 'tools.kimchisession.on': True,
'tools.kimchiauth.on': False
},
'/vnc_auto.html': {
@@ -116,15 +115,11 @@ class ConfigTests(unittest.TestCase):
'/kimchi-ui.html': {
'tools.kimchiauth.on': True
},
- '/login.html': {
- 'tools.kimchisession.on': False,
- },
'/css': {
'tools.staticdir.on': True,
'tools.staticdir.dir': '%s/ui/css' % paths.prefix,
'tools.expires.on': True,
'tools.expires.secs': CACHEEXPIRES,
- 'tools.kimchisession.on': False,
'tools.nocache.on': False
},
'/js': {
@@ -132,7 +127,6 @@ class ConfigTests(unittest.TestCase):
'tools.staticdir.dir': '%s/ui/js' % paths.prefix,
'tools.expires.on': True,
'tools.expires.secs': CACHEEXPIRES,
- 'tools.kimchisession.on': False,
'tools.nocache.on': False
},
'/libs': {
@@ -140,13 +134,11 @@ class ConfigTests(unittest.TestCase):
'tools.staticdir.dir': '%s/ui/libs' % paths.prefix,
'tools.expires.on': True,
'tools.expires.secs': CACHEEXPIRES,
- 'tools.kimchisession.on': False,
'tools.nocache.on': False,
},
'/images': {
'tools.staticdir.on': True,
'tools.staticdir.dir': '%s/ui/images' % paths.prefix,
- 'tools.kimchisession.on': False,
'tools.nocache.on': False
},
'/data/screenshots': {
--
1.9.3