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 can_update = lambda (field, value): field in \
12 class UpdateKey(Method):
14 Updates the parameters of an existing key with the values in
17 Non-admins may only update their own keys.
19 Returns 1 if successful, faults otherwise.
22 roles = ['admin', 'pi', 'tech', 'user']
24 key_fields = dict(filter(can_update, Key.fields.items()))
32 returns = Parameter(int, '1 if successful')
34 def call(self, auth, key_id, key_fields):
35 key_fields = dict(filter(can_update, key_fields.items()))
38 keys = Keys(self.api, [key_id])
40 raise PLCInvalidArgument, "No such key"
43 if key['peer_id'] is not None:
44 raise PLCInvalidArgument, "Not a local key"
46 if 'admin' not in self.caller['roles']:
47 if key['key_id'] not in self.caller['key_ids']:
48 raise PLCPermissionDenied, "Key must be associated with one of your accounts"
50 key.update(key_fields)
54 self.event_objects = {'Key': [key['key_id']]}
55 self.message = 'key %d updated: %s' % \
56 (key['key_id'], ", ".join(key_fields.keys()))