aboutsummaryrefslogtreecommitdiff
path: root/scripts/p7s/bitwarden.py
diff options
context:
space:
mode:
authoralex <alex@pdp7.net>2026-12-05 22:09:29 +0100
committeralex <alex@pdp7.net>2026-12-06 12:12:40 +0100
commitbfa433a01d1042270c82fcc0c40619ca24909e2c (patch)
tree7109e927ea004896ad358df643a0ebb5538c2094 /scripts/p7s/bitwarden.py
parentabd668108d9932e39c5de075b9aee116f667987f (diff)
WIP
Somewhat blocked by https://bugzilla.redhat.com/show_bug.cgi?id=2521543
Diffstat (limited to 'scripts/p7s/bitwarden.py')
-rw-r--r--scripts/p7s/bitwarden.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/scripts/p7s/bitwarden.py b/scripts/p7s/bitwarden.py
index ab6cc4f2..6015cbbb 100644
--- a/scripts/p7s/bitwarden.py
+++ b/scripts/p7s/bitwarden.py
@@ -1,7 +1,11 @@
import contextlib
import json
import os
+import pathlib
import subprocess
+import tempfile
+import urllib.request
+import zipfile
class Bitwarden():
@@ -40,3 +44,25 @@ def get_item(server, email, uuid):
with b.login(server, email):
b.sync()
return b.get_item(uuid)
+
+
+@contextlib.contextmanager
+def default():
+ b = Bitwarden()
+ with b.login("https://vaultwarden.pdp7.net", "alex@corcoles.net"):
+ b.sync()
+ yield b
+
+
+def install_cli(version):
+ with tempfile.TemporaryDirectory() as tempdir:
+ tempdir = pathlib.Path(tempdir)
+ zip = tempdir / "zip"
+ with urllib.request.urlopen(f"https://github.com/bitwarden/clients/releases/download/cli-v{version}/bw-oss-linux-{version}.zip") as urlopen:
+ zip.write_bytes(urlopen.read())
+ with zipfile.ZipFile(zip) as zip:
+ with zip.open("bw") as bw:
+ bw_path = pathlib.Path.home() / ".local" / "bin" / "bw"
+ bw_path.unlink()
+ bw_path.write_bytes(bw.read())
+ bw_path.chmod(0o555)