Skip to content

Commit

Permalink
Fix exceptions thrown from cryptography import (#16723)
Browse files Browse the repository at this point in the history
A simple import of cryptography can throw several types of errors. For example,
if `setuptools` is less than cryptography's minimum requirement of 11.3, then
this import of cryptography will throw a VersionConflict here. An earlier case
threw a DistributionNotFound exception.

An optional dependency should not stop ansible. If the error is more than
an ImportError, log a warning, so that errors can be fixed in ansible or
elsewhere.
  • Loading branch information
cdosborn authored and abadger committed Jul 21, 2016
1 parent ed959d7 commit 505a1de
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/ansible/parsing/vault/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
from binascii import hexlify
from binascii import unhexlify

try:
from __main__ import display
except ImportError:
from ansible.utils.display import Display
display = Display()

# Note: Only used for loading obsolete VaultAES files. All files are written
# using the newer VaultAES256 which does not require md5
from hashlib import md5
Expand Down Expand Up @@ -71,10 +77,9 @@
except ImportError:
pass
except Exception as e:
if e.__module__ == 'pkg_resources' and e.__class__.__name__ == 'DistributionNotFound':
pass
else:
raise
display.warning("Optional dependency 'cryptography' raised an exception, falling back to 'Crypto'")
import traceback
traceback.print_exc()

from ansible.compat.six import PY3
from ansible.utils.unicode import to_unicode, to_bytes
Expand Down

0 comments on commit 505a1de

Please sign in to comment.