Merge from trunk
[plcapi.git] / trunk / PLC / Methods / DeleteSession.py
diff --git a/trunk/PLC/Methods/DeleteSession.py b/trunk/PLC/Methods/DeleteSession.py
new file mode 100644 (file)
index 0000000..3898f51
--- /dev/null
@@ -0,0 +1,30 @@
+import time
+
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Auth import SessionAuth
+from PLC.Sessions import Session, Sessions
+
+class DeleteSession(Method):
+    """
+    Invalidates the current session.
+
+    Returns 1 if successful.
+    """
+
+    roles = ['admin', 'pi', 'user', 'tech', 'node']
+    accepts = [SessionAuth()]
+    returns = Parameter(int, '1 if successful')
+
+
+    def call(self, auth):
+        assert auth.has_key('session')
+
+        sessions = Sessions(self.api, [auth['session']])
+        if not sessions:
+            raise PLCAPIError, "No such session"
+        session = sessions[0]
+
+        session.delete()
+
+        return 1