secrets: add has_machine and has_secret function

This commit is contained in:
Jörg Thalheim
2023-09-19 20:30:36 +02:00
committed by lassulus
parent dc51ca5803
commit ead5c6e6a8
2 changed files with 10 additions and 5 deletions

View File

@@ -19,11 +19,15 @@ def get_machine(name: str) -> str:
return read_key(sops_machines_folder() / name)
def has_machine(name: str) -> bool:
return (sops_machines_folder() / name / "key.json").exists()
def list_machines() -> list[str]:
path = sops_machines_folder()
def validate(name: str) -> bool:
return validate_hostname(name) and (path / name / "key.json").exists()
return validate_hostname(name) and has_machine(name)
return list_objects(path, validate)

View File

@@ -171,14 +171,15 @@ def disallow_member(group_folder: Path, name: str) -> None:
)
def has_secret(secret: str) -> bool:
return (sops_secrets_folder() / secret / "secret").exists()
def list_secrets() -> list[str]:
path = sops_secrets_folder()
def validate(name: str) -> bool:
return (
VALID_SECRET_NAME.match(name) is not None
and (path / name / "secret").exists()
)
return VALID_SECRET_NAME.match(name) is not None and has_secret(name)
return list_objects(path, validate)