mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
More helpful prompts from ansible-vault encrypt/decrypt
Now we issue a "Reading … from stdin" prompt if our input isatty(), as gpg does. We also suppress the "x successful" confirmation message at the end if we're part of a pipeline. (The latter requires that we not close sys.stdout in VaultEditor, and for symmetry we do the same for sys.stdin, though it doesn't matter in that case.)
This commit is contained in:
parent
b6de6e69a6
commit
090cfc9e03
2 changed files with 17 additions and 10 deletions
|
@ -329,25 +329,24 @@ class VaultEditor:
|
|||
def read_data(self, filename):
|
||||
try:
|
||||
if filename == '-':
|
||||
f = sys.stdin
|
||||
data = sys.stdin.read()
|
||||
else:
|
||||
f = open(filename, "rb")
|
||||
data = f.read()
|
||||
f.close()
|
||||
with open(filename, "rb") as fh:
|
||||
data = fh.read()
|
||||
except Exception as e:
|
||||
raise AnsibleError(str(e))
|
||||
|
||||
return data
|
||||
|
||||
def write_data(self, data, filename):
|
||||
bytes = to_bytes(data, errors='strict')
|
||||
if filename == '-':
|
||||
f = sys.stdout
|
||||
sys.stdout.write(bytes)
|
||||
else:
|
||||
if os.path.isfile(filename):
|
||||
os.remove(filename)
|
||||
f = open(filename, "wb")
|
||||
f.write(to_bytes(data, errors='strict'))
|
||||
f.close()
|
||||
with open(filename, "wb") as fh:
|
||||
fh.write(bytes)
|
||||
|
||||
def shuffle_files(self, src, dest):
|
||||
# overwrite dest with src
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue