42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
# Copyright: (c) 2025, Luca Bilke <luca@bil.ke>
|
|
# MIT License (see LICENSE)
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Any, Callable
|
|
|
|
from ansible_collections.snailed.ez_compose.plugins.module_utils.common import (
|
|
clean_none,
|
|
recursive_update,
|
|
)
|
|
|
|
if TYPE_CHECKING:
|
|
from ansible_collections.snailed.ez_compose.plugins.module_utils.models import State
|
|
|
|
|
|
BASE_ARGS: dict[str, Any] = {}
|
|
|
|
|
|
def apply_update(
|
|
service: dict[str, Any],
|
|
update: dict[str, Any],
|
|
) -> dict[str, Any]:
|
|
return recursive_update(service, update)
|
|
|
|
|
|
def get_default_args(state: State, helper_name: str) -> dict[str, Any]:
|
|
settings: dict[str, Any] = state.module.params.get("settings") or {}
|
|
label_default_args: dict[str, Any] = settings.get("label_default_args") or {}
|
|
default_args: dict[str, Any] = label_default_args.get(helper_name) or {}
|
|
return clean_none(default_args)
|
|
|
|
|
|
def run_helper(
|
|
state: State,
|
|
service_name: str,
|
|
service: dict[str, Any],
|
|
params: dict[str, Any],
|
|
helper: Callable[[State, str, dict[str, Any]], dict[str, Any]] = lambda _a, _b, _c: {},
|
|
) -> dict[str, Any]:
|
|
update = helper(state, service_name, params)
|
|
return apply_update(service, update)
|