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