mirror of
https://github.com/traxys/Nixfiles.git
synced 2026-04-01 18:07:25 +02:00
Switch to python implementation of hbw for TOTP
This commit is contained in:
parent
25f7880c0d
commit
ce2258679e
5 changed files with 64 additions and 15 deletions
3
home.nix
3
home.nix
|
|
@ -40,7 +40,8 @@ in {
|
|||
comma
|
||||
raclette
|
||||
oscclip
|
||||
nvfetcher
|
||||
nvfetcher
|
||||
hbw
|
||||
];
|
||||
|
||||
services = {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
wowup = callPackage ./wowup.nix {};
|
||||
simulationcraft = callPackage ./simulationcraft.nix {simulationcraft-src = sources.simulationcraft;};
|
||||
proton-ge = callPackage ./proton-ge.nix {proton-ge-src = sources.proton-ge;};
|
||||
hbw = callPackage ./hbw {};
|
||||
kabalist_cli = callPackage ./kabalist.nix {
|
||||
inherit naersk;
|
||||
kabalist-src = sources.kabalist;
|
||||
|
|
|
|||
27
pkgs/hbw/default.nix
Normal file
27
pkgs/hbw/default.nix
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
stdenv,
|
||||
lib,
|
||||
python3,
|
||||
bitwarden-cli,
|
||||
makeWrapper,
|
||||
...
|
||||
}:
|
||||
stdenv.mkDerivation {
|
||||
pname = "hbw";
|
||||
version = "0.1";
|
||||
src = ./hbw.py;
|
||||
|
||||
buildInputs = [
|
||||
(python3.withPackages (ps: with ps; [pyotp]))
|
||||
bitwarden-cli
|
||||
makeWrapper
|
||||
];
|
||||
|
||||
dontUnpack = true;
|
||||
dontBuild = true;
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $src $out/bin/hbw
|
||||
wrapProgram $out/bin/hbw --prefix PATH : ${lib.makeBinPath [bitwarden-cli]}
|
||||
'';
|
||||
}
|
||||
34
pkgs/hbw/hbw.py
Executable file
34
pkgs/hbw/hbw.py
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
import json
|
||||
import pyotp
|
||||
import datetime
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print("Missing search term")
|
||||
sys.exit(1)
|
||||
|
||||
search = sys.argv[1]
|
||||
|
||||
process = subprocess.Popen(
|
||||
["bw", "list", "items", "--search", search], stdout=subprocess.PIPE
|
||||
)
|
||||
process.wait()
|
||||
data, _ = process.communicate()
|
||||
if process.returncode != 0:
|
||||
sys.exit(1)
|
||||
|
||||
data = json.loads(data)
|
||||
|
||||
for item in data:
|
||||
print(f"==== {item['name']} ====")
|
||||
print(f" {item['login']['username']}")
|
||||
print(f" {item['login']['password']}")
|
||||
if "totp" in item["login"] and item["login"]["totp"] is not None:
|
||||
totp = pyotp.TOTP(item["login"]["totp"])
|
||||
time_remaining = (
|
||||
totp.interval - datetime.datetime.now().timestamp() % totp.interval
|
||||
)
|
||||
print(f" {totp.now()} ({int(time_remaining)})")
|
||||
14
scripts/hbw
14
scripts/hbw
|
|
@ -1,14 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
NAME=$1
|
||||
if [ -z $1 ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
bw list items --search $NAME |\
|
||||
jq 'reduce .[] as $item (
|
||||
"";
|
||||
. + "=====" + $item.name + "====\n "
|
||||
+ $item.login.username + "\n "
|
||||
+ $item.login.password + "\n\n")' -r |\
|
||||
head -n -2
|
||||
Loading…
Add table
Add a link
Reference in a new issue