42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
# Copyright: (c) 2024, Luca Bilke <luca@bil.ke>
|
|
# MIT License (see LICENSE)
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
import ansible_collections.ssnailed.ez_compose.plugins.module_utils.service.common as service
|
|
|
|
if TYPE_CHECKING:
|
|
from ansible_collections.ssnailed.ez_compose.plugins.module_utils.common import (
|
|
State,
|
|
)
|
|
|
|
EXTRA_ARGS = {
|
|
"proxy_type": {"type": "str", "default": "http"},
|
|
"name": {"type": "string"},
|
|
"port": {"type": "int"},
|
|
}
|
|
|
|
|
|
def helper(state: State, service_name: str, params: dict[str, Any]) -> State:
|
|
project_name: str = state.module.params["name"]
|
|
port: int | None = params.get("port")
|
|
proxy_type: str = params["proxy_type"]
|
|
name: str = params.get(
|
|
"name",
|
|
f"{project_name}_{service_name}_{proxy_type}",
|
|
)
|
|
|
|
prefix = f"traefik.{proxy_type}.services.{name}"
|
|
|
|
labels: dict[str, Any] = {}
|
|
|
|
if port:
|
|
labels[f"{prefix}.loadbalancer.server.port"] = str(port)
|
|
|
|
update = {
|
|
"labels": labels,
|
|
}
|
|
|
|
return service.update(service_name, state, update)
|