32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
"""Resolver that inherits a candidate from another entity's resolution.
|
|
|
|
Used by BGP events to pick up the location of their owning collector. The
|
|
``source_lookup`` callable is the only domain coupling — it receives the
|
|
incoming :class:`LocationQuery` and returns either an already-resolved
|
|
:class:`LocationCandidate` (typically by querying another pipeline) or
|
|
``None`` to signal "no parent location available".
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Callable
|
|
|
|
from ..models import LocationCandidate, LocationQuery, ResolverOutput
|
|
|
|
|
|
class InheritFromAnotherEntityResolver:
|
|
def __init__(
|
|
self,
|
|
*,
|
|
source_lookup: Callable[[LocationQuery], LocationCandidate | None],
|
|
name: str = "inherited",
|
|
) -> None:
|
|
self.name = name
|
|
self._lookup = source_lookup
|
|
|
|
def resolve(self, query: LocationQuery) -> ResolverOutput:
|
|
result = self._lookup(query)
|
|
if result is None:
|
|
return ResolverOutput()
|
|
return ResolverOutput(candidates=(result,))
|