diff --git a/src/common/gen/Configurator.py b/src/common/gen/Configurator.py index 616b8c22d2..13ac3a2ee0 100644 --- a/src/common/gen/Configurator.py +++ b/src/common/gen/Configurator.py @@ -50,7 +50,7 @@ def __init__( self.__compiled_regexes = {} # Pre-defined exclusion sets for config processing - self.__excluded_prefixes = ("_", "PYTHON", "KUBERNETES_", "SVC_", "LB_", "SUPERVISOR_") + self.__excluded_prefixes = ("PYTHON", "KUBERNETES_", "NOMAD_", "SVC_", "LB_", "SUPERVISOR_") self.__excluded_vars = frozenset( { "DOCKER_HOST", @@ -112,6 +112,36 @@ def __init__( else: self.__variables = variables + # Allow a leading underscore prefix on env var names so that domain names + # starting with a digit can be configured (bash forbids var names starting + # with a digit, e.g. 1nteresting.io). Users write _1nteresting.io_USE_... + # and we strip the single leading underscore here before any other processing. + stripped: Dict[str, str] = {} + stripped_origins: Dict[str, str] = {} # new_key -> original key that set the current value + for k, v in self.__variables.items(): + new_key = k.removeprefix("_") + if not new_key: + # Skip bare "_" or similar empty-after-strip keys + continue + if new_key in stripped: + prev_key = stripped_origins[new_key] + # Deterministic tie-break: the explicit (non-underscore) key wins over the + # underscore-prefixed form, independent of dict iteration order, so the same + # input always yields the same output. In a collision exactly one of the two + # keys equals new_key (the explicit form); the other is "_" + new_key. + explicit_wins = k == new_key + winner = k if explicit_wins else prev_key + self.__logger.warning( + f"Variable collision after stripping leading underscore: {prev_key!r} and {k!r} both map to {new_key!r}, keeping {winner!r}" + ) + if explicit_wins: + stripped[new_key] = v + stripped_origins[new_key] = k + continue + stripped[new_key] = v + stripped_origins[new_key] = k + self.__variables = stripped + self.__multisite = self.__variables.get("MULTISITE", "no") == "yes" self.__servers = self.__map_servers()