[Kimchi-devel] [PATCH V2 2/2] remove kimchisession hook and add the same logic to root.get

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Thu Jun 19 11:00:12 UTC 2014


From: ShaoHe Feng <shaohef at 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 at linux.vnet.ibm.com>
---
 src/kimchi/auth.py      | 13 -------------
 src/kimchi/config.py.in |  4 ----
 src/kimchi/root.py      |  6 ++++++
 src/kimchi/server.py    |  2 --
 tests/test_config.py.in |  4 ----
 5 files changed, 6 insertions(+), 23 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 74c8fa5..3aef8cf 100644
--- a/src/kimchi/config.py.in
+++ b/src/kimchi/config.py.in
@@ -179,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': {
@@ -191,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..2daec64 100644
--- a/src/kimchi/root.py
+++ b/src/kimchi/root.py
@@ -77,6 +77,12 @@ 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:
+            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 a78cb04..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,9 +115,6 @@ 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,
-- 
1.9.3




More information about the Kimchi-devel mailing list