From: Marco Yuen Date: Wed, 26 Sep 2012 13:30:32 +0000 (-0400) Subject: Implement GetKeys. X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=213d5742acc4d3f08f7193308a3de1205313297d;p=plcapi.git Implement GetKeys. --- diff --git a/PLC/Keys.py b/PLC/Keys.py index ebabd190..60c39ff6 100644 --- a/PLC/Keys.py +++ b/PLC/Keys.py @@ -6,8 +6,9 @@ from PLC.Filter import Filter from PLC.Debug import profile from PLC.Table import Row, Table from PLC.KeyTypes import KeyType, KeyTypes +from PLC.NovaTable import NovaObject, NovaTable -class Key(Row): +class Key(NovaObject): """ Representation of a row in the keys table. To use, instantiate with a dict of values. Update as you would a dict. Commit to the database @@ -18,7 +19,7 @@ class Key(Row): primary_key = 'key_id' join_tables = ['person_key', 'peer_key'] fields = { - 'key_id': Parameter(int, "Key identifier"), + 'key_id': Parameter(str, "Key identifier"), 'key_type': Parameter(str, "Key type"), 'key': Parameter(str, "Key value", max = 4096), 'person_id': Parameter(int, "User to which this key belongs", nullok = True), @@ -95,25 +96,27 @@ class Key(Row): if commit: self.api.db.commit() -class Keys(Table): +class Keys(NovaTable): """ Representation of row(s) from the keys table in the database. """ def __init__(self, api, key_filter = None, columns = None): - Table.__init__(self, api, Key, columns) - - sql = "SELECT %s FROM view_keys WHERE is_blacklisted IS False" % \ - ", ".join(self.columns) + self.api = api + keysManager = self.api.client_shell.nova.keypairs + keyPairs = [] if key_filter is not None: if isinstance(key_filter, (list, tuple, set, int, long)): - key_filter = Filter(Key.fields, {'key_id': key_filter}) + keyPairs = filter(lambda kp: kp.uuid in key_filter, + keysManager.findall()) elif isinstance(key_filter, dict): - key_filter = Filter(Key.fields, key_filter) + keyPairs = keysManager.findall(**key_filter) + elif isinstnace(key_filter, StringTypes): + keyPairs = keyManagers.findall(uuid = key_filter) else: raise PLCInvalidArgument, "Wrong key filter %r"%key_filter - sql += " AND (%s) %s" % key_filter.sql(api) - self.selectall(sql) + self.extend(keyPairs) + diff --git a/PLC/Methods/GetKeys.py b/PLC/Methods/GetKeys.py index 70b3a4db..6c024413 100644 --- a/PLC/Methods/GetKeys.py +++ b/PLC/Methods/GetKeys.py @@ -34,8 +34,8 @@ class GetKeys(Method): keys = Keys(self.api, key_filter, return_fields) # If we are not admin, make sure to only return our own keys - if isinstance(self.caller, Person) and \ - 'admin' not in self.caller['roles']: - keys = filter(lambda key: key['key_id'] in self.caller['key_ids'], keys) + #if isinstance(self.caller, Person) and \ + # 'admin' not in self.caller['roles']: + # keys = filter(lambda key: key['key_id'] in self.caller['key_ids'], keys) return keys