cache signing file data

This will make it so that we don't have to read from the disk every time
that a key reports, only if the mtime has changed.
This commit is contained in:
Daniel Wallace 2018-10-19 10:15:43 -05:00
parent 792a82a32f
commit f634db4390
No known key found for this signature in database
GPG Key ID: 5FA5E5544F010D48

View File

@ -275,6 +275,7 @@ class AutoKey(object):
Implement the methods to run auto key acceptance and rejection Implement the methods to run auto key acceptance and rejection
''' '''
def __init__(self, opts): def __init__(self, opts):
self.signing_files = {}
self.opts = opts self.opts = opts
def check_permissions(self, filename): def check_permissions(self, filename):
@ -314,15 +315,15 @@ class AutoKey(object):
log.warning('Wrong permissions for %s, ignoring content', signing_file) log.warning('Wrong permissions for %s, ignoring content', signing_file)
return False return False
with salt.utils.files.fopen(signing_file, 'r') as fp_: mtime = os.path.getmtime(signing_file)
for line in fp_: if self.signing_files.get(signing_file, {}).get('mtime') != mtime:
line = line.strip() self.signing_files.setdefault(signing_file, {})['mtime'] = mtime
if line.startswith('#'): with salt.utils.files.fopen(signing_file, 'r') as fp_:
continue self.signing_files[signing_file]['data'] = [
else: entry for entry in [line.strip() for line in fp_] if not entry.strip().startswith('#')
if salt.utils.stringutils.expr_match(keyid, line): ]
return True return any(salt.utils.stringutils.expr_match(keyid, line) for line
return False in self.signing_files[signing_file].get('data', []))
def check_autosign_dir(self, keyid): def check_autosign_dir(self, keyid):
''' '''