mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 23:08:06 +02:00
Finished Mobilizon OIDC implementation
This commit is contained in:
@@ -30,11 +30,15 @@ class TestDeprecatedVersionKey(unittest.TestCase):
|
||||
uses_version = 'version' in config
|
||||
uses_images = 'images' in config
|
||||
|
||||
if uses_version and not uses_images:
|
||||
if uses_version:
|
||||
warnings.append(
|
||||
f"[DEPRECATION WARNING] {role_path.name}/vars/configuration.yml: "
|
||||
f"'version:' is set, but 'images:' is missing. "
|
||||
f"'version' is deprecated and must only be set if 'images' is present."
|
||||
f"'version' is deprecated. Replace it by docker.versions[version]."
|
||||
)
|
||||
if uses_images:
|
||||
warnings.append(
|
||||
f"[DEPRECATION WARNING] {role_path.name}/vars/configuration.yml: "
|
||||
f"'images' is deprecated. Replace it by docker.images[image]."
|
||||
)
|
||||
|
||||
if warnings:
|
||||
|
@@ -33,55 +33,15 @@ class TestDockerRoleImagesConfiguration(unittest.TestCase):
|
||||
errors.append(f"{role_path.name}: YAML parse error: {e}")
|
||||
continue
|
||||
|
||||
images = config.get("images")
|
||||
images = config.get("docker",{}).get("images")
|
||||
if not images:
|
||||
warnings.append(f"[WARNING] {role_path.name}: No 'images' key in configuration.yml")
|
||||
warnings.append(f"[WARNING] {role_path.name}: No 'docker.images' key in configuration.yml")
|
||||
continue
|
||||
|
||||
if not isinstance(images, dict):
|
||||
errors.append(f"{role_path.name}: 'images' must be a dict in configuration.yml")
|
||||
continue
|
||||
|
||||
for key, value in images.items():
|
||||
if not key or not value or not isinstance(key, str) or not isinstance(value, str):
|
||||
errors.append(f"{role_path.name}: images['{key}'] is invalid (must be non-empty string key and value)")
|
||||
continue
|
||||
|
||||
# Improved regex: matches both ' and " and allows whitespace
|
||||
pattern = (
|
||||
r'image:\s*["\']\{\{\s*applications\[application_id\]\.images\.' + re.escape(key) + r'\s*\}\}["\']'
|
||||
)
|
||||
|
||||
# innerhalb Deines Loops
|
||||
pattern2 = (
|
||||
r'image:\s*["\']\{\{\s*' # image: "{{
|
||||
r'applications\[\s*application_id\s*\]\.images' # applications[ application_id ].images
|
||||
r'\[\s*application_id\s*\]\s*' # [ application_id ]
|
||||
r'\}\}["\']' # }}" oder }}"
|
||||
)
|
||||
|
||||
|
||||
for tmpl_file in [
|
||||
role_path / "templates" / "docker-compose.yml.j2",
|
||||
role_path / "templates" / "env.j2",
|
||||
]:
|
||||
if not tmpl_file.exists():
|
||||
continue
|
||||
content = tmpl_file.read_text("utf-8")
|
||||
if re.search(pattern, content):
|
||||
break
|
||||
if key == main.get('application_id') and re.search(pattern2, content):
|
||||
break
|
||||
else:
|
||||
# Dieser Block wird nur ausgeführt, wenn kein `break` ausgelöst wurde
|
||||
errors.append(
|
||||
f"{role_path.name}: image key '{key}' is not referenced as "
|
||||
f"image: \"{{{{ applications[application_id].images.{key} }}}}\" or "
|
||||
f"\"{{{{ applications[application_id].images[application_id] }}}}\" "
|
||||
"in docker-compose.yml.j2 or env.j2"
|
||||
)
|
||||
|
||||
|
||||
# OPTIONAL: Check if the image is available locally via docker images
|
||||
# from shutil import which
|
||||
# import subprocess
|
||||
|
@@ -18,27 +18,14 @@ class TestGetDockerImage(unittest.TestCase):
|
||||
"akaunting": {
|
||||
"version": "1.0.0",
|
||||
"docker": {
|
||||
"images": { "akaunting": "docker.io/akaunting/akaunting" },
|
||||
"versions": { "akaunting": "2.0.0" }
|
||||
"images": {"akaunting": "docker.io/akaunting/akaunting"},
|
||||
"versions": {"akaunting": "2.0.0"}
|
||||
}
|
||||
}
|
||||
}
|
||||
result = self.get_docker_image(applications, "akaunting", "akaunting")
|
||||
self.assertEqual(result, "docker.io/akaunting/akaunting:2.0.0")
|
||||
|
||||
def test_fallback_to_application_version(self):
|
||||
applications = {
|
||||
"akaunting": {
|
||||
"version": "1.2.3",
|
||||
"docker": {
|
||||
"images": { "akaunting": "ghcr.io/akaunting/akaunting" },
|
||||
"versions": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
result = self.get_docker_image(applications, "akaunting", "akaunting")
|
||||
self.assertEqual(result, "ghcr.io/akaunting/akaunting:1.2.3")
|
||||
|
||||
def test_missing_image_raises_error(self):
|
||||
applications = {
|
||||
"akaunting": {
|
||||
@@ -56,7 +43,7 @@ class TestGetDockerImage(unittest.TestCase):
|
||||
applications = {
|
||||
"akaunting": {
|
||||
"docker": {
|
||||
"images": { "akaunting": "some/image" },
|
||||
"images": {"akaunting": "some/image"},
|
||||
"versions": {}
|
||||
}
|
||||
}
|
||||
@@ -64,5 +51,45 @@ class TestGetDockerImage(unittest.TestCase):
|
||||
with self.assertRaises(ValueError):
|
||||
self.get_docker_image(applications, "akaunting", "akaunting")
|
||||
|
||||
# --- new: Default image_key uses application_id if none provided ---
|
||||
def test_default_image_key_uses_application_id(self):
|
||||
applications = {
|
||||
"myapp": {
|
||||
"version": "3.0.0",
|
||||
"docker": {
|
||||
"images": {"myapp": "registry/myapp"},
|
||||
"versions": {"myapp": "4.5.6"}
|
||||
}
|
||||
}
|
||||
}
|
||||
# No image_key argument → falls back to application_id
|
||||
result = self.get_docker_image(applications, "myapp")
|
||||
self.assertEqual(result, "registry/myapp:4.5.6")
|
||||
|
||||
# --- new: Alternate image_key lookup ---
|
||||
def test_alternate_image_key(self):
|
||||
applications = {
|
||||
"service": {
|
||||
"version": "9.9.9",
|
||||
"docker": {
|
||||
"images": {
|
||||
"service": "registry/service",
|
||||
"db": "registry/service-db"
|
||||
},
|
||||
"versions": {
|
||||
"db": "2.2.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result = self.get_docker_image(applications, "service", "db")
|
||||
self.assertEqual(result, "registry/service-db:2.2.2")
|
||||
|
||||
# --- new: Missing application raises error ---
|
||||
def test_missing_application_raises_error(self):
|
||||
applications = {}
|
||||
with self.assertRaises(ValueError):
|
||||
self.get_docker_image(applications, "does_not_exist")
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
Reference in New Issue
Block a user