"""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)