Skip to content

Commit

Permalink
Check for hashlib support on remote host. If not, raise an Environmen…
Browse files Browse the repository at this point in the history
…tException
  • Loading branch information
cgarciaarano committed Jan 21, 2017
1 parent b1ffbc3 commit 67da9cd
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/cuisine.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,8 @@ def file_sha256(location):
# appear before the result, so we simply split and get the last line to
# be on the safe side.
if fabric.api.env[OPTION_HASH] == "python":
if not _hashlib_supported():
raise EnvironmentError("Remote host has not hashlib support. Please, use select_hash('openssl')")
if file_exists(location):
return run("cat {0} | python -c 'import sys,hashlib;sys.stdout.write(hashlib.sha256(sys.stdin.read()).hexdigest())'".format(shell_safe((location))))
else:
Expand All @@ -855,13 +857,21 @@ def file_md5(location):
# appear before the result, so we simply split and get the last line to
# be on the safe side.
if fabric.api.env[OPTION_HASH] == "python":
if not _hashlib_supported():
raise EnvironmentError("Remote host has not hashlib support. Please, use select_hash('openssl')")
if file_exists(location):
return run("cat {0} | python -c 'import sys,hashlib;sys.stdout.write(hashlib.md5(sys.stdin.read()).hexdigest())'".format(shell_safe((location))))
else:
return None
else:
return run('openssl dgst -md5 %s' % (shell_safe(location))).split("\n")[-1].split(")= ",1)[-1].strip()

def _hashlib_supported():
""" Returns True if remote host has hashlib support on Python """
return run("python -c 'import hashlib'", warn_only=True).succeeded



# =============================================================================
#
# PROCESS OPERATIONS
Expand Down

0 comments on commit 67da9cd

Please sign in to comment.