4 from sfa.trust.gid import GID
5 from sfa.util.sfalogging import logger
9 # we want to avoid reading all files in the directory
10 # this is because it's common to have backups of all kinds
11 # e.g. *~, *.hide, *-00, *.bak and the like
12 supported_extensions= [ 'gid', 'cert', 'pem' ]
14 def __init__(self, dir):
16 # create the directory to hold the files, if not existing
17 if not os.path.isdir (self.basedir):
18 os.makedirs(self.basedir)
20 def add_gid(self, gid):
21 fn = os.path.join(self.basedir, gid.get_hrn() + ".gid")
25 gid_list = [GID(filename=cert_file) for cert_file in self.get_file_list()]
28 def get_file_list(self):
30 pattern=os.path.join(self.basedir,"*")
31 for cert_file in glob.glob(pattern):
32 if os.path.isfile(cert_file):
33 if self.has_supported_extension(cert_file):
34 file_list.append(cert_file)
36 logger.warning("File %s ignored - supported extensions are %r"%\
37 (cert_file,TrustedRoots.supported_extensions))
40 def has_supported_extension (self,path):
41 (_,ext)=os.path.splitext(path)
42 ext=ext.replace('.','').lower()
43 return ext in TrustedRoots.supported_extensions