[PATCH] [Wok 0/3] Make session timeout configurable

Aline Manera (3): Add wok-robot header to /notifications requests Issue #19: Make session timeout configurable Add root configuration as default for PluginConfig src/wok.conf.in | 4 ++++ src/wok/auth.py | 2 +- src/wok/config.py.in | 16 +++++++++++++--- src/wokd.in | 5 +++++ tests/test_config.py.in | 2 -- ui/js/src/wok.api.js | 1 + 6 files changed, 24 insertions(+), 6 deletions(-) -- 2.5.5

Periodic requests made by UI must contain the wok-robot header to do not restart the user session counting down. Without the header, the user session is refreshed on each /notifications request and will never expire. It closes issue https://github.com/kimchi-project/kimchi/issues/376 Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- ui/js/src/wok.api.js | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/js/src/wok.api.js b/ui/js/src/wok.api.js index 56e90ed..5238594 100644 --- a/ui/js/src/wok.api.js +++ b/ui/js/src/wok.api.js @@ -63,6 +63,7 @@ var wok = { wok.requestJSON({ url: 'notifications', type : 'GET', + headers: {'Wok-Robot': 'wok-robot'}, dataType : 'json', success : suc, error: err -- 2.5.5

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@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

The root configuration ('/') is common piece for every plugin, so move it to common place (PluginConfig) so the plugin only needs to define its specific APIs Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- src/wok/config.py.in | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/wok/config.py.in b/src/wok/config.py.in index 65f6b6c..1b0e7bd 100644 --- a/src/wok/config.py.in +++ b/src/wok/config.py.in @@ -230,6 +230,18 @@ class PluginConfig(dict): def __init__(self, plugin_name): super(PluginConfig, self).__init__(self) plugin_config = { + '/': { + 'tools.trailing_slash.on': False, + 'request.methods_with_bodies': ('POST', 'PUT'), + 'tools.nocache.on': True, + 'tools.proxy.on': True, + 'tools.sessions.on': True, + 'tools.sessions.name': 'wok', + 'tools.sessions.secure': True, + 'tools.sessions.httponly': True, + 'tools.sessions.locking': 'explicit', + 'tools.sessions.storage_type': 'ram' + }, '/ui/config/tab-ext.xml': { 'tools.staticfile.on': True, 'tools.staticfile.filename': -- 2.5.5

Reviewed-by: Jose Ricardo Ziviani <joserz@linux.vnet.ibm.com> On Wed, May 04, 2016 at 01:58:05PM -0300, Aline Manera wrote:
Aline Manera (3): Add wok-robot header to /notifications requests Issue #19: Make session timeout configurable Add root configuration as default for PluginConfig
src/wok.conf.in | 4 ++++ src/wok/auth.py | 2 +- src/wok/config.py.in | 16 +++++++++++++--- src/wokd.in | 5 +++++ tests/test_config.py.in | 2 -- ui/js/src/wok.api.js | 1 + 6 files changed, 24 insertions(+), 6 deletions(-)
-- 2.5.5
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel

Reviewed-by: Daniel Barboza <dhbarboza82@gmail.com> Tested-by: Daniel Barboza <dhbarboza82@gmail.com> On 05/04/2016 01:58 PM, Aline Manera wrote:
Aline Manera (3): Add wok-robot header to /notifications requests Issue #19: Make session timeout configurable Add root configuration as default for PluginConfig
src/wok.conf.in | 4 ++++ src/wok/auth.py | 2 +- src/wok/config.py.in | 16 +++++++++++++--- src/wokd.in | 5 +++++ tests/test_config.py.in | 2 -- ui/js/src/wok.api.js | 1 + 6 files changed, 24 insertions(+), 6 deletions(-)
participants (3)
-
Aline Manera
-
Daniel Henrique Barboza
-
joserz@linux.vnet.ibm.com