Files
unshackle/unshackle/core/utils/service_params.py
T
imSp4rky 5206b3cab6 refactor(remote)!: send service options only in service_params
A service option named like a dl option (e.g. --profile) is no longer dropped or mixed with the dl value; the server casts nested values and keeps cli defaults nested.
2026-10-30 16:16:56 -06:00

19 lines
836 B
Python

from typing import Any, Collection, Dict, Iterable
FLAT_DL_KEYS = frozenset({"title", "service", "title_id", "profile", "proxy", "no_proxy"})
def service_options(
data: Dict[str, Any], names: Collection[str], flat_excluded: Iterable[str] = FLAT_DL_KEYS
) -> Dict[str, Any]:
"""A request's service options named in ``names``: from its ``service_params`` object, else its flat keys.
With ``service_params`` present every flat key is a dl value, so it never fills a service option of the same name.
Without it, the flat keys in ``flat_excluded`` stay dl values.
"""
nested = data.get("service_params")
if isinstance(nested, dict):
return {k: v for k, v in nested.items() if k in names}
excluded = set(flat_excluded)
return {k: v for k, v in data.items() if k in names and k not in excluded}