- re-enable return_fields specification
[plcapi.git] / PLC / Methods / GetKeys.py
index 9f8f7f4..fcbd2b1 100644 (file)
@@ -1,13 +1,17 @@
 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 Auth
 
 class GetKeys(Method):
     """
     Returns an array of structs containing details about keys. If
-    key_ids is specified, only the specified keys will be queried.
+    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 query all keys. Non-admins may only query their own
     keys.
@@ -17,16 +21,18 @@ class GetKeys(Method):
 
     accepts = [
         Auth(),
-        [Key.fields['key_id']]
+        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_ids = None):
+    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']:
-            key_ids = set(key_ids).intersection(self.caller['key_ids'])
-            if not key_ids:
-                return []
+            keys = filter(lambda key: key['key_id'] in self.caller['key_ids'], keys)
 
-       return Keys(self.api, key_ids).values()
+        return keys