1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

Remove query_group from query fields

This commit is contained in:
thatmattlove
2021-09-25 21:50:51 -07:00
parent 27b6ba09d8
commit c2240d92c6
5 changed files with 3 additions and 58 deletions

View File

@@ -71,7 +71,7 @@ async def send_webhook(
await hook.send(
query={
**query_data.export_dict(pretty=True),
**query_data.dict(),
"headers": headers,
"source": host,
"network": network_info.get(host, {}),

View File

@@ -97,14 +97,6 @@ class QueryTypeNotFound(NotFound):
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):
"""Raised when input validation fails."""

View File

@@ -1,10 +1,8 @@
"""Input query validation model."""
# Standard Library
import json
import hashlib
import secrets
from typing import Optional
from datetime import datetime
# Third Party
@@ -30,12 +28,8 @@ from ..config.devices import Device
class Query(BaseModel):
"""Validation model for input query parameters."""
# Device `name` field
query_location: StrictStr
# Directive `id` field
query_type: StrictStr
# Directive `groups` member
query_group: Optional[StrictStr] = None
query_location: StrictStr # Device `name` field
query_type: StrictStr # Directive `id` field
query_target: constr(strip_whitespace=True, min_length=1)
class Config:
@@ -54,11 +48,6 @@ class Query(BaseModel):
"description": "Type of Query to Execute",
"example": "bgp_route",
},
"query_group": {
"title": TEXT.query_group,
"description": "Routing Table/VRF",
"example": "default",
},
"query_target": {
"title": TEXT.query_target,
"description": "IP Address, Community, or AS Path",
@@ -105,45 +94,11 @@ class Query(BaseModel):
self.directive.validate_target(self.query_target)
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
def device(self) -> Device:
"""Get this query's device object by 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")
def validate_query_type(cls, value):
"""Ensure a requested query type exists."""

View File

@@ -141,7 +141,6 @@ class Text(HyperglassModel):
query_location: StrictStr = "Location"
query_type: StrictStr = "Query Type"
query_target: StrictStr = "Target"
query_group: StrictStr = "Routing Table"
fqdn_tooltip: StrictStr = "Use {protocol}" # 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

View File

@@ -36,7 +36,6 @@ interface _Text {
query_location: string;
query_type: string;
query_target: string;
query_group: string;
fqdn_tooltip: string;
fqdn_message: string;
fqdn_error: string;