mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 03:11:24 -07:00
Making the switch to v2
This commit is contained in:
parent
8cf4452d48
commit
ce3ef7f4c1
486 changed files with 7948 additions and 9070 deletions
|
@ -20,6 +20,7 @@ from __future__ import (absolute_import, division, print_function)
|
|||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
from ansible.errors import AnsibleError
|
||||
|
||||
# Note, sha1 is the only hash algorithm compatible with python2.4 and with
|
||||
# FIPS-140 mode (as of 11-2014)
|
||||
|
@ -43,6 +44,8 @@ def secure_hash_s(data, hash_func=sha1):
|
|||
|
||||
digest = hash_func()
|
||||
try:
|
||||
if not isinstance(data, basestring):
|
||||
data = "%s" % data
|
||||
digest.update(data)
|
||||
except UnicodeEncodeError:
|
||||
digest.update(data.encode('utf-8'))
|
||||
|
@ -62,8 +65,8 @@ def secure_hash(filename, hash_func=sha1):
|
|||
digest.update(block)
|
||||
block = infile.read(blocksize)
|
||||
infile.close()
|
||||
except IOError, e:
|
||||
raise errors.AnsibleError("error while accessing the file %s, error was: %s" % (filename, e))
|
||||
except IOError as e:
|
||||
raise AnsibleError("error while accessing the file %s, error was: %s" % (filename, e))
|
||||
return digest.hexdigest()
|
||||
|
||||
# The checksum algorithm must match with the algorithm in ShellModule.checksum() method
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue