Example #1
0
def show_secret(args):
    try:
        path = os.path.join(args["--secrets"],
                            sacretindex.get(args["index"], args["<secret>"]))
        subprocess.check_call(decrypt + [path])
    except KeyError:
        sys.stderr.write("no secret {} found\n".format(args["<secret>"]))
        sys.exit(1)
Example #2
0
def edit_secret(args):
    if os.getenv("EDITOR") is None:
        sys.stderr.write("please set EDITOR\n")
        sys.exit(1)
    sacretindex.add(args["index"], args["<secret>"], str(uuid.uuid4()))
    secret_path = os.path.join(args["--secrets"],
                               sacretindex.get(args["index"], args["<secret>"]))
    with tempfile.NamedTemporaryFile(mode="w", dir=tmp_dir()) as temp_file:
        if os.path.exists(secret_path):
            subprocess.check_call(decrypt + [secret_path], stdout=temp_file)
        subprocess.check_call(["$EDITOR {}".format(temp_file.name)], shell=True)
        subprocess.check_call(encrypt + ["--yes", "--output", secret_path,
                                         temp_file.name])
Example #3
0
def copy_secret(args):
    try:
        path = os.path.join(args["--secrets"],
                            sacretindex.get(args["index"], args["<secret>"]))
    except KeyError:
        sys.stderr.write("no secret {} found\n".format(args["<secret>"]))
        sys.exit(1)
    with subprocess.Popen(decrypt + [path], stdout=subprocess.PIPE) as gpg:
        with subprocess.Popen(["head -n 1 | tr -d '\n' | xclip -selection clipboard"],
                              shell=True,
                              stdin=gpg.stdout) as xclip:
            gpg.stdout.close()
            if xclip.wait() != 0:
                sys.exit(xclip.returncode)