mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
fix model type annotations to make flake8 happy
This commit is contained in:
@@ -5,6 +5,8 @@ from pydantic import Field, HttpUrl, StrictStr, StrictBool, constr
|
||||
# Project
|
||||
from hyperglass.models import AnyUri, HyperglassModel
|
||||
|
||||
DocsMode = constr(regex=r"(swagger|redoc)")
|
||||
|
||||
|
||||
class EndpointConfig(HyperglassModel):
|
||||
"""Validation model for per API endpoint documentation."""
|
||||
@@ -32,7 +34,7 @@ class Docs(HyperglassModel):
|
||||
enable: StrictBool = Field(
|
||||
True, title="Enable", description="Enable or disable API documentation."
|
||||
)
|
||||
mode: constr(regex=r"(swagger|redoc)") = Field(
|
||||
mode: DocsMode = Field(
|
||||
"redoc",
|
||||
title="Docs Mode",
|
||||
description="OpenAPI UI library to use for the hyperglass API docs. Currently, the options are [Swagger UI](/fixme) and [Redoc](/fixme).",
|
||||
|
@@ -24,6 +24,10 @@ from pydantic import (
|
||||
from hyperglass.models import HyperglassModel, HyperglassModelExtra
|
||||
from hyperglass.constants import __version__
|
||||
|
||||
HttpAuthMode = constr(regex=r"(basic|api_key)")
|
||||
HttpProvider = constr(regex=r"(msteams|slack|generic)")
|
||||
LogFormat = constr(regex=r"(text|json)")
|
||||
|
||||
|
||||
class Syslog(HyperglassModel):
|
||||
"""Validation model for syslog configuration."""
|
||||
@@ -36,7 +40,7 @@ class Syslog(HyperglassModel):
|
||||
class HttpAuth(HyperglassModel):
|
||||
"""HTTP hook authentication parameters."""
|
||||
|
||||
mode: constr(regex=r"(basic|api_key)") = "basic"
|
||||
mode: HttpAuthMode = "basic"
|
||||
username: Optional[StrictStr]
|
||||
password: SecretStr
|
||||
|
||||
@@ -53,7 +57,7 @@ class Http(HyperglassModelExtra):
|
||||
"""HTTP logging parameters."""
|
||||
|
||||
enable: StrictBool = True
|
||||
provider: constr(regex=r"(msteams|slack|generic)") = "generic"
|
||||
provider: HttpProvider = "generic"
|
||||
host: AnyHttpUrl
|
||||
authentication: Optional[HttpAuth]
|
||||
headers: Dict[StrictStr, Union[StrictStr, StrictInt, StrictBool, None]] = {}
|
||||
@@ -97,7 +101,7 @@ class Logging(HyperglassModel):
|
||||
"""Validation model for logging configuration."""
|
||||
|
||||
directory: DirectoryPath = Path("/tmp") # noqa: S108
|
||||
format: constr(regex=r"(text|json)") = "text"
|
||||
format: LogFormat = "text"
|
||||
max_size: ByteSize = "50MB"
|
||||
syslog: Optional[Syslog]
|
||||
http: Optional[Http]
|
||||
|
@@ -25,6 +25,8 @@ from hyperglass.configuration.models.queries import Queries
|
||||
from hyperglass.configuration.models.messages import Messages
|
||||
from hyperglass.configuration.models.structured import Structured
|
||||
|
||||
Localhost = constr(regex=r"localhost")
|
||||
|
||||
|
||||
class Params(HyperglassModel):
|
||||
"""Validation model for all configuration variables."""
|
||||
@@ -87,7 +89,7 @@ class Params(HyperglassModel):
|
||||
title="Request Timeout",
|
||||
description="Global timeout in seconds for all requests. The frontend application (UI) uses this field's exact value when submitting queries. The backend application uses this field's value, minus one second, for its own timeout handling. This is to ensure a contextual timeout error is presented to the end user in the event of a backend application timeout.",
|
||||
)
|
||||
listen_address: Optional[Union[IPvAnyAddress, constr(regex=r"localhost")]] = Field(
|
||||
listen_address: Optional[Union[IPvAnyAddress, Localhost]] = Field(
|
||||
None,
|
||||
title="Listen Address",
|
||||
description="Local IP Address or hostname the hyperglass application listens on to serve web traffic.",
|
||||
|
@@ -10,6 +10,9 @@ from pydantic import Field, StrictStr, StrictBool, constr
|
||||
from hyperglass.models import HyperglassModel
|
||||
from hyperglass.constants import SUPPORTED_QUERY_TYPES
|
||||
|
||||
ASPathMode = constr(regex=r"asplain|asdot")
|
||||
CommunityInput = constr(regex=r"(input|select)")
|
||||
|
||||
|
||||
class BgpCommunityPattern(HyperglassModel):
|
||||
"""Validation model for bgp_community regex patterns."""
|
||||
@@ -42,7 +45,7 @@ class BgpCommunityPattern(HyperglassModel):
|
||||
class BgpAsPathPattern(HyperglassModel):
|
||||
"""Validation model for bgp_aspath regex patterns."""
|
||||
|
||||
mode: constr(regex=r"asplain|asdot") = Field(
|
||||
mode: ASPathMode = Field(
|
||||
"asplain",
|
||||
title="AS Path Mode",
|
||||
description="Set ASN display mode. This field is dependent on how your network devices are configured.",
|
||||
@@ -89,7 +92,7 @@ class BgpCommunity(HyperglassModel):
|
||||
description="Text displayed for the BGP Community query type in the hyperglas UI.",
|
||||
)
|
||||
pattern: BgpCommunityPattern = BgpCommunityPattern()
|
||||
mode: constr(regex=r"(input|select)") = "input"
|
||||
mode: CommunityInput = "input"
|
||||
communities: List[Community] = []
|
||||
|
||||
|
||||
|
@@ -9,18 +9,21 @@ from pydantic import StrictStr, constr
|
||||
# Project
|
||||
from hyperglass.models import HyperglassModel
|
||||
|
||||
StructuredCommunityMode = constr(regex=r"(permit|deny)")
|
||||
StructuredRPKIMode = constr(regex=r"(router|external)")
|
||||
|
||||
|
||||
class StructuredCommunities(HyperglassModel):
|
||||
"""Control structured data response for BGP communties."""
|
||||
|
||||
mode: constr(regex=r"(permit|deny)") = "deny"
|
||||
mode: StructuredCommunityMode = "deny"
|
||||
items: List[StrictStr] = []
|
||||
|
||||
|
||||
class StructuredRpki(HyperglassModel):
|
||||
"""Control structured data response for RPKI state."""
|
||||
|
||||
mode: constr(regex=r"(router|external)") = "router"
|
||||
mode: StructuredRPKIMode = "router"
|
||||
|
||||
|
||||
class Structured(HyperglassModel):
|
||||
|
@@ -19,6 +19,8 @@ from pydantic import (
|
||||
# Project
|
||||
from hyperglass.models import HyperglassModel, HyperglassModelExtra
|
||||
|
||||
ACLAction = constr(regex=r"permit|deny")
|
||||
|
||||
|
||||
class AccessList4(HyperglassModel):
|
||||
"""Validation model for IPv4 access-lists."""
|
||||
@@ -28,7 +30,7 @@ class AccessList4(HyperglassModel):
|
||||
title="Network",
|
||||
description="IPv4 Network/Prefix that should be permitted or denied. ",
|
||||
)
|
||||
action: constr(regex=r"permit|deny") = Field(
|
||||
action: ACLAction = Field(
|
||||
"permit",
|
||||
title="Action",
|
||||
description="Permit or deny any networks contained within the prefix.",
|
||||
@@ -69,7 +71,7 @@ class AccessList6(HyperglassModel):
|
||||
title="Network",
|
||||
description="IPv6 Network/Prefix that should be permitted or denied. ",
|
||||
)
|
||||
action: constr(regex=r"permit|deny") = Field(
|
||||
action: ACLAction = Field(
|
||||
"permit",
|
||||
title="Action",
|
||||
description="Permit or deny any networks contained within the prefix.",
|
||||
|
@@ -24,6 +24,11 @@ from hyperglass.configuration.models.opengraph import OpenGraph
|
||||
|
||||
DEFAULT_IMAGES = Path(__file__).parent.parent.parent / "images"
|
||||
|
||||
Percentage = constr(regex=r"^([1-9][0-9]?|100)\%$")
|
||||
TitleMode = constr(regex=("logo_only|text_only|logo_title|logo_subtitle|all"))
|
||||
ColorMode = constr(regex=r"light|dark")
|
||||
DOHProvider = constr(regex="|".join(DNS_OVER_HTTPS.keys()))
|
||||
|
||||
|
||||
class Analytics(HyperglassModel):
|
||||
"""Validation model for Google Analytics."""
|
||||
@@ -95,8 +100,8 @@ class Logo(HyperglassModel):
|
||||
light: FilePath = DEFAULT_IMAGES / "hyperglass-light.svg"
|
||||
dark: FilePath = DEFAULT_IMAGES / "hyperglass-dark.svg"
|
||||
favicon: FilePath = DEFAULT_IMAGES / "hyperglass-icon.svg"
|
||||
width: Optional[Union[StrictInt, constr(regex=r"^([1-9][0-9]?|100)\%$")]] = "75%"
|
||||
height: Optional[Union[StrictInt, constr(regex=r"^([1-9][0-9]?|100)\%$")]]
|
||||
width: Optional[Union[StrictInt, Percentage]] = "75%"
|
||||
height: Optional[Union[StrictInt, Percentage]]
|
||||
|
||||
|
||||
class Terms(HyperglassModel):
|
||||
@@ -110,9 +115,7 @@ class Terms(HyperglassModel):
|
||||
class Text(HyperglassModel):
|
||||
"""Validation model for params.branding.text."""
|
||||
|
||||
title_mode: constr(
|
||||
regex=("logo_only|text_only|logo_title|logo_subtitle|all")
|
||||
) = "logo_only"
|
||||
title_mode: TitleMode = "logo_only"
|
||||
title: StrictStr = "hyperglass"
|
||||
subtitle: StrictStr = "Network Looking Glass"
|
||||
query_location: StrictStr = "Location"
|
||||
@@ -194,14 +197,14 @@ class Theme(HyperglassModel):
|
||||
"""Validation model for theme variables."""
|
||||
|
||||
colors: ThemeColors = ThemeColors()
|
||||
default_color_mode: Optional[constr(regex=r"light|dark")]
|
||||
default_color_mode: Optional[ColorMode]
|
||||
fonts: ThemeFonts = ThemeFonts()
|
||||
|
||||
|
||||
class DnsOverHttps(HyperglassModel):
|
||||
"""Validation model for DNS over HTTPS resolution."""
|
||||
|
||||
name: constr(regex="|".join(DNS_OVER_HTTPS.keys())) = "cloudflare"
|
||||
name: DOHProvider = "cloudflare"
|
||||
url: StrictStr = ""
|
||||
|
||||
@root_validator
|
||||
|
@@ -12,6 +12,8 @@ from hyperglass.log import log
|
||||
from hyperglass.models import HyperglassModel
|
||||
from hyperglass.parsing.models.serialized import ParsedRoutes
|
||||
|
||||
FRRPeerType = constr(regex=r"(internal|external)")
|
||||
|
||||
|
||||
def _alias_generator(field):
|
||||
components = field.split("_")
|
||||
@@ -39,7 +41,7 @@ class FRRPeer(_FRRBase):
|
||||
|
||||
peer_id: StrictStr
|
||||
router_id: StrictStr
|
||||
type: constr(regex=r"(internal|external)")
|
||||
type: FRRPeerType
|
||||
|
||||
|
||||
class FRRPath(_FRRBase):
|
||||
|
@@ -12,6 +12,8 @@ from hyperglass.models import HyperglassModel
|
||||
from hyperglass.configuration import params
|
||||
from hyperglass.external.rpki import rpki_state
|
||||
|
||||
WinningWeight = constr(regex=r"(low|high)")
|
||||
|
||||
|
||||
class ParsedRouteEntry(HyperglassModel):
|
||||
"""Per-Route Response Model."""
|
||||
@@ -94,4 +96,4 @@ class ParsedRoutes(HyperglassModel):
|
||||
vrf: StrictStr
|
||||
count: StrictInt = 0
|
||||
routes: List[ParsedRouteEntry]
|
||||
winning_weight: constr(regex=r"(low|high)")
|
||||
winning_weight: WinningWeight
|
||||
|
Reference in New Issue
Block a user