From 52f2425a98c416c36553cc805882a586984194b6 Mon Sep 17 00:00:00 2001 From: Chris Hambridge Date: Wed, 16 Aug 2017 11:28:38 -0400 Subject: [PATCH] Catch decryption error and provide user with message. Closes #132. --- rho/vault.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rho/vault.py b/rho/vault.py index 62eb611..72bda6b 100644 --- a/rho/vault.py +++ b/rho/vault.py @@ -12,6 +12,7 @@ from __future__ import print_function import os +import sys import json import uuid from tempfile import gettempdir @@ -19,6 +20,8 @@ from getpass import getpass import yaml from ansible.parsing.vault import VaultLib +from ansible.errors import AnsibleError +from rho.translation import _ as t def represent_none(self, _): @@ -88,7 +91,11 @@ def load(self, stream): :param stream: The stream to read data from :returns: The decrypted data """ - return self.vault.decrypt(stream) + try: + return self.vault.decrypt(stream) + except AnsibleError: + print(t("Unable to decrypt file using given vault password")) + sys.exit(1) def load_secure_file(self, secure_file): """ Read vault secured file and return python object