Skip to content

Commit

Permalink
Merge pull request #25 from gl-yziquel/24-totp-rm
Browse files Browse the repository at this point in the history
Adding an rm command
  • Loading branch information
WhyNotHugo authored Sep 27, 2023
2 parents 121616a + e8c86ca commit 5a71b01
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
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:
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

0 comments on commit 5a71b01

Please sign in to comment.