removed sfa-clean-peer-records.py
[sfa.git] / sfa / managers / registry_manager.py
index 1c66e53..04daa48 100644 (file)
@@ -7,6 +7,7 @@ import commands
 
 from sfa.util.faults import RecordNotFound, AccountNotEnabled, PermissionError, MissingAuthority, \
     UnknownSfaType, ExistingRecord, NonExistingRecord
+from sfa.util.sfatime import utcparse, datetime_to_epoch
 from sfa.util.prefixTree import prefixTree
 from sfa.util.xrn import Xrn, get_authority, hrn_to_urn, urn_to_hrn
 from sfa.util.plxrn import hrn_to_pl_login_base
@@ -31,6 +32,8 @@ class RegistryManager:
                        if hrn != api.hrn])
         xrn=Xrn(api.hrn)
         return version_core({'interface':'registry',
+                             'sfa': 2,
+                             'geni_api': 2,
                              'hrn':xrn.get_hrn(),
                              'urn':xrn.get_urn(),
                              'peers':peers})
@@ -73,8 +76,8 @@ class RegistryManager:
         rights = api.auth.determine_user_rights(caller_hrn, record)
         # make sure caller has rights to this object
         if rights.is_empty():
-            raise PermissionError(caller_hrn + " has no rights to " + record['name'])
-    
+            raise PermissionError("%s has no rights to %s (%s)" % \
+                                  (caller_hrn, object_hrn, xrn))    
         object_gid = GID(string=record['gid'])
         new_cred = Credential(subject = object_gid.get_subject())
         new_cred.set_gid_caller(caller_gid)
@@ -84,7 +87,9 @@ class RegistryManager:
         new_cred.set_privileges(rights)
         new_cred.get_privileges().delegate_all_privileges(True)
         if 'expires' in record:
-            new_cred.set_expiration(int(record['expires']))
+            date = utcparse(record['expires'])
+            expires = datetime_to_epoch(date)
+            new_cred.set_expiration(int(expires))
         auth_kind = "authority,ma,sa"
         # Parent not necessary, verify with certs
         #new_cred.set_parent(api.auth.hierarchy.get_auth_cred(auth_hrn, kind=auth_kind))
@@ -97,10 +102,10 @@ class RegistryManager:
     def Resolve(self, api, xrns, type=None, full=True):
     
         if not isinstance(xrns, types.ListType):
-            xrns = [xrns]
             # try to infer type if not set and we get a single input
             if not type:
                 type = Xrn(xrns).get_type()
+            xrns = [xrns]
         hrns = [urn_to_hrn(xrn)[0] for xrn in xrns] 
         # load all known registry names into a prefix tree and attempt to find
         # the longest matching prefix