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