diff options
| author | alex <alex@pdp7.net> | 2026-12-05 22:09:29 +0100 |
|---|---|---|
| committer | alex <alex@pdp7.net> | 2026-12-06 12:58:10 +0100 |
| commit | 29af71e4105dc8bd8761957a1e3e4f7ef45c076b (patch) | |
| tree | 688d99c762b237f0cb1839db3dc6a941bdd51d2e /scripts/p7s/bitwarden.py | |
| parent | 6e6fc68fee5783e391d8b921ca44b90aeb67223c (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.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/scripts/p7s/bitwarden.py b/scripts/p7s/bitwarden.py index ab6cc4f2..3f10780e 100644 --- a/scripts/p7s/bitwarden.py +++ b/scripts/p7s/bitwarden.py @@ -1,7 +1,12 @@ +import argparse import contextlib import json import os +import pathlib import subprocess +import tempfile +import urllib.request +import zipfile class Bitwarden(): @@ -40,3 +45,32 @@ 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) + + +def install_cli_main(): + parser = argparse.ArgumentParser() + parser.add_argument("version") + args = parser.parse_args() + install_cli(args.version) |
