X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fmanagers%2Fregistry_manager_pl.py;h=e20be089dd75d2378bc726b0b6d33a938c140020;hb=dec7138b35234db846d96dc6ce3b5a402c474a1d;hp=c8d56bd20acf97265bf7f92ecfd34c0cb9a8b8d8;hpb=d212baa505ec0ff212aa3332f76982b2de2612c2;p=sfa.git diff --git a/sfa/managers/registry_manager_pl.py b/sfa/managers/registry_manager_pl.py index c8d56bd2..e20be089 100644 --- a/sfa/managers/registry_manager_pl.py +++ b/sfa/managers/registry_manager_pl.py @@ -1,19 +1,28 @@ import types import time + +from sfa.util.faults import * from sfa.util.prefixTree import prefixTree from sfa.util.record import SfaRecord from sfa.util.table import SfaTable from sfa.util.record import SfaRecord from sfa.trust.gid import GID -from sfa.util.namespace import * -from sfa.trust.credential import * -from sfa.trust.certificate import * -from sfa.util.faults import * +from sfa.util.xrn import Xrn, get_leaf, get_authority, hrn_to_urn, urn_to_hrn +from sfa.util.plxrn import hrn_to_pl_login_base +from sfa.trust.credential import Credential +from sfa.trust.certificate import Certificate, Keypair +from sfa.trust.gid import create_uuid +from sfa.util.version import version_core -def get_version(api): - version = {} - version['geni_api'] = 1 - return version +# The GENI GetVersion call +def GetVersion(api): + peers =dict ([ (peername,v._ServerProxy__host) for (peername,v) in api.registries.iteritems() + if peername != api.hrn]) + xrn=Xrn(api.hrn) + return version_core({'interface':'registry', + 'hrn':xrn.get_hrn(), + 'urn':xrn.get_urn(), + 'peers':peers}) def get_credential(api, xrn, type, is_self=False): # convert xrn to hrn @@ -64,6 +73,8 @@ def get_credential(api, xrn, type, is_self=False): #new_cred.set_pubkey(object_gid.get_pubkey()) new_cred.set_privileges(rights) new_cred.get_privileges().delegate_all_privileges(True) + if 'expires' in record: + new_cred.set_expiration(int(record['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)) @@ -73,37 +84,16 @@ def get_credential(api, xrn, type, is_self=False): return new_cred.save_to_string(save_parents=True) -# The GENI GetVersion call -def GetVersion(): - version = {} - version['geni_api'] = 1 - return version - - - -# The GENI resolve call -def Resolve(api, xrn, creds): - records = resolve(api, xrn) - - if len(records) == 0: - return {} - - record = records[0] - if record.type == 'slice': - return {'geni_urn': xrn, 'geni_creator': " ".join(record.PI)} - if record.type == 'user': - return {'geni_urn': xrn, 'geni_certificate': record.gid} - - +def resolve(api, xrns, type=None, full=True): -def resolve(api, xrns, type=None, origin_hrn=None, full=True): - - # load all know registry names into a prefix tree and attempt to find + # load all known registry names into a prefix tree and attempt to find # the longest matching prefix if not isinstance(xrns, types.ListType): + if not type: + type = Xrn(xrns).get_type() xrns = [xrns] hrns = [urn_to_hrn(xrn)[0] for xrn in xrns] - # create a dict whre key is an registry hrn and its value is a + # create a dict where key is a registry hrn and its value is a # hrns at that registry (determined by the known prefix tree). xrn_dict = {} registries = api.registries @@ -128,7 +118,7 @@ def resolve(api, xrns, type=None, origin_hrn=None, full=True): xrns = xrn_dict[registry_hrn] if registry_hrn != api.hrn: credential = api.getCredential() - peer_records = registries[registry_hrn].resolve(credential, xrns, origin_hrn) + peer_records = registries[registry_hrn].Resolve(xrns, credential) records.extend([SfaRecord(dict=record).as_dict() for record in peer_records]) # try resolving the remaining unfound records at the local registry @@ -170,10 +160,10 @@ def list(api, xrn, origin_hrn=None): records = [] if registry_hrn != api.hrn: credential = api.getCredential() - record_list = registries[registry_hrn].list(credential, xrn, origin_hrn) + record_list = registries[registry_hrn].List(xrn, credential) records = [SfaRecord(dict=record).as_dict() for record in record_list] - # if we still havnt found the record yet, try the local registry + # if we still have not found the record yet, try the local registry if not records: if not api.auth.hierarchy.auth_exists(hrn): raise MissingAuthority(hrn) @@ -184,6 +174,13 @@ def list(api, xrn, origin_hrn=None): return records +def create_gid(api, xrn, cert): + # get the authority + authority = Xrn(xrn=xrn).get_authority_hrn() + auth_info = api.auth.get_auth_info(authority) + + + def register(api, record): hrn, type = record['hrn'], record['type'] @@ -202,7 +199,6 @@ def register(api, record): record['authority'] = get_authority(record['hrn']) type = record['type'] hrn = record['hrn'] - api.auth.verify_object_permission(hrn) auth_info = api.auth.get_auth_info(record['authority']) pub_key = None # make sure record has a gid @@ -298,7 +294,6 @@ def update(api, record_dict): type = new_record['type'] hrn = new_record['hrn'] urn = hrn_to_urn(hrn,type) - api.auth.verify_object_permission(hrn) table = SfaTable() # make sure the record exists records = table.findObjects({'type': type, 'hrn': hrn}) @@ -379,20 +374,18 @@ def update(api, record_dict): return 1 -def remove(api, xrn, type, origin_hrn=None): - # convert xrn to hrn - if type: - hrn = urn_to_hrn(xrn)[0] - else: - hrn, type = urn_to_hrn(xrn) +# expecting an Xrn instance +def remove(api, xrn, origin_hrn=None): table = SfaTable() - filter = {'hrn': hrn} - if type not in ['all', '*']: + filter = {'hrn': xrn.get_hrn()} + hrn=xrn.get_hrn() + type=xrn.get_type() + if type and type not in ['all', '*']: filter['type'] = type + records = table.find(filter) - if not records: - raise RecordNotFound(hrn) + if not records: raise RecordNotFound(hrn) record = records[0] type = record['type']