Handle vault filenames with nonascii chars when displaying messages. Fixes #33879 (#33926)

This commit is contained in:
Matt Martz 2017-12-14 16:02:25 -06:00 committed by GitHub
parent ff4eb94a04
commit 0b9f1f7982
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -77,7 +77,7 @@ from ansible import constants as C
from ansible.module_utils.six import PY3, binary_type from ansible.module_utils.six import PY3, binary_type
# Note: on py2, this zip is izip not the list based zip() builtin # Note: on py2, this zip is izip not the list based zip() builtin
from ansible.module_utils.six.moves import zip from ansible.module_utils.six.moves import zip
from ansible.module_utils._text import to_bytes, to_text from ansible.module_utils._text import to_bytes, to_text, to_native
try: try:
from __main__ import display from __main__ import display
@ -663,7 +663,7 @@ class VaultLib:
if not is_encrypted(b_vaulttext): if not is_encrypted(b_vaulttext):
msg = "input is not vault encrypted data" msg = "input is not vault encrypted data"
if filename: if filename:
msg += "%s is not a vault encrypted file" % filename msg += "%s is not a vault encrypted file" % to_native(filename)
raise AnsibleError(msg) raise AnsibleError(msg)
b_vaulttext, dummy, cipher_name, vault_id = parse_vaulttext_envelope(b_vaulttext, b_vaulttext, dummy, cipher_name, vault_id = parse_vaulttext_envelope(b_vaulttext,
@ -699,7 +699,7 @@ class VaultLib:
vault_id_matchers.append(vault_id) vault_id_matchers.append(vault_id)
_matches = match_secrets(self.secrets, vault_id_matchers) _matches = match_secrets(self.secrets, vault_id_matchers)
if _matches: if _matches:
display.vvvvv('We have a secret associated with vault id (%s), will try to use to decrypt %s' % (vault_id, filename)) display.vvvvv('We have a secret associated with vault id (%s), will try to use to decrypt %s' % (vault_id, to_text(filename)))
else: else:
display.vvvvv('Found a vault_id (%s) in the vault text, but we do not have a associated secret (--vault-id)' % (vault_id)) display.vvvvv('Found a vault_id (%s) in the vault text, but we do not have a associated secret (--vault-id)' % (vault_id))
@ -713,7 +713,7 @@ class VaultLib:
# for vault_secret_id in vault_secret_ids: # for vault_secret_id in vault_secret_ids:
for vault_secret_id, vault_secret in matched_secrets: for vault_secret_id, vault_secret in matched_secrets:
display.vvvvv('Trying to use vault secret=(%s) id=%s to decrypt %s' % (vault_secret, vault_secret_id, filename)) display.vvvvv('Trying to use vault secret=(%s) id=%s to decrypt %s' % (vault_secret, vault_secret_id, to_text(filename)))
try: try:
# secret = self.secrets[vault_secret_id] # secret = self.secrets[vault_secret_id]
@ -726,24 +726,24 @@ class VaultLib:
except AnsibleVaultFormatError as exc: except AnsibleVaultFormatError as exc:
msg = "There was a vault format error" msg = "There was a vault format error"
if filename: if filename:
msg += ' in %s' % (filename) msg += ' in %s' % (to_text(filename))
msg += ': %s' % exc msg += ': %s' % exc
display.warning(msg) display.warning(msg)
raise raise
except AnsibleError as e: except AnsibleError as e:
display.vvvv('Tried to use the vault secret (%s) to decrypt (%s) but it failed. Error: %s' % display.vvvv('Tried to use the vault secret (%s) to decrypt (%s) but it failed. Error: %s' %
(vault_secret_id, filename, e)) (vault_secret_id, to_text(filename), e))
continue continue
else: else:
msg = "Decryption failed (no vault secrets were found that could decrypt)" msg = "Decryption failed (no vault secrets were found that could decrypt)"
if filename: if filename:
msg += " on %s" % filename msg += " on %s" % to_native(filename)
raise AnsibleVaultError(msg) raise AnsibleVaultError(msg)
if b_plaintext is None: if b_plaintext is None:
msg = "Decryption failed" msg = "Decryption failed"
if filename: if filename:
msg += " on %s" % filename msg += " on %s" % to_native(filename)
raise AnsibleError(msg) raise AnsibleError(msg)
return b_plaintext, vault_id_used return b_plaintext, vault_id_used