Created
December 11, 2023 12:22
-
-
Save phaer/e826e3d10e8ee5bd1065e1baecaaa370 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import uuid | |
import subprocess | |
from pathlib import Path | |
age_identity = Path("~/.passage/identities").expanduser() | |
store_dir = Path("~/.passage/store").expanduser() | |
folders = [] | |
items = [] | |
for root, dirs, files in store_dir.walk(on_error=print): | |
root = root.relative_to(store_dir) | |
if str(root).startswith(".git"): | |
continue | |
if str(root) != ".": | |
folder_id = uuid.uuid4() | |
folders.append({ | |
"name": str(root), | |
"id": str(folder_id) | |
}) | |
else: | |
folder_id = None | |
for file in files: | |
file = Path(file) | |
if not file.suffix == ".age": | |
continue | |
proc = subprocess.run( | |
['age', '-i', age_identity, '-d', store_dir / root / file], | |
check=True, capture_output=True, encoding="utf-8" | |
) | |
first, rest = proc.stdout.split("\n", maxsplit=1) | |
items.append({ | |
"folderId": str(folder_id), | |
"type": 1, # login | |
"name": file.stem, | |
"notes": rest, | |
"login": { | |
"password": first | |
}, | |
}) | |
print(json.dumps({ | |
"folders": folders, | |
"items": items | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment