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