cosmetic changes in sendmail.py - please the linter
[plcapi.git] / PLC / Methods / GetSession.py
index e0dd01a..8ae8dd1 100644 (file)
@@ -1,4 +1,3 @@
-# $Id$
 import time
 
 from PLC.Method import Method
@@ -12,29 +11,36 @@ 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'):
+        if 'session' in auth:
             return auth['session']
 
         session = Session(self.api)
 
         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)
+        session.sync(commit=False)
 
         if isinstance(self.caller, Node):
-            session.add_node(self.caller, commit = True)
+            session.add_node(self.caller, commit=True)
         elif isinstance(self.caller, Person):
-            session.add_person(self.caller, commit = True)
+            session.add_person(self.caller, commit=True)
 
         return session['session_id']