60 lines
1.4 KiB
Python
60 lines
1.4 KiB
Python
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright: (c) 2024, Luca Bilke <luca@bil.ke>
|
|
# MIT License (see LICENSE)
|
|
|
|
# TODO: write ansible sections
|
|
|
|
DOCUMENTATION = r"""
|
|
"""
|
|
|
|
EXAMPLES = r"""
|
|
"""
|
|
|
|
RETURN = r"""
|
|
"""
|
|
|
|
from __future__ import annotations # pyright: ignore[reportGeneralTypeIssues]
|
|
|
|
from ansible_collections.snailed.ez_compose.plugins.module_utils.common import (
|
|
State,
|
|
run_label,
|
|
update_service,
|
|
)
|
|
|
|
|
|
def helper(state: State) -> State:
|
|
service_name = state.module.params["name"]
|
|
project_name = state.module.params["project_name"]
|
|
middleware = state.module.params["middleware"]
|
|
settings = state.module.params["settings"]
|
|
proxy_type = state.module.params.get("proxy_type", "http")
|
|
middleware_name = state.module.params.get(
|
|
"middleware_name",
|
|
f"{project_name}_{service_name}_{proxy_type}_{middleware.lower()}",
|
|
)
|
|
|
|
prefix = f"traefik.{proxy_type}.middlewares.{middleware_name}"
|
|
|
|
labels = {f"{prefix}.{middleware}.{key}": var for key, var in settings.items()}
|
|
|
|
update = {
|
|
"labels": labels,
|
|
}
|
|
|
|
return update_service(state, update)
|
|
|
|
|
|
def main():
|
|
extra_args = {
|
|
"proxy_type": {"type": "str"},
|
|
"middleware_name": {"type": "string"},
|
|
"middleware": {"type": "str", "required": True},
|
|
"settings": {"type": "list", "required": True},
|
|
}
|
|
run_label(extra_args, helper)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|