Switch from base64 encoding to sha1 digest for unique cache filename

This commit is contained in:
Erik Johnson 2018-09-28 09:39:56 -05:00
parent 0e26dc6f70
commit 7ddfd720ed
No known key found for this signature in database
GPG Key ID: 5E5583C437808F3F
2 changed files with 12 additions and 2 deletions

View File

@ -1735,7 +1735,7 @@ class State(object):
troot = os.path.join(self.opts['cachedir'], self.jid)
tfile = os.path.join(
troot,
salt.utils.hashutils.base64_b64encode(tag)[:32])
salt.utils.hashutils.sha1_digest(tag))
if not os.path.isdir(troot):
try:
os.makedirs(troot)
@ -2097,7 +2097,7 @@ class State(object):
ret_cache = os.path.join(
self.opts['cachedir'],
self.jid,
salt.utils.hashutils.base64_b64encode(tag)[:32])
salt.utils.hashutils.sha1_digest(tag))
if not os.path.isfile(ret_cache):
ret = {'result': False,
'comment': 'Parallel process failed to return',

View File

@ -82,6 +82,16 @@ def md5_digest(instr):
return hashlib.md5(instr).hexdigest()
def sha1_digest(instr):
'''
Generate an sha1 hash of a given string.
'''
if six.PY3:
b = salt.utils.to_bytes(instr)
return hashlib.sha1(b).hexdigest()
return hashlib.sha1(instr).hexdigest()
def sha256_digest(instr):
'''
Generate an sha256 hash of a given string.