From: Thierry Parmentelat Date: Thu, 20 Sep 2012 17:32:02 +0000 (+0200) Subject: add an optional 'options' dict to Resolve (checked that old clients X-Git-Tag: sfa-2.1-15~11 X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=commitdiff_plain;h=872ab6f6b720fac6dff888ba32a0ec73911827ee add an optional 'options' dict to Resolve (checked that old clients would not break) go deeper yet in cleaning up the amount of extra fields in records turns out CreateSliver actually needs to re-synthesize a whole lot of data about users (for when account creation needs to take place) in a truly federated environment this is not going to work, the registry will never have enough data for account creation as this is testbed-dependent as far as I can tell this is a blatant flaw in the architecture this code might work - accidentally - in a simple one-SFA-one-PLC setup but this needs more work --- diff --git a/sfa/client/client_helper.py b/sfa/client/client_helper.py index 291a8731..d25873fc 100644 --- a/sfa/client/client_helper.py +++ b/sfa/client/client_helper.py @@ -4,38 +4,39 @@ def pg_users_arg(records): for record in records: if record['type'] != 'user': continue - user = {'urn': record['geni_urn'], + user = {'urn': record['urn'], 'keys': record['keys']} users.append(user) return users -def sfa_users_arg(records, slice_record): +def sfa_users_arg (records, slice_record): users = [] for record in records: if record['type'] != 'user': continue try: - user = {'urn': record['geni_urn'], # - 'keys': record['keys'], - 'email': record['email'], # needed for MyPLC - 'person_id': record['person_id'], # needed for MyPLC - 'first_name': record['first_name'], # needed for MyPLC - 'last_name': record['last_name'], # needed for MyPLC - 'slice_record': slice_record, # needed for legacy refresh peer - 'key_ids': record['key_ids'] # needed for legacy refresh peer - } + user = {'urn': record['urn'], # +# all right, so this is sooo totally wrong +# 'keys': record['keys'], +# 'email': record['email'], # needed for MyPLC +# 'person_id': record['person_id'], # needed for MyPLC +# 'first_name': record['first_name'], # needed for MyPLC +# 'last_name': record['last_name'], # needed for MyPLC +# 'slice_record': slice_record, # needed for legacy refresh peer +# 'key_ids': record['key_ids'] # needed for legacy refresh peer + } except: # handle NITOS user args - user = {'urn': record['geni_urn'], - 'keys': record['keys'], - 'email': record['email'], - 'user_id': record['user_id'], - 'slice_record': slice_record, - } - + user = {'urn': record['urn'], + 'keys': record['keys'], + 'email': record['email'], + 'user_id': record['user_id'], + 'slice_record': slice_record, + } + users.append(user) - return users + return users def sfa_to_pg_users_arg(users): diff --git a/sfa/client/sfi.py b/sfa/client/sfi.py index 35270191..f16a2346 100644 --- a/sfa/client/sfi.py +++ b/sfa/client/sfi.py @@ -221,7 +221,7 @@ def terminal_render_user (record, options): def terminal_render_slice (record, options): print "%s (Slice)"%record['hrn'], if record.get('reg-researchers',None): print " [USERS %s]"%(" and ".join(record['reg-researchers'])), - print record.keys() +# print record.keys() print "" def terminal_render_authority (record, options): print "%s (Authority)"%record['hrn'], @@ -521,7 +521,11 @@ class Sfi: # Main: parse arguments and dispatch to command # def dispatch(self, command, command_options, command_args): - return getattr(self, command)(command_options, command_args) + method=getattr(self, command,None) + if not method: + print "Unknown command %s"%command + return + return method(command_options, command_args) def main(self): self.sfi_parser = self.create_parser() @@ -556,8 +560,8 @@ class Sfi: try: self.dispatch(command, command_options, command_args) - except KeyError: - self.logger.critical ("Unknown command %s"%command) + except: + self.logger.log_exc ("sfi command %s failed"%command) sys.exit(1) return @@ -904,9 +908,8 @@ or version information about sfi itself self.print_help() sys.exit(1) hrn = args[0] - # xxx should set details=True here but that's not in the xmlrpc interface ... - # record_dicts = self.registry().Resolve(hrn, self.my_credential_string, details=True) - record_dicts = self.registry().Resolve(hrn, self.my_credential_string) + # explicitly require Resolve to run in details mode + record_dicts = self.registry().Resolve(hrn, self.my_credential_string, {'details':True}) record_dicts = filter_records(options.type, record_dicts) if not record_dicts: self.logger.error("No record of type %s"% options.type) diff --git a/sfa/managers/managerwrapper.py b/sfa/managers/managerwrapper.py index 58a0527b..946f7d2b 100644 --- a/sfa/managers/managerwrapper.py +++ b/sfa/managers/managerwrapper.py @@ -24,6 +24,9 @@ class ManagerWrapper: # to the actual method calls anyway self.manager = manager(config) else: + # that's what happens when there's something wrong with the db + # or any bad stuff of that kind at startup time + logger.log_exc("Failed to create a manager, startup sequence is broken") raise SfaAPIError,"Argument to ManagerWrapper must be a module or class" self.interface = interface diff --git a/sfa/managers/registry_manager.py b/sfa/managers/registry_manager.py index 898fac3a..81c2bec7 100644 --- a/sfa/managers/registry_manager.py +++ b/sfa/managers/registry_manager.py @@ -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_related_hrns + augment_with_urn_and_related_hrns 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_related_hrns (local_record) + augment_with_urn_and_related_hrns (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 ] @@ -226,7 +226,7 @@ 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_related_hrns (record) + for record in records: augment_with_urn_and_related_hrns (record) record_dicts=[ record.todict(exclude_type=RegRecord) for record in records ] return record_dicts diff --git a/sfa/methods/Resolve.py b/sfa/methods/Resolve.py index 6a323440..f3a6e671 100644 --- a/sfa/methods/Resolve.py +++ b/sfa/methods/Resolve.py @@ -23,15 +23,18 @@ class Resolve(Method): Mixed(Parameter(str, "Human readable name (hrn or urn)"), Parameter(list, "List of Human readable names ([hrn])")), Mixed(Parameter(str, "Credential string"), - Parameter(list, "List of credentials)")) + Parameter(list, "List of credentials)")), + Parameter(dict, "options"), ] # xxx used to be [SfaRecord] returns = [Parameter(dict, "registry record")] - def call(self, xrns, creds): - # xxx should be ar arg - details=False + def call(self, xrns, creds, options={}): + # use details=False by default, only when explicitly specified do we want + # to mess with the testbed details + if 'details' in options: details=options['details'] + else: details=False type = None if not isinstance(xrns, types.ListType): type = Xrn(xrns).get_type() diff --git a/sfa/storage/model.py b/sfa/storage/model.py index 05046d06..a2fae0e5 100644 --- a/sfa/storage/model.py +++ b/sfa/storage/model.py @@ -374,7 +374,10 @@ augment_map={'authority': {'reg-pis':'reg_pis',}, 'reg-slices':'reg_slices_as_researcher',}, } -def augment_with_related_hrns (local_record): +def augment_with_urn_and_related_hrns (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 # search in map according to record type type_map=augment_map.get(local_record.type,{}) # use type-dep. map to do the job