Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an rm command #25

Merged
merged 7 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions totp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ def add_pass_entry(path, token_length, shared_key):
raise PassBackendError(err)


def rm_pass_entry(path):
"""Remove an entry via pass"""
code_path = "2fa/{}/code"
code_path = code_path.format(path)

p = subprocess.Popen(
["pass", "rm", code_path],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)

pass_output, err = p.communicate()

if p.returncode != 0:
raise PassBackendError(err)


def get_pass_entry(path):
"""Return the entire entry as provided via pass."""
code_path = "2fa/{}/code"
Expand Down
24 changes: 24 additions & 0 deletions totp/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import getpass
import click
import sys
from base64 import b32decode
from collections import namedtuple
Expand Down Expand Up @@ -111,6 +112,29 @@ def add_uri(path, uri):
totp.add_pass_entry_from_uri(path, uri)


@subcommand(
"rm",
argument(
"identifier",
help="the identifier under the '2fa' folder where the key to remove is saved",
),
aliases=["-r"],
description="Remove a TOTP entry from the database.",
help="remove a TOTP entry from the database",
)
def _cmd_rm(args):
if args.identifier:
WhyNotHugo marked this conversation as resolved.
Show resolved Hide resolved
if click.confirm('Do you really want to remove a shared secret TOTP key ?'):
print("OK. Living dangerously, aren't we ? Removing at your behest.")
rm_uri(args.identifier)
else:
raise ValueError("The identifier to remove was not provided")


def rm_uri(path):
totp.rm_pass_entry(path)


@subcommand(
"show",
argument(
Expand Down