From 95537d1d4846a9fe3e777017950f86d1a3b41168 Mon Sep 17 00:00:00 2001 From: mia Date: Sun, 30 Jun 2024 18:25:15 -0700 Subject: key editing --- commia/bearer.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/commia/bearer.py b/commia/bearer.py index 6202126..0ee761c 100644 --- a/commia/bearer.py +++ b/commia/bearer.py @@ -1,17 +1,21 @@ import base64 +import os import pyrage from commia.prelude import * from commia.ssh import sftp_exists, sftp_rm, ssh_opt_args +from commia.util import with_written _target = "secrets@bearer" _opts = lambda: ssh_opt_args(_target) +@overload +def get_key(key: "Key", decode: bool = True) -> str: ... @overload def get_key(key: "Key", decode: bool = False) -> bytes: ... -def get_key(key: "Key", decode: bool = True) -> str: +def get_key(key: "Key", decode: bool = True): found = None for recipient in key.recipients: idn = _identity(recipient) @@ -56,6 +60,16 @@ def has_key(key: "Key") -> bool: return sftp_exists(f"data/{key.path}", target=_target) +def edit_key(key: "Key"): + data = get_key(key) + + def callback(path: str): + run([os.environ["EDITOR"], path]) + set_key(key, Path(path).read_text().strip()) + + with_written(data, callback) + + _identity_c = {} @@ -90,6 +104,8 @@ class Key: class keys: test = Key("test", "fw") + domains = Key("domains", "fw") + class certificates: certs = Key("certificates:certs", "fw") state = Key("certificates:state", "fw") -- cgit 1.4.1