1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Keys import Key, Keys
5 from PLC.Auth import Auth
7 class DeleteKey(Method):
11 Non-admins may only delete their own keys.
13 Returns 1 if successful, faults otherwise.
16 roles = ['admin', 'pi', 'tech', 'user']
23 returns = Parameter(int, '1 if successful')
26 def call(self, auth, key_id):
27 # Get associated key details
28 keys = Keys(self.api, [key_id])
30 raise PLCInvalidArgument, "No such key"
33 if key['peer_id'] is not None:
34 raise PLCInvalidArgument, "Not a local key"
36 if 'admin' not in self.caller['roles']:
37 if key['key_id'] not in self.caller['key_ids']:
38 raise PLCPermissionDenied, "Key must be associated with your account"
43 self.object_ids = [key['key_id']]
44 self.message = 'Key %d deleted' % key['key_id']