forked from mirrors/thatmattlove-hyperglass
Remove query_group from query fields
This commit is contained in:
parent
27b6ba09d8
commit
c2240d92c6
5 changed files with 3 additions and 58 deletions
|
|
@ -71,7 +71,7 @@ async def send_webhook(
|
||||||
|
|
||||||
await hook.send(
|
await hook.send(
|
||||||
query={
|
query={
|
||||||
**query_data.export_dict(pretty=True),
|
**query_data.dict(),
|
||||||
"headers": headers,
|
"headers": headers,
|
||||||
"source": host,
|
"source": host,
|
||||||
"network": network_info.get(host, {}),
|
"network": network_info.get(host, {}),
|
||||||
|
|
|
||||||
|
|
@ -97,14 +97,6 @@ class QueryTypeNotFound(NotFound):
|
||||||
super().__init__(type=TEXT.query_type, name=str(query_type), **kwargs)
|
super().__init__(type=TEXT.query_type, name=str(query_type), **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class QueryGroupNotFound(NotFound):
|
|
||||||
"""Raised when a query group is not found."""
|
|
||||||
|
|
||||||
def __init__(self, group: Any, **kwargs: Dict[str, Any]) -> None:
|
|
||||||
"""Initialize a NotFound error for a query group."""
|
|
||||||
super().__init__(type=TEXT.query_group, name=str(group), **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class InputInvalid(PublicHyperglassError, template=MESSAGES.invalid_input):
|
class InputInvalid(PublicHyperglassError, template=MESSAGES.invalid_input):
|
||||||
"""Raised when input validation fails."""
|
"""Raised when input validation fails."""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
"""Input query validation model."""
|
"""Input query validation model."""
|
||||||
|
|
||||||
# Standard Library
|
# Standard Library
|
||||||
import json
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import secrets
|
import secrets
|
||||||
from typing import Optional
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
# Third Party
|
# Third Party
|
||||||
|
|
@ -30,12 +28,8 @@ from ..config.devices import Device
|
||||||
class Query(BaseModel):
|
class Query(BaseModel):
|
||||||
"""Validation model for input query parameters."""
|
"""Validation model for input query parameters."""
|
||||||
|
|
||||||
# Device `name` field
|
query_location: StrictStr # Device `name` field
|
||||||
query_location: StrictStr
|
query_type: StrictStr # Directive `id` field
|
||||||
# Directive `id` field
|
|
||||||
query_type: StrictStr
|
|
||||||
# Directive `groups` member
|
|
||||||
query_group: Optional[StrictStr] = None
|
|
||||||
query_target: constr(strip_whitespace=True, min_length=1)
|
query_target: constr(strip_whitespace=True, min_length=1)
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
|
@ -54,11 +48,6 @@ class Query(BaseModel):
|
||||||
"description": "Type of Query to Execute",
|
"description": "Type of Query to Execute",
|
||||||
"example": "bgp_route",
|
"example": "bgp_route",
|
||||||
},
|
},
|
||||||
"query_group": {
|
|
||||||
"title": TEXT.query_group,
|
|
||||||
"description": "Routing Table/VRF",
|
|
||||||
"example": "default",
|
|
||||||
},
|
|
||||||
"query_target": {
|
"query_target": {
|
||||||
"title": TEXT.query_target,
|
"title": TEXT.query_target,
|
||||||
"description": "IP Address, Community, or AS Path",
|
"description": "IP Address, Community, or AS Path",
|
||||||
|
|
@ -105,45 +94,11 @@ class Query(BaseModel):
|
||||||
self.directive.validate_target(self.query_target)
|
self.directive.validate_target(self.query_target)
|
||||||
log.debug("Validation passed for query {!r}", self)
|
log.debug("Validation passed for query {!r}", self)
|
||||||
|
|
||||||
@property
|
|
||||||
def summary(self):
|
|
||||||
"""Create abbreviated representation of instance."""
|
|
||||||
items = (
|
|
||||||
f"query_location={self.query_location}",
|
|
||||||
f"query_type={self.query_type}",
|
|
||||||
f"query_group={self.query_group}",
|
|
||||||
f"query_target={self.query_target!s}",
|
|
||||||
)
|
|
||||||
return f'Query({", ".join(items)})'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device(self) -> Device:
|
def device(self) -> Device:
|
||||||
"""Get this query's device object by query_location."""
|
"""Get this query's device object by query_location."""
|
||||||
return self._state.devices[self.query_location]
|
return self._state.devices[self.query_location]
|
||||||
|
|
||||||
def export_dict(self, pretty=False):
|
|
||||||
"""Create dictionary representation of instance."""
|
|
||||||
|
|
||||||
if pretty:
|
|
||||||
items = {
|
|
||||||
"query_location": self.device.name,
|
|
||||||
"query_type": self.query.display_name,
|
|
||||||
"query_group": self.query_group,
|
|
||||||
"query_target": str(self.query_target),
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
items = {
|
|
||||||
"query_location": self.query_location,
|
|
||||||
"query_type": self.query_type,
|
|
||||||
"query_group": self.query_group,
|
|
||||||
"query_target": str(self.query_target),
|
|
||||||
}
|
|
||||||
return items
|
|
||||||
|
|
||||||
def export_json(self):
|
|
||||||
"""Create JSON representation of instance."""
|
|
||||||
return json.dumps(self.export_dict(), default=str)
|
|
||||||
|
|
||||||
@validator("query_type")
|
@validator("query_type")
|
||||||
def validate_query_type(cls, value):
|
def validate_query_type(cls, value):
|
||||||
"""Ensure a requested query type exists."""
|
"""Ensure a requested query type exists."""
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,6 @@ class Text(HyperglassModel):
|
||||||
query_location: StrictStr = "Location"
|
query_location: StrictStr = "Location"
|
||||||
query_type: StrictStr = "Query Type"
|
query_type: StrictStr = "Query Type"
|
||||||
query_target: StrictStr = "Target"
|
query_target: StrictStr = "Target"
|
||||||
query_group: StrictStr = "Routing Table"
|
|
||||||
fqdn_tooltip: StrictStr = "Use {protocol}" # Formatted by Javascript
|
fqdn_tooltip: StrictStr = "Use {protocol}" # Formatted by Javascript
|
||||||
fqdn_message: StrictStr = "Your browser has resolved {fqdn} to" # Formatted by Javascript
|
fqdn_message: StrictStr = "Your browser has resolved {fqdn} to" # Formatted by Javascript
|
||||||
fqdn_error: StrictStr = "Unable to resolve {fqdn}" # Formatted by Javascript
|
fqdn_error: StrictStr = "Unable to resolve {fqdn}" # Formatted by Javascript
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ interface _Text {
|
||||||
query_location: string;
|
query_location: string;
|
||||||
query_type: string;
|
query_type: string;
|
||||||
query_target: string;
|
query_target: string;
|
||||||
query_group: string;
|
|
||||||
fqdn_tooltip: string;
|
fqdn_tooltip: string;
|
||||||
fqdn_message: string;
|
fqdn_message: string;
|
||||||
fqdn_error: string;
|
fqdn_error: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue