|
|
@@ -25,8 +25,15 @@ class KeePass:
|
|
|
def read_entry_attribute(self, key, attribute):
|
|
|
return self._exec(["show", "-a", attribute, self.path, key]).strip()
|
|
|
|
|
|
+ def read_entry_attachment(self, key, attachment):
|
|
|
+ return self._exec(["attachment-export", "--stdout", self.path, key, attachment, "/dev/null"])
|
|
|
+
|
|
|
def _exec(self, args: list[Any]):
|
|
|
- return subprocess.check_output([self.bin] + args, text=True)
|
|
|
+ try:
|
|
|
+ return subprocess.check_output([self.bin] + args, text=True)
|
|
|
+ except subprocess.CalledProcessError as e:
|
|
|
+ print("\nThere was an error on call to keepass, please check the outout")
|
|
|
+ exit(1)
|
|
|
|
|
|
@classmethod
|
|
|
def new(cls, path: Path):
|
|
|
@@ -37,6 +44,7 @@ class KeePass:
|
|
|
class SecretType(StrEnum):
|
|
|
File="file"
|
|
|
KeepassAttribute="keepass-attribute"
|
|
|
+ KeepassAttachment="keepass-attachment"
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
@@ -47,6 +55,7 @@ class Secret:
|
|
|
host_path: Path | None = None
|
|
|
key: str | None = None
|
|
|
attribute: str | None = None
|
|
|
+ attachment: str | None = None
|
|
|
|
|
|
def create(self, keepass: KeePass):
|
|
|
match self.type:
|
|
|
@@ -61,6 +70,12 @@ class Secret:
|
|
|
print(args)
|
|
|
subprocess.run(args, input=value.encode())
|
|
|
|
|
|
+ case SecretType.KeepassAttachment:
|
|
|
+ value = keepass.read_entry_attachment(self.key, self.attachment)
|
|
|
+ args = ["podman", "secret", "create", "--replace", self.name, "-"]
|
|
|
+ print(args)
|
|
|
+ subprocess.run(args, input=value.encode())
|
|
|
+
|
|
|
@classmethod
|
|
|
def from_line(cls, line: str):
|
|
|
type_, *args = line.split(",")
|
|
|
@@ -70,6 +85,8 @@ class Secret:
|
|
|
return cls(host_path=path, name=path.name, mode=0o0400, type=SecretType.File)
|
|
|
case (SecretType.KeepassAttribute, key, attribute):
|
|
|
return cls(name=key, key=key, mode=0o0400, type=SecretType.KeepassAttribute, attribute=attribute)
|
|
|
+ case (SecretType.KeepassAttachment, key, attachment):
|
|
|
+ return cls(name=key, key=key, mode=0o0400, type=SecretType.KeepassAttachment, attachment=attachment)
|
|
|
|
|
|
@classmethod
|
|
|
def read_sources(cls, hostname: str, login: str) -> list["Secret"]:
|