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 PasswordAuth
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()))
23 for field in key_fields.values():
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]).values()
40 raise PLCInvalidArgument, "No such key"
43 if 'admin' not in self.caller['roles']:
44 if key['key_id'] not in self.caller['key_ids']:
45 raise PLCPermissionDenied, "Key must be associated with one of your accounts"
47 key.update(key_fields)