Changeset 9be06f0 for fedd


Ignore:
Timestamp:
Apr 6, 2012 3:19:59 PM (13 years ago)
Author:
Ted Faber <faber@…>
Branches:
compt_changes, master
Children:
cf7bc45
Parents:
cde9b98
Message:

Be more principled about loading credentials

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/authorizer.py

    rcde9b98 r9be06f0  
    302302
    303303    def import_credentials(self, file_list=None, data_list=None):
     304        '''
     305        Import a list of credentials.  Be careful about dependencies and only
     306        use one logic loop.  if files are given, append them to the list of
     307        chunks and then try to read each chunk as an ID and then the failed
     308        ones as attributes.
     309        '''
     310        if file_list:
     311            if data_list is None: data_list = []
     312            for fn in file_list:
     313                try:
     314                    f = open(fn, 'r')
     315                    data_list.append(f.read())
     316                    f.close()
     317                except EnvironmentError, e:
     318                    # Ignore unreadable files
     319                    pass
     320        # Now one way or another data_list is ready
    304321        if data_list:
    305             return any([self.import_credential(data=d) for d in data_list])
    306         elif file_list:
    307             return any([self.import_credential(file=f) for f in file_list])
     322            rv = False
     323            attr_list = [ ]
     324            for d in data_list:
     325                if self.context.load_id_chunk(d) != ABAC.ABAC_CERT_SUCCESS:
     326                    attr_list.append(d)
     327                else:
     328                    rv = True
     329
     330            for d in attr_list:
     331                v = self.context.load_attribute_chunk(d)
     332                if v == ABAC.ABAC_CERT_SUCCESS:
     333                    rv = True
     334            return rv
    308335        else:
    309336            return False
Note: See TracChangeset for help on using the changeset viewer.