X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FGetKeys.py;h=73ad9b67910febb423aec504336e7b3c3f53cb27;hb=0395bfd9e88b0f5fbfcbfd91c95fa5baaa9e7fe0;hp=baabca1fd9557e3c7a7dff859cda5b6027b6c3e4;hpb=a1a197680995031d3f1a2565671ec4df4e74dcc0;p=plcapi.git diff --git a/PLC/Methods/GetKeys.py b/PLC/Methods/GetKeys.py index baabca1..73ad9b6 100644 --- a/PLC/Methods/GetKeys.py +++ b/PLC/Methods/GetKeys.py @@ -1,42 +1,39 @@ from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed +from PLC.Filter import Filter from PLC.Keys import Key, Keys -from PLC.Auth import PasswordAuth +from PLC.Auth import Auth class GetKeys(Method): """ - Get an array of structs containing the keys for the specified - key_ids. If key_id_list is not specified, all keys - will be queried. + Returns an array of structs containing details about keys. If + key_filter is specified and is an array of key identifiers, or a + struct of key attributes, only keys matching the filter will be + returned. If return_fields is specified, only the specified + details will be returned. - Admin may get all keys. Non-admins can only get their own keys + Admin may query all keys. Non-admins may only query their own + keys. """ roles = ['admin', 'pi', 'user', 'tech'] accepts = [ - PasswordAuth(), - [Key.fields['key_id']] + Auth(), + Mixed([Mixed(Key.fields['key_id'])], + Filter(Key.fields)), + Parameter([str], "List of fields to return", nullok = True) ] returns = [Key.fields] - def call(self, auth, key_id_list = None): - - #if we are not admin, make sure to only return our own keys + + def call(self, auth, key_filter = None, return_fields = None): + keys = Keys(self.api, key_filter, return_fields) + + # If we are not admin, make sure to only return our own keys if 'admin' not in self.caller['roles']: - if key_id_list is None: - key_id_list = self.caller['key_ids'] - else: - valid_keys = lambda x: x in self.caller['key_ids'] - key_id_list = filter(valid_keys, key_id_list) - - keys = Keys(self.api, key_id_list).values() - - # Filter out undesired or None fields (XML-RPC cannot marshal - # None) and turn each key into a real dict. - valid_return_fields_only = lambda (key, value): value is not None - keys = [dict(filter(valid_return_fields_only, key.items())) \ - for key in keys] + keys = filter(lambda key: key['key_id'] in self.caller['key_ids'], keys) + return keys