mirror of
https://github.com/valitydev/salt.git
synced 2024-11-09 01:36:48 +00:00
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:
parent
792a82a32f
commit
f634db4390
@ -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):
|
||||||
'''
|
'''
|
||||||
|
Loading…
Reference in New Issue
Block a user