🗝
summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--commia/bearer.py18
1 files changed, 17 insertions, 1 deletions
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")