expose reg-keys as part of Resolve
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 21 Sep 2012 16:47:17 +0000 (18:47 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 21 Sep 2012 16:47:17 +0000 (18:47 +0200)
sfa/managers/registry_manager.py
sfa/storage/model.py
sfa/storage/record.py

index 81c2bec..b5a63a9 100644 (file)
@@ -18,7 +18,7 @@ from sfa.trust.certificate import Certificate, Keypair, convert_public_key
 from sfa.trust.gid import create_uuid
 
 from sfa.storage.model import make_record, RegRecord, RegAuthority, RegUser, RegSlice, RegKey, \
-    augment_with_urn_and_related_hrns
+    augment_with_sfa_builtins
 from sfa.storage.alchemy import dbsession
 
 class RegistryManager:
@@ -155,7 +155,7 @@ class RegistryManager:
         local_records=local_records.all()
         
         for local_record in local_records:
-            augment_with_urn_and_related_hrns (local_record)
+            augment_with_sfa_builtins (local_record)
 
         logger.info("Resolve, (details=%s,type=%s) local_records=%s "%(details,type,local_records))
         local_dicts = [ record.__dict__ for record in local_records ]
@@ -179,7 +179,7 @@ class RegistryManager:
         # xxx somehow here calling dict(record) issues a weird error
         # however record.todict() seems to work fine
         # records.extend( [ dict(record) for record in local_records ] )
-        records.extend( [ record.todict(exclude_type=RegRecord) for record in local_records ] )
+        records.extend( [ record.todict(exclude_types=[RegRecord,RegKey]) for record in local_records ] )
 
         if not records:
             raise RecordNotFound(str(hrns))
@@ -226,8 +226,9 @@ class RegistryManager:
                 records = dbsession.query(RegRecord).filter(RegRecord.hrn.startswith(hrn))
             else:
                 records = dbsession.query(RegRecord).filter_by(authority=hrn)
-            for record in records: augment_with_urn_and_related_hrns (record)
-            record_dicts=[ record.todict(exclude_type=RegRecord) for record in records ]
+            # so that sfi list can show more than plain names...
+            for record in records: augment_with_sfa_builtins (record)
+            record_dicts=[ record.todict(exclude_types=[RegRecord,RegKey]) for record in records ]
     
         return record_dicts
     
index a2fae0e..3be257f 100644 (file)
@@ -374,10 +374,15 @@ augment_map={'authority': {'reg-pis':'reg_pis',},
                       'reg-slices':'reg_slices_as_researcher',},
              }
 
-def augment_with_urn_and_related_hrns (local_record):
+def augment_with_sfa_builtins (local_record):
     # don't ruin the import of that file in a client world
     from sfa.util.xrn import Xrn
-    local_record.urn=Xrn(xrn=local_record.hrn,type=local_record.type).urn
+    # add a 'urn' field
+    setattr(local_record,'reg-urn',Xrn(xrn=local_record.hrn,type=local_record.type).urn)
+    # users have keys and this is needed to synthesize 'users' sent over to CreateSliver
+    if local_record.type=='user':
+        user_keys = [ key.key for key in local_record.reg_keys ]
+        setattr(local_record, 'reg-keys', user_keys)
     # search in map according to record type
     type_map=augment_map.get(local_record.type,{})
     # use type-dep. map to do the job
index 6e58d10..1aa3aa9 100644 (file)
@@ -34,13 +34,14 @@ class Record:
         return "** undef_datetime **"
     
     # it may be important to exclude relationships
-    def todict (self, exclude_type=None):
+    def todict (self, exclude_types=[]):
         d=self.__dict__
         def exclude (k,v):
             if k.startswith('_'): return True
-            if exclude_type:
-                if isinstance (v,exclude_type): return True
-                if isinstance (v,list) and v and isinstance (v[0],exclude_type) : return True
+            if exclude_types:
+                for exclude_type in exclude_types:
+                    if isinstance (v,exclude_type): return True
+                    if isinstance (v,list) and v and isinstance (v[0],exclude_type) : return True
             return False
         keys=[k for (k,v) in d.items() if not exclude(k,v)]
         return dict ( [ (k,d[k]) for k in keys ] )