b55c6862f2658845284fd2ccb0b503c480027641
[plcapi.git] / PLC / Methods / DeleteSession.py
1 # $Id$
2 import time
3
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Auth import SessionAuth
7 from PLC.Sessions import Session, Sessions
8
9 class DeleteSession(Method):
10     """
11     Invalidates the current session.
12
13     Returns 1 if successful.
14     """
15
16     roles = ['admin', 'pi', 'user', 'tech', 'node']
17     accepts = [SessionAuth()]
18     returns = Parameter(int, '1 if successful')
19
20
21     def call(self, auth):
22         assert auth.has_key('session')
23
24         sessions = Sessions(self.api, [auth['session']])
25         if not sessions:
26             raise PLCAPIError, "No such session"
27         session = sessions[0]
28
29         session.delete()
30
31         return 1