Skip to content

_values

Input normalization shared by the schema-backed firewall objects.

as_list #

as_list(value: object) -> Optional[list[object]]

Accept one value or the API's array form, preserving absent values.

Source code in pyfortinet/fmg_api/firewall/_values.py
def as_list(value: object) -> Optional[list[object]]:
    """Accept one value or the API's array form, preserving absent values."""
    if value is None or isinstance(value, list):
        return value
    return [value]

reference_names #

reference_names(value: object) -> Optional[list[str]]

Turn named high-level object references into the API's name arrays.

Source code in pyfortinet/fmg_api/firewall/_values.py
def reference_names(value: object) -> Optional[list[str]]:
    """Turn named high-level object references into the API's name arrays."""
    values = as_list(value)
    if values is None:
        return None
    result = []
    for item in values:
        name = getattr(item, "name", None) if isinstance(item, FMGObject) else item
        if not isinstance(name, str) or not name:
            raise ValueError("References must be nonempty names or objects with a name")
        result.append(name)
    return result

uuid_string #

uuid_string(value: Optional[str]) -> Optional[str]

Validate UUID values while leaving omitted attributes unset.

Source code in pyfortinet/fmg_api/firewall/_values.py
def uuid_string(value: Optional[str]) -> Optional[str]:
    """Validate UUID values while leaving omitted attributes unset."""
    return str(UUID(value)) if value is not None else None