[Kimchi-devel] [PATCH] [Wok 2/3] Issue #19: Make session timeout configurable

Aline Manera alinefm at linux.vnet.ibm.com
Wed May 4 16:58:07 UTC 2016


By default, the session timeout is set to 10 minutes but user can change it by
editing the wok.conf file (session_timeout value) or using the --session_timeout
option for wokd command line.

Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
 src/wok.conf.in         | 4 ++++
 src/wok/auth.py         | 2 +-
 src/wok/config.py.in    | 4 +---
 src/wokd.in             | 5 +++++
 tests/test_config.py.in | 2 --
 5 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/wok.conf.in b/src/wok.conf.in
index 184c71e..713c5a9 100644
--- a/src/wok.conf.in
+++ b/src/wok.conf.in
@@ -22,6 +22,10 @@
 # Port for websocket proxy to listen on
 #websockets_port = 64667
 
+# Number of minutes that a session can remain idle before the server
+# terminates it automatically.
+#session_timeout = 10
+
 # The full path to an SSL Certificate or chain of certificates in
 # PEM format. When a chain is used, the server's certificate must be
 # the first certificate in the file with the chain concatenated into
diff --git a/src/wok/auth.py b/src/wok/auth.py
index ef3215c..0355e86 100644
--- a/src/wok/auth.py
+++ b/src/wok/auth.py
@@ -264,7 +264,7 @@ def check_auth_session():
         wokRobot = cherrypy.request.headers.get('Wok-Robot')
         if wokRobot == "wok-robot":
             if (time.time() - cherrypy.session[REFRESH] >
-                    cherrypy.session.timeout * 60):
+                    int(config.get('server', 'session_timeout')) * 60):
                 cherrypy.session[USER_NAME] = None
                 cherrypy.lib.sessions.expire()
                 raise cherrypy.HTTPError(401, "sessionTimeout")
diff --git a/src/wok/config.py.in b/src/wok/config.py.in
index 0c3acdd..65f6b6c 100644
--- a/src/wok/config.py.in
+++ b/src/wok/config.py.in
@@ -57,8 +57,6 @@ FONTS_PATH = {
     ]
 }
 
-SESSIONSTIMEOUT = 10    # session time out is 10 minutes
-
 
 def get_log_download_path():
     return os.path.join(paths.state_dir, 'logs')
@@ -189,7 +187,6 @@ class WokConfig(dict):
             'tools.sessions.httponly': True,
             'tools.sessions.locking': 'explicit',
             'tools.sessions.storage_type': 'ram',
-            'tools.sessions.timeout': SESSIONSTIMEOUT,
             'tools.wokauth.on': False
         },
         '/data/logs': {
@@ -251,6 +248,7 @@ def _get_config():
     config.set("server", "https_only", "false")
     config.set("server", "cherrypy_port", "8010")
     config.set("server", "websockets_port", "64667")
+    config.set("server", "session_timeout", "10")
     config.set("server", "ssl_cert", "")
     config.set("server", "ssl_key", "")
     config.set("server", "environment", "production")
diff --git a/src/wokd.in b/src/wokd.in
index 7255d3c..962581d 100644
--- a/src/wokd.in
+++ b/src/wokd.in
@@ -49,6 +49,7 @@ def main(options):
     https_only = config.config.get("server", "https_only")
     cherrypy_port = config.config.get("server", "cherrypy_port")
     websockets_port = config.config.get("server", "websockets_port")
+    session_timeout = config.config.get("server", "session_timeout")
     runningEnv = config.config.get("server", "environment")
     logDir = config.config.get("logging", "log_dir")
     logLevel = config.config.get("logging", "log_level")
@@ -68,6 +69,10 @@ def main(options):
     parser.add_option('--websockets_port', type="int", default=websockets_port,
                       help="Websockets port to listen on (default %s)" %
                             websockets_port)
+    parser.add_option('--session_timeout', type="int", default=session_timeout,
+                      help="Number of minutes that a session can remain idle "
+                           "before the server terminates it automatically. "
+                           "(default %s)" % session_timeout)
     parser.add_option('--log-level', default=logLevel,
                       help="Logging level")
     parser.add_option('--access-log',
diff --git a/tests/test_config.py.in b/tests/test_config.py.in
index 1e7cc72..b221d18 100644
--- a/tests/test_config.py.in
+++ b/tests/test_config.py.in
@@ -67,7 +67,6 @@ class ConfigTests(unittest.TestCase):
     def test_wok_config(self):
         Paths.get_prefix = get_prefix
         paths = Paths()
-        SESSIONSTIMEOUT = 10
         configObj = {
             '/': {
                 'tools.trailing_slash.on': False,
@@ -80,7 +79,6 @@ class ConfigTests(unittest.TestCase):
                 'tools.sessions.httponly': True,
                 'tools.sessions.locking': 'explicit',
                 'tools.sessions.storage_type': 'ram',
-                'tools.sessions.timeout': SESSIONSTIMEOUT,
                 'tools.wokauth.on': False
             },
             '/data/logs': {
-- 
2.5.5




More information about the Kimchi-devel mailing list