From: Stephen Soltesz Date: Fri, 17 Jun 2011 00:01:49 +0000 (-0400) Subject: Add an optional 'expires' argument to GetSession() to allow longer expirations X-Git-Tag: plcapi-5.0-34~4^2 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=b4e7800fb72b36ae1ea4db6ab28421a6e66dcb9f;p=plcapi.git Add an optional 'expires' argument to GetSession() to allow longer expirations --- diff --git a/PLC/Methods/GetSession.py b/PLC/Methods/GetSession.py index 6a8ac4c1..82dccbfd 100644 --- a/PLC/Methods/GetSession.py +++ b/PLC/Methods/GetSession.py @@ -11,14 +11,18 @@ class GetSession(Method): """ Returns a new session key if a user or node authenticated successfully, faults otherwise. + + Default value for 'expires' is 24 hours. Otherwise, the returned + session 'expires' in the given number of seconds. """ roles = ['admin', 'pi', 'user', 'tech', 'node'] - accepts = [Auth()] + accepts = [Auth(), + Parameter(int,"expires", nullok=True)] returns = Session.fields['session_id'] - def call(self, auth): + def call(self, auth, expires=None): # Authenticated with a session key, just return it if auth.has_key('session'): return auth['session'] @@ -27,7 +31,10 @@ class GetSession(Method): if isinstance(self.caller, Person): # XXX Make this configurable - session['expires'] = int(time.time()) + (24 * 60 * 60) + if expires is None: + session['expires'] = int(time.time()) + (24 * 60 * 60) + else: + session['expires'] = int(time.time()) + int(expires) session.sync(commit = False)