mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-28 13:57:43 +00:00
fix(lookups): name file-backed extra secrets by content and hand plain types to PyYAML
compose_volumes copied extra_configs and extra_secrets through verbatim.
A file-backed extra without a name therefore reached swarm under a fixed
name, and swarm secrets are immutable: a new content under the same name
is rejected on the next stack deploy. Such extras now get the same
{role}_{key}_{sha8(content)} name that _config_secret_name already gives
meta-declared entries. An explicit name is kept.
container_volumes appended extras as handed over. Ansible passes one
lookup's result to another as proxy containers, and a TaggedInt mode
inside a proxy mapping made PyYAML raise "cannot represent an object".
The private _to_plain of compose_volumes moves to utils/templating as
to_plain, now coercing bool, int and float to the exact builtin types
(bool before int, since bool subclasses int), and container_volumes runs
its extras through it.
Only web-app-matrix passes extra secrets or configs today; the
extra_volumes path that web-app-nextcloud uses is unchanged.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
a3b0606791
commit
a650801b35
5 files changed
+103
-34
No files matched your search
@@ -2,8 +2,10 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import unittest.mock as mock
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from ansible.errors import AnsibleFilterError
|
||||
@@ -172,6 +174,29 @@ class TestComposeVolumes(unittest.TestCase):
|
||||
|
||||
self.assertEqual(data["volumes"]["redis"]["name"], "custom_redis")
|
||||
|
||||
def test_extra_secret_without_name_gets_the_content_hashed_name(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
one, two = Path(tmp) / "one.yaml", Path(tmp) / "two.yaml"
|
||||
one.write_text("as_token: one\n", encoding="utf-8")
|
||||
two.write_text("as_token: two\n", encoding="utf-8")
|
||||
secrets = self._parse_yaml(
|
||||
_call(
|
||||
self._base_apps(),
|
||||
"app",
|
||||
extra_secrets={
|
||||
"cfg": {"file": str(one)},
|
||||
"other": {"file": str(two)},
|
||||
"named": {"name": "kept", "file": str(one)},
|
||||
},
|
||||
)
|
||||
)["secrets"]
|
||||
|
||||
self.assertEqual(secrets["cfg"]["file"], str(one))
|
||||
self.assertRegex(secrets["cfg"]["name"], r"^app_cfg_[0-9a-f]{8}$")
|
||||
self.assertRegex(secrets["other"]["name"], r"^app_other_[0-9a-f]{8}$")
|
||||
self.assertNotEqual(secrets["cfg"]["name"][-8:], secrets["other"]["name"][-8:])
|
||||
self.assertEqual(secrets["named"]["name"], "kept")
|
||||
|
||||
def test_database_enabled_not_shared_shared_provider_name_used_when_present(self):
|
||||
apps = self._base_apps()
|
||||
apps["app"]["services"]["mariadb"]["enabled"] = True
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from collections.abc import Mapping
|
||||
|
||||
import yaml
|
||||
|
||||
@@ -331,6 +332,38 @@ class TestContainerVolumesExtras(unittest.TestCase):
|
||||
},
|
||||
)
|
||||
|
||||
def test_extras_handed_over_as_templating_proxies_still_serialize(self) -> None:
|
||||
class ProxyMapping(Mapping):
|
||||
def __init__(self, data):
|
||||
self._data = data
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self._data[key]
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self._data)
|
||||
|
||||
def __len__(self):
|
||||
return len(self._data)
|
||||
|
||||
class TaggedInt(int):
|
||||
pass
|
||||
|
||||
out = container_volumes(
|
||||
_apps(None),
|
||||
"my-app",
|
||||
"app",
|
||||
extra_secrets=[
|
||||
ProxyMapping(
|
||||
{"source": "s", "target": "/run/y", "mode": TaggedInt(0o444)}
|
||||
)
|
||||
],
|
||||
)
|
||||
self.assertEqual(
|
||||
_parse(out),
|
||||
{"secrets": [{"source": "s", "target": "/run/y", "mode": 0o444}]},
|
||||
)
|
||||
|
||||
|
||||
class TestContainerVolumesOutputShape(unittest.TestCase):
|
||||
def test_empty_meta_returns_empty_string(self) -> None:
|
||||
|
||||
Reference in new issue
Block a user