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 can_update = lambda (field, value): field in \
11 class UpdateKey(Method):
13 Updates the parameters of an existing key with the values in
16 Non-admins may only update their own keys.
18 Returns 1 if successful, faults otherwise.
21 roles = ['admin', 'pi', 'tech', 'user']
23 key_fields = dict(filter(can_update, Key.fields.items()))
31 returns = Parameter(int, '1 if successful')
33 def call(self, auth, key_id, key_fields):
34 key_fields = dict(filter(can_update, key_fields.items()))
37 keys = Keys(self.api, [key_id])
39 raise PLCInvalidArgument, "No such key"
42 if key['peer_id'] is not None:
43 raise PLCInvalidArgument, "Not a local key"
45 if 'admin' not in self.caller['roles']:
46 if key['key_id'] not in self.caller['key_ids']:
47 raise PLCPermissionDenied, "Key must be associated with one of your accounts"
49 key.update(key_fields)
53 self.event_objects = {'Key': [key['key_id']]}
54 self.message = 'key %d updated: %s' % \
55 (key['key_id'], ", ".join(key_fields.keys()))