mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
31 lines
864 B
Python
31 lines
864 B
Python
"""Input validation plugins."""
|
|
|
|
# Standard Library
|
|
import typing as t
|
|
|
|
# Local
|
|
from ._base import DirectivePlugin, HyperglassPlugin
|
|
|
|
if t.TYPE_CHECKING:
|
|
# Project
|
|
from hyperglass.models.api.query import Query, QueryTarget
|
|
|
|
|
|
InputPluginValidationReturn = t.Union[None, bool]
|
|
InputPluginTransformReturn = t.Union[t.Sequence["QueryTarget"], "QueryTarget"]
|
|
|
|
|
|
class InputPlugin(HyperglassPlugin, DirectivePlugin):
|
|
"""Plugin to validate user input prior to running commands."""
|
|
|
|
_type = "input"
|
|
failure_reason: t.Optional[str] = None
|
|
|
|
def validate(self, query: "Query") -> InputPluginValidationReturn:
|
|
"""Validate input from hyperglass UI/API."""
|
|
return None
|
|
|
|
def transform(self, query: "Query") -> InputPluginTransformReturn:
|
|
"""Transform query target prior to running commands."""
|
|
return query.query_target
|