mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-05 09:18:53 +00:00
Merge branch 'feature/updater' into feature/store-i18n
68 conflicts, resolved per hunk; resolutions agreed with the Updater session were applied as agreed: - svc-db-postgres (superuser password script and core) and sys-svc-rdbms realign_dedicated_db: updater's argv/stdin redesign with expand_argument_vars: false, nested into store-i18n's block structure. - svc-db-redis 01_init: store-i18n's ACL password on stdin. - sys-svc-proxy forwarded.conf.j2: store-i18n's handover-aware file, without the forwarded_base include (Host and X-Forwarded-Proto would be sent twice); forwarded_base serves the inline consumers, e.g. web-app-seaweedfs nginx.conf.j2. - basic.conf.j2 and web-app-openproject proxy.conf.j2: issuer redirect, then handover, else updater's location/sso_acl.conf.j2; the server-level webserver_extra_configuration hook stays. - web-app-keycloak: updater's admin-REST settings step and renumbered update steps; update/01_client.yml removed; store-i18n's design step and LDAP block kept;a73435cc9darrived through rename detection. - web-app-nextcloud OpenProject provisioning: updater's rewrite, all credentials on the Ruby runner's stdin. - web-app-semaphore: store-i18n's canonical web root (a1d7835863). - Role READMEs: no generated Cosmos/Architecture/Quick Setup/Credits sections; desk-* paths resolved to the dsk-* renames. Integration fixes for what merged cleanly but did not fit together: - web-app-matrix ansible vars: drop updater's second matrix_client_element_configuration_extension_json, which silently overrode store-i18n's design-aware value. - url.origin instead of a stripped url.base in 19 places store-i18n added since44aaa68924, same lookup targets (the double-slash lint). - Package batch (18ea75049e,cb4d340de9): installs the deploy-start batch covers are removed (caffeine, cursor, blender, npm in dsk-gnt-*, with shared references), the rest carry batch: false and a nocheck with the verified reason (PyPI fallback, before the batch, vendor repository, configured flavor only, addon gate); dev-npm references the root npm id. - sys-token-store write_many.yml: store-i18n's change-gated block and IS_SWARM_MODE. - web-app-openproject: IS_COMPOSE_MODE in 02_migrate/run.yml; the seeded-admin lock (ccbf8f168d) ported into 04_admin/provision.yml and covered by the admin-state digest. - Bucket policy (3b4ac40df5and follow-ups) moved to web-svc-seaweedfs, where store-i18n's object store lives; the S3 admin secret travels on stdin instead of a task-level environment. - act workflow.sh: no Exception-labelled comment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
c9e7f950d9
533 files changed
+14274
-1833
No files matched your search
+47
-1
@@ -402,7 +402,53 @@ class TestGetMergedApplicationsCarrierFact(unittest.TestCase):
|
||||
"key": [key[0], list(key[1])],
|
||||
"applications": {"web-app-foo": {"carried": True}},
|
||||
}
|
||||
tokens.write_text("users: {}\n", encoding="utf-8")
|
||||
tokens.write_text(
|
||||
"users: {no-reply: {tokens: {web-app-stalwart: minted}}}\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
merged = cache_apps.get_merged_applications(
|
||||
variables=variables, roles_dir=roles, templar=None
|
||||
)
|
||||
self.assertNotIn("carried", merged["web-app-foo"])
|
||||
|
||||
def _park_from_the_tokens_file(self, tmp: Path, token: str) -> tuple:
|
||||
roles = _seed_minimal_roles(tmp)
|
||||
tokens = tmp / "tokens.yml"
|
||||
tokens.write_text(
|
||||
f"users: {{no-reply: {{tokens: {{web-app-stalwart: {token}}}}}}}\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
variables = self._variables()
|
||||
variables["FILE_TOKENS"] = str(tokens)
|
||||
key = merged_applications_cache_key(variables, roles_dir=roles)
|
||||
carried = {"web-app-foo": {"carried": True}}
|
||||
variables[APPLICATIONS_RENDERED_FACT] = {
|
||||
"key": [key[0], list(key[1])],
|
||||
"applications": carried,
|
||||
}
|
||||
return roles, variables, carried
|
||||
|
||||
def test_the_store_fact_with_the_file_tokens_keeps_the_carrier(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
roles, variables, carried = self._park_from_the_tokens_file(
|
||||
Path(tmp), "minted"
|
||||
)
|
||||
variables["sys_token_store_users"] = {
|
||||
"no-reply": {"tokens": {"web-app-stalwart": "minted"}}
|
||||
}
|
||||
merged = cache_apps.get_merged_applications(
|
||||
variables=variables, roles_dir=roles, templar=None
|
||||
)
|
||||
self.assertIs(merged, carried)
|
||||
|
||||
def test_the_store_fact_with_other_tokens_than_the_file_rejects_the_carrier(
|
||||
self,
|
||||
):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
roles, variables, _ = self._park_from_the_tokens_file(Path(tmp), "minted")
|
||||
variables["sys_token_store_users"] = {
|
||||
"no-reply": {"tokens": {"web-app-stalwart": "rotated"}}
|
||||
}
|
||||
merged = cache_apps.get_merged_applications(
|
||||
variables=variables, roles_dir=roles, templar=None
|
||||
)
|
||||
|
||||
+53
-1
@@ -8,9 +8,11 @@ the module so the real repo tree is never touched.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
|
||||
from utils.cache import files as files_module
|
||||
@@ -20,7 +22,7 @@ from utils.cache.files import (
|
||||
iter_project_files_with_content,
|
||||
read_text,
|
||||
)
|
||||
from utils.roles.mapping import ROLE_FILE_META_SERVICES
|
||||
from utils.roles.mapping import ROLE_FILE_META_SERVICES, ROLE_FILE_TASKS_MAIN
|
||||
|
||||
|
||||
def _touch(path: Path, content: str = "") -> Path:
|
||||
@@ -191,6 +193,56 @@ class TestReset(_ProjectRootFixture, unittest.TestCase):
|
||||
self.assertEqual(read_text(str(self.root / "x.txt")), "v1-changed")
|
||||
|
||||
|
||||
class TestRepositoryFiles(_ProjectRootFixture, unittest.TestCase):
|
||||
TRACKED = f"roles/web-app-nextcloud/{ROLE_FILE_TASKS_MAIN}"
|
||||
CUSTOM = f"roles/web-app-cst-demo/{ROLE_FILE_TASKS_MAIN}"
|
||||
|
||||
def _git(self, *listings: bytes):
|
||||
return patch.object(
|
||||
files_module.subprocess,
|
||||
"run",
|
||||
side_effect=[SimpleNamespace(stdout=listing) for listing in listings],
|
||||
)
|
||||
|
||||
def test_lists_placed_custom_roles_next_to_the_tracked_files(self) -> None:
|
||||
_touch(self.root / self.TRACKED, "- y")
|
||||
_touch(self.root / self.CUSTOM, "- x")
|
||||
_touch(self.root / "roles/web-app-cst-demo/__pycache__/x.pyc", "")
|
||||
with self._git(f"{self.TRACKED}\0".encode()):
|
||||
self.assertEqual(
|
||||
(self.CUSTOM, self.TRACKED),
|
||||
files_module.repository_files(),
|
||||
)
|
||||
|
||||
def test_lists_only_the_tracked_files_without_placed_custom_roles(self) -> None:
|
||||
_touch(self.root / self.TRACKED, "- y")
|
||||
_touch(self.root / "build/install.stamp", "")
|
||||
with self._git(f"{self.TRACKED}\0".encode()):
|
||||
self.assertEqual((self.TRACKED,), files_module.repository_files())
|
||||
|
||||
def test_untracked_adds_the_files_gitignore_does_not_exclude(self) -> None:
|
||||
with self._git(f"{self.TRACKED}\0".encode(), b"new.py\0") as run:
|
||||
self.assertEqual(
|
||||
("new.py", self.TRACKED),
|
||||
files_module.repository_files(untracked=True),
|
||||
)
|
||||
self.assertEqual(
|
||||
["--others", "--exclude-standard"],
|
||||
run.call_args_list[1].args[0][-2:],
|
||||
)
|
||||
|
||||
def test_a_git_failure_propagates(self) -> None:
|
||||
with (
|
||||
patch.object(
|
||||
files_module.subprocess,
|
||||
"run",
|
||||
side_effect=subprocess.CalledProcessError(128, "git"),
|
||||
),
|
||||
self.assertRaises(subprocess.CalledProcessError),
|
||||
):
|
||||
files_module.repository_files()
|
||||
|
||||
|
||||
class TestWalkIsKeyedOnTheRoot(_ProjectRootFixture, unittest.TestCase):
|
||||
def test_a_second_root_is_walked_rather_than_answered_from_the_first(
|
||||
self,
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from utils.cache import gitignore
|
||||
from utils.roles.custom import ROLES_GLOB
|
||||
from utils.roles.mapping import ROLE_FILE_TASKS_MAIN
|
||||
|
||||
|
||||
class TestLoadGitignorePatterns(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(tmp.cleanup)
|
||||
self.addCleanup(gitignore._reset)
|
||||
self.root = Path(tmp.name)
|
||||
(self.root / ".gitignore").write_text(
|
||||
f"# comment\n*.log\n{ROLES_GLOB}\n!keep.log\nbuild/*\n", encoding="utf-8"
|
||||
)
|
||||
|
||||
def test_reads_plain_patterns(self):
|
||||
patterns = gitignore.load_gitignore_patterns(str(self.root))
|
||||
self.assertEqual(("*.log", "build/*"), patterns)
|
||||
|
||||
def test_pulled_custom_roles_stay_in_the_scanned_tree(self):
|
||||
patterns = gitignore.load_gitignore_patterns(str(self.root))
|
||||
self.assertFalse(
|
||||
gitignore.is_path_gitignored(
|
||||
f"roles/web-app-cst-demo/{ROLE_FILE_TASKS_MAIN}", patterns
|
||||
)
|
||||
)
|
||||
|
||||
def test_ignored_files_inside_a_custom_role_stay_ignored(self):
|
||||
patterns = gitignore.load_gitignore_patterns(str(self.root))
|
||||
self.assertTrue(
|
||||
gitignore.is_path_gitignored("roles/web-app-cst-demo/debug.log", patterns)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
+35
@@ -7,11 +7,13 @@ from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
from utils.cache.yaml import (
|
||||
TaggedValue,
|
||||
_reset_cache_for_tests,
|
||||
dump_yaml,
|
||||
invalidate,
|
||||
load_yaml,
|
||||
load_yaml_any,
|
||||
load_yaml_tagged,
|
||||
)
|
||||
|
||||
|
||||
@@ -158,5 +160,38 @@ class TestInvalidate(unittest.TestCase):
|
||||
invalidate(self.tmp / "never-loaded.yml")
|
||||
|
||||
|
||||
class TestLoadYamlTagged(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
_reset_cache_for_tests()
|
||||
self._tmp = TemporaryDirectory()
|
||||
self.addCleanup(self._tmp.cleanup)
|
||||
self.path = Path(self._tmp.name) / "inventory.yml"
|
||||
self.path.write_text(
|
||||
"motd: !unsafe '{{ literal }}'\n"
|
||||
"secret: !vault |\n"
|
||||
" $ANSIBLE_VAULT;1.1;AES256\n"
|
||||
" 6162\n"
|
||||
"hosts: !custom [a, b]\n"
|
||||
"plain: value\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
def test_every_local_tag_loads_as_its_raw_value(self):
|
||||
self.assertEqual(
|
||||
{
|
||||
"motd": TaggedValue("!unsafe", "{{ literal }}"),
|
||||
"secret": TaggedValue("!vault", "$ANSIBLE_VAULT;1.1;AES256\n6162\n"),
|
||||
"hosts": TaggedValue("!custom", ["a", "b"]),
|
||||
"plain": "value",
|
||||
},
|
||||
load_yaml_tagged(self.path),
|
||||
)
|
||||
|
||||
def test_load_yaml_any_still_reads_vault_as_its_ciphertext(self):
|
||||
self.path.write_text("secret: !vault abc\n", encoding="utf-8")
|
||||
load_yaml_tagged(self.path)
|
||||
self.assertEqual({"secret": "abc"}, load_yaml_any(self.path))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -20,6 +20,7 @@ from pathlib import Path
|
||||
from utils.cache import _reset_cache_for_tests
|
||||
from utils.cache import base as cache_base
|
||||
from utils.cache import users as cache_users
|
||||
from utils.cache.users import store as cache_users_store
|
||||
from utils.cache.yaml import dump_yaml_str
|
||||
from utils.domains.default_primary import default_domain_primary
|
||||
from utils.roles.mapping import ROLE_FILE_META_SERVICES, ROLE_FILE_META_USERS
|
||||
@@ -425,5 +426,89 @@ class TestGetMergedUsersTokenSource(unittest.TestCase):
|
||||
self.assertEqual(after["foo"]["tokens"]["web-app-foo"], "minted")
|
||||
|
||||
|
||||
class TestStoreSignature(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
_reset_cache_for_tests()
|
||||
|
||||
@staticmethod
|
||||
def _signature(store: dict) -> tuple:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
return cache_users._store_signature(
|
||||
{cache_users_store.STORE_FACT: store}, Path(tmp) / "tokens.yml"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _hydrated(store: dict) -> str:
|
||||
users = {"foo": {"tokens": {"web-app-foo": ""}}}
|
||||
return repr(cache_users._hydrate_users_tokens(users, store))
|
||||
|
||||
def test_the_tokens_file_signs_like_the_store_fact_with_the_same_tokens(self):
|
||||
store = {"foo": {"tokens": {"web-app-foo": "minted"}}}
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
tokens_file = Path(tmp) / "tokens.yml"
|
||||
tokens_file.write_text(dump_yaml_str({"users": store}), encoding="utf-8")
|
||||
self.assertEqual(
|
||||
cache_users._store_signature({}, tokens_file),
|
||||
cache_users._store_signature(
|
||||
{cache_users_store.STORE_FACT: store}, tokens_file
|
||||
),
|
||||
)
|
||||
|
||||
def test_a_missing_tokens_file_signs_like_an_empty_store_fact(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
absent = Path(tmp) / "tokens.yml"
|
||||
self.assertEqual(
|
||||
cache_users._store_signature({}, absent),
|
||||
cache_users._store_signature(
|
||||
{cache_users_store.STORE_FACT: {}}, absent
|
||||
),
|
||||
)
|
||||
|
||||
def test_fields_and_padding_the_hydration_ignores_keep_the_signature(self):
|
||||
plain = {"foo": {"tokens": {"web-app-foo": "minted"}}}
|
||||
for variant in (
|
||||
{"foo": {"tokens": {"web-app-foo": " minted "}}},
|
||||
{"foo": {"tokens": {"web-app-foo": "minted"}, "note": "unread"}},
|
||||
{"foo": {"tokens": {"web-app-foo": "minted", "web-app-bar": None}}},
|
||||
{"foo": {"tokens": {"web-app-foo": "minted"}}, "bar": "not-a-mapping"},
|
||||
):
|
||||
with self.subTest(variant=variant):
|
||||
self.assertEqual(self._hydrated(variant), self._hydrated(plain))
|
||||
self.assertEqual(self._signature(variant), self._signature(plain))
|
||||
|
||||
def test_the_store_order_enters_the_signature_because_the_hydration_keeps_it(
|
||||
self,
|
||||
):
|
||||
first = {"bar": {"tokens": {"x": "1"}}, "baz": {"tokens": {"y": "2"}}}
|
||||
swapped = {"baz": {"tokens": {"y": "2"}}, "bar": {"tokens": {"x": "1"}}}
|
||||
self.assertNotEqual(self._hydrated(first), self._hydrated(swapped))
|
||||
self.assertNotEqual(self._signature(first), self._signature(swapped))
|
||||
|
||||
def test_an_equal_signature_means_an_equal_hydration(self):
|
||||
stores = [
|
||||
{"foo": {"tokens": {"web-app-foo": "minted"}}},
|
||||
{"foo": {"tokens": {"web-app-foo": " minted "}}},
|
||||
{"foo": {"tokens": {"web-app-foo": "rotated"}}},
|
||||
{"foo": {"tokens": {"web-app-foo": None}}},
|
||||
{"foo": {"tokens": {"web-app-foo": ""}}},
|
||||
{"foo": {"tokens": {}}},
|
||||
{"foo": {"tokens": "not-a-mapping"}},
|
||||
{"foo": {}},
|
||||
{"foo": "not-a-mapping"},
|
||||
{},
|
||||
{"bar": {"tokens": {"x": "1"}}},
|
||||
{"bar": {"tokens": {"x": 1}}},
|
||||
{"bar": {"tokens": {}}},
|
||||
{1: {"tokens": {"x": "1"}}},
|
||||
{"1": {"tokens": {"x": "1"}}},
|
||||
]
|
||||
for first in stores:
|
||||
for second in stores:
|
||||
if self._signature(first) != self._signature(second):
|
||||
continue
|
||||
with self.subTest(first=first, second=second):
|
||||
self.assertEqual(self._hydrated(first), self._hydrated(second))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user