3 Commits
Author SHA1 Message Date
moritz 19fa4e0ffe chore: update and patch abra
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2026-08-31 21:39:09 +02:00
moritz 6803b2f317 fix(secrets): tolerate a purge that had no secrets to remove
continuous-integration/drone/push Build is passing
2026-08-31 20:45:44 +02:00
moritz b77df7c5a6 Merge pull request 'adds kimai grouu as env to combine yml' (#13) from kimai_group into main
continuous-integration/drone/push Build is passing
Reviewed-on: #13
2026-08-31 16:36:22 +00:00
3 changed files with 52 additions and 5 deletions
+1 -1
Submodule abra updated: e1b10f6020...643a551da3
+10 -3
View File
@@ -75,8 +75,9 @@ CONNECTION_ERRORS = (
)
# marker in the abra output that indicates a secret which is not stored on the server
MISSING_SECRET_ERROR = "doesn't exist on server"
# marker in the abra output for a generate run that had nothing left to do, which abra exits 1 on
# markers in the abra output for a secret run that had nothing left to do, which abra exits 1 on
NO_SECRETS_GENERATED = "no secrets generated"
NO_SECRETS_TO_REMOVE = "no secrets to remove"
# container statuses that have not settled yet, matched against the abra output
PENDING_STATUS_RE = re.compile(r".*(starting|unknown|unhealthy).*")
# marker in a service name for a container that runs once and exits instead of becoming healthy
@@ -2196,7 +2197,7 @@ def parse_secret_variants(only: Tuple[str]) -> Set[str]:
def purge_app_secrets(recipe_secrets: Dict[str, List[str]]) -> None:
"""
Removes the given secrets from every app of the given recipes.
A secret that is not stored on the server is skipped, so an aborted run can simply be repeated.
A secret that is not stored on the server is skipped, and so is an app that has none at all, so an aborted run can simply be repeated.
All other errors are not suppressed: a secret that could not be removed would silently keep its old value on a later recreation.
Args:
@@ -2207,7 +2208,13 @@ def purge_app_secrets(recipe_secrets: Dict[str, List[str]]) -> None:
for _, domain in app_domains:
logging.info(f'purge secrets of {domain}')
if not secret_names:
abra("app", "secret", "rm", "-a", domain)
try:
abra("app", "secret", "rm", "-a", domain)
except RuntimeError as e:
if NO_SECRETS_TO_REMOVE not in str(e):
raise
print(f"{domain} has no secrets on its server, skip")
continue
print(f"Secrets for {domain} purged")
continue
for secret_name in secret_names:
+41 -1
View File
@@ -9,7 +9,7 @@ import pytest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import alakazam
from alakazam import purge_apps
from alakazam import purge_app_secrets, purge_apps
INSTANCE_APPS = {"a.org": [["authentik", "login.a.org"]]}
CONFIG = {"a.org": {"authentik": {"app_domain": "login.a.org", "server": "a.org"}}}
@@ -50,3 +50,43 @@ class TestPurgeApps:
monkeypatch.setattr(alakazam, "abra", lambda *a, **k: calls.append(a) or "")
purge_apps(INSTANCE_APPS)
assert calls == []
class TestPurgeAppSecrets:
@pytest.fixture
def config(self, monkeypatch):
monkeypatch.setattr(alakazam, "INSTANCE_CONFIGS", CONFIG)
def install(self, monkeypatch, error=None):
calls = []
def abra(*args, **kwargs):
calls.append(args)
if error:
raise RuntimeError(error)
return ""
monkeypatch.setattr(alakazam, "abra", abra)
return calls
def test_all_secrets_of_a_recipe_are_removed(self, config, monkeypatch, capsys):
calls = self.install(monkeypatch)
purge_app_secrets({"authentik": []})
assert calls == [("app", "secret", "rm", "-a", "login.a.org")]
assert "purged" in capsys.readouterr().out
def test_an_app_without_secrets_is_not_a_failure(self, config, monkeypatch, capsys):
"""abra exits non-zero when it found nothing to remove, which says the job is already done."""
self.install(monkeypatch, error="FATA no secrets to remove?")
purge_app_secrets({"authentik": []})
assert "has no secrets on its server" in capsys.readouterr().out
def test_a_real_failure_still_propagates(self, config, monkeypatch):
self.install(monkeypatch, error="FATA error during connect: no route to host")
with pytest.raises(RuntimeError):
purge_app_secrets({"authentik": []})
def test_a_named_secret_that_is_absent_is_skipped(self, config, monkeypatch, capsys):
self.install(monkeypatch, error="FATA email_pass doesn't exist on server?")
purge_app_secrets({"authentik": ["email_pass"]})
assert "is not stored on the server" in capsys.readouterr().out