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 'admin' not in self.caller['roles']:
42 if key['key_id'] not in self.caller['key_ids']:
43 raise PLCPermissionDenied, "Key must be associated with one of your accounts"
45 key.update(key_fields)