gid creation code change, again. NT.
[sfa.git] / sfa / senslab / slab-import.py
index 1cfbda1..38be563 100644 (file)
@@ -6,6 +6,8 @@
 #
 ###########################################################################
 import sys
+import datetime
+import time
 from sfa.senslab.OARrestapi import OARapi
 from sfa.senslab.LDAPapi import LDAPapi
 from sfa.senslab.slabdriver import SlabDriver
@@ -14,7 +16,7 @@ from sfa.util.xrn import hrn_to_urn, get_authority,Xrn,get_leaf
 from sfa.util.table import SfaTable
 from sfa.util.record import SfaRecord
 from sfa.trust.hierarchy import Hierarchy
-from sfa.trust.certificate import Keypair
+from sfa.trust.certificate import Keypair,convert_public_key
 from sfa.trust.gid import create_uuid
 
 
@@ -66,6 +68,8 @@ def import_node(hrn, node):
     node_gid = AuthHierarchy.create_gid(urn, create_uuid(), pkey)
     node_record = SfaRecord(hrn=hrn, gid=node_gid, type="node", pointer=node['node_id'])
     node_record['authority'] = get_authority(node_record['hrn'])
+    extime = datetime.datetime.utcnow()
+    node_record['date_created'] = int(time.mktime(extime.timetuple()))
     existing_records = table.find({'hrn': hrn, 'type': 'node', 'pointer': node['node_id']})
     if not existing_records:
         print>>sys.stderr, " \r\n \t slab-import : node record %s inserted" %(node_record['hrn'])
@@ -76,14 +80,16 @@ def import_node(hrn, node):
         table.update(node_record)
 
 # person is already a sfa record 
-def import_person(person):       
+def import_person(authname,person):       
     existing_records = table.find({'hrn': person['hrn'], 'type': 'user'})
+    extime = datetime.datetime.utcnow()
+    person['date_created'] = int(time.mktime(extime.timetuple()))
     if not existing_records:
         print>>sys.stderr, " \r\n \t slab-import : person record %s inserted" %(person['hrn'])
         uuid=create_uuid() 
         RSA_KEY_STRING=person['pkey']
         pkey=convert_public_key(RSA_KEY_STRING)
-       person['gid']=self.senslabauth.create_gid("urn:publicid:IDN+"+self.authname+"+user+"+ldapentry[1]['uid'][0], uuid, pkey, CA=False)
+       person['gid']=AuthHierarchy.create_gid("urn:publicid:IDN+"+authname+"+user+"+person['uid'], uuid, pkey, CA=False).save_to_string()
         table.insert(person)
     else:
         existing_record = existing_records[0]
@@ -99,6 +105,10 @@ def import_slice(person):
     gid = AuthHierarchy.create_gid(urn, create_uuid(), pkey)
     slice_record= SfaRecord(hrn=hrn, gid=gid, type="slice", pointer=-1)
     slice_record['authority'] = get_authority(slice_record['hrn'])
+   
+    extime = datetime.datetime.utcnow()
+    slice_record['date_created'] = int(time.mktime(extime.timetuple()))
+                               
     print>>sys.stderr, " \r\n \t slab-import : slice record %s " %(slice_record['hrn']) 
     existing_records = table.find({'hrn': slice_record['hrn'], 'type': 'slice'})
     if not existing_records:
@@ -199,7 +209,7 @@ def main():
     for person in ldap_person_list:
         if person['hrn'] not in existing_hrns or \
             (person['hrn'], 'user') not in existing_records :
-            import_person(person)
+            import_person(root_auth,person)
             import_slice(person)
 
 # import slices