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