3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Keys import Key, Keys
7 from PLC.Auth import Auth
9 class DeleteKey(Method):
13 Non-admins may only delete their own keys.
15 Returns 1 if successful, faults otherwise.
18 roles = ['admin', 'pi', 'tech', 'user']
25 returns = Parameter(int, '1 if successful')
28 def call(self, auth, key_id):
29 # Get associated key details
30 keys = Keys(self.api, [key_id])
32 raise PLCInvalidArgument, "No such key"
35 if key['peer_id'] is not None:
36 raise PLCInvalidArgument, "Not a local key"
38 if 'admin' not in self.caller['roles']:
39 if key['key_id'] not in self.caller['key_ids']:
40 raise PLCPermissionDenied, "Key must be associated with your account"
45 self.event_objects = {'Key': [key['key_id']]}
46 self.message = 'Key %d deleted' % key['key_id']