setting peer_id of remote key object
[sfa.git] / sfa / methods / register.py
index ea86051..00ec075 100644 (file)
@@ -62,7 +62,7 @@ class register(Method):
         if existing_records:
             raise ExistingRecord(name)
         
-        if (type == "sa") or (type=="ma"):
+        if type in ["authority", "sa", "ma"]:
             # update the tree
             if not self.api.auth.hierarchy.auth_exists(name):
                 self.api.auth.hierarchy.create_auth(name)
@@ -78,10 +78,8 @@ class register(Method):
 
             # if registering a sa, see if a ma already exists
             # if registering a ma, see if a sa already exists
-            if (type == "sa"):
-                other_rec = table.resolve("ma", record.get_name())
-            elif (type == "ma"):
-                other_rec = table.resolve("sa", record.get_name())
+            if type in ["authority", "sa", "ma"]:
+                other_rec = table.resolve("authority", record.get_name())
 
             if other_rec:
                 print >> log, "linking ma and sa to the same plc site"
@@ -109,8 +107,8 @@ class register(Method):
             record.set_pointer(pointer)
            
            # Add the user's key
-            if record['keys']:
-               self.api.plshell.AddPersonKey(self.api.plauth, pointer, {'key_type' : 'ssh', 'key' : record['keys'][0]})
+            if record['key']:
+               self.api.plshell.AddPersonKey(self.api.plauth, pointer, {'key_type' : 'ssh', 'key' : record['key']})
 
         elif (type == "node"):
             pl_record = self.api.geni_fields_to_pl_fields(type, name, record)
@@ -121,7 +119,11 @@ class register(Method):
         else:
             raise UnknownGeniType(type)
 
-        table.insert(record)
+        # SFA upcalls may exist in PLCAPI and they could have already added the
+        # record for us. Lets check if the record already exists  
+        existing_records = table.resolve(type, name)
+        if not existing_records:
+            table.insert(record)
 
         # update membership for researchers, pis, owners, operators
         self.api.update_membership(None, record)