This repository has been archived on 2020-06-17. You can view files and clone it, but cannot push or open issues or pull requests.
autonomic/autonomic/passstore.py

23 lines
707 B
Python

"""Password store management module."""
import os
import subprocess
from autonomic.settings import INFRASTRUCTURE_PATH, PASSWORD_STORE_PATH
from autonomic.system import exit_with_msg
def get_from_pass(path):
"""Retrieve a password from the password store."""
env = os.environ.copy()
env.update({"PASSWORD_STORE_DIR": PASSWORD_STORE_PATH})
try:
os.chdir(INFRASTRUCTURE_PATH)
command = ["pass", "show", path]
output = subprocess.check_output(command, env=env)
return output.decode("utf-8").strip()
except subprocess.CalledProcessError as exception:
msg = "{} failed! Saw {}".format(" ".join(command), str(exception))
exit_with_msg(msg)