summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhijit Menon-Sen <ams@2ndQuadrant.com>2015-09-30 20:00:34 +0530
committerAbhijit Menon-Sen <ams@2ndQuadrant.com>2015-09-30 22:13:36 +0530
commit0bb34fd0765d56ce17c31fe0d1af3c20cc6f5885 (patch)
treeaf6b27396c31cba122fbd0d46b55e5308c4bde19
parentbf06e36382369e43ef4062eba1e7ff79ca0ad615 (diff)
downloadansible-0bb34fd0765d56ce17c31fe0d1af3c20cc6f5885.tar.gz
Make «ansible-vault view» not write plaintext to a tempfile
CLI already provides a pager() method that feeds $PAGER on stdin, so we just feed that the plaintext from the vault file. We can also eliminate the redundant and now-unused shell_pager_command method in VaultEditor.
-rw-r--r--lib/ansible/cli/vault.py2
-rw-r--r--lib/ansible/parsing/vault/__init__.py17
2 files changed, 3 insertions, 16 deletions
diff --git a/lib/ansible/cli/vault.py b/lib/ansible/cli/vault.py
index 086c55e35e..63aa86e5f0 100644
--- a/lib/ansible/cli/vault.py
+++ b/lib/ansible/cli/vault.py
@@ -138,7 +138,7 @@ class VaultCLI(CLI):
def execute_view(self):
for f in self.args:
- self.editor.view_file(f)
+ self.pager(self.editor.plaintext(f))
def execute_rekey(self):
for f in self.args:
diff --git a/lib/ansible/parsing/vault/__init__.py b/lib/ansible/parsing/vault/__init__.py
index f1e544204a..62df9b8dd1 100644
--- a/lib/ansible/parsing/vault/__init__.py
+++ b/lib/ansible/parsing/vault/__init__.py
@@ -300,20 +300,14 @@ class VaultEditor:
else:
self._edit_file_helper(filename, existing_data=plaintext, force_save=False)
- def view_file(self, filename):
+ def plaintext(self, filename):
check_prereqs()
- # FIXME: Why write this to a temporary file at all? It would be safer
- # to feed it to the PAGER on stdin.
- _, tmp_path = tempfile.mkstemp()
ciphertext = self.read_data(filename)
plaintext = self.vault.decrypt(ciphertext)
- self.write_data(plaintext, tmp_path)
- # drop the user into pager on the tmp file
- call(self._pager_shell_command(tmp_path))
- os.remove(tmp_path)
+ return plaintext
def rekey_file(self, filename, new_password):
@@ -361,13 +355,6 @@ class VaultEditor:
return editor
- def _pager_shell_command(self, filename):
- PAGER = os.environ.get('PAGER','less')
- pager = shlex.split(PAGER)
- pager.append(filename)
-
- return pager
-
class VaultFile(object):
def __init__(self, password, filename):