This commit is contained in:
checktheroads 2019-09-04 01:28:55 -07:00
parent 0a25552193
commit a5bb782d3e
4 changed files with 20 additions and 82 deletions

View file

@ -251,7 +251,7 @@ class Branding(BaseSettings):
primary: Color = "#40798c"
secondary: Color = "#330036"
danger: Color = "#ff5e5b"
danger: Color = "#a21024"
warning: Color = "#eec643"
light: Color = "#fbfffe"
dark: Color = "#383541"
@ -296,9 +296,9 @@ class Branding(BaseSettings):
title_mode: str = "logo_only"
title: str = "hyperglass"
subtitle: str = "AS{primary_asn}"
location: str = "Location"
query_location: str = "Location"
query_type: str = "Query"
query_placeholder: str = "Target"
query_target: str = "Target"
terms: str = "Terms"
info: str = "Help"
peeringdb = "PeeringDB"
@ -354,7 +354,7 @@ class Messages(BaseSettings):
no_query_type: str = "A query type must be specified."
no_location: str = "A location must be selected."
no_input: str = "A target must be specified"
no_input: str = "{query_type} must be specified."
blacklist: str = "{target} a member of {blacklisted_net}, which is not allowed."
max_prefix: str = (
"Prefix length must be shorter than /{max_length}. {target} is too specific."

View file

@ -5,42 +5,6 @@ Global Constants for hyperglass
protocol_map = {80: "http", 8080: "http", 443: "https", 8443: "https"}
class Status:
"""
Defines codes, messages, and method names for status codes used by
hyperglass.
"""
codes_dict = {
200: ("valid", "Valid Query"),
405: ("not_allowed", "Query Not Allowed"),
415: ("invalid", "Invalid Query"),
504: ("target_error", "Unable to Reach Target"),
}
def __init__(self):
"""
Dynamically generates class attributes for codes in codes_dict.
"""
for (_code, text) in Status.codes_dict.items():
setattr(self, text[0], _code)
@staticmethod
def get_reason(search_code):
"""
Maps and returns input code integer to associated reason text.
Mainly used for populating Prometheus fields.
"""
reason = None
for (_code, text) in Status.codes_dict.items():
if _code == search_code:
reason = text[1]
return reason
code = Status()
class Supported:
"""
Defines items supported by hyperglass.

View file

@ -2,26 +2,20 @@
Custom exceptions for hyperglass
"""
from hyperglass.constants import code
class HyperglassError(Exception):
"""hyperglass base exception"""
def __init__(self, message="", status=500, keywords={}):
def __init__(self, message="", alert="warning", keywords={}):
self.message = message
self.status = status
self.alert = alert
self.keywords = keywords
def __str__(self):
return self.message
def __dict__(self):
return {
"message": self.message,
"status": self.status,
"keywords": self.keywords,
}
return {"message": self.message, "alert": self.alert, "keywords": self.keywords}
class ConfigError(HyperglassError):
@ -63,11 +57,9 @@ class ScrapeError(HyperglassError):
def __init__(self, msg, **kwargs):
self.message = msg.format(**kwargs)
self.status = code.target_error
self.alert = "danger"
self.keywords = [value for value in kwargs.values()]
super().__init__(
message=self.message, status=self.status, keywords=self.keywords
)
super().__init__(message=self.message, alert=self.alert, keywords=self.keywords)
class AuthError(HyperglassError):
@ -75,11 +67,9 @@ class AuthError(HyperglassError):
def __init__(self, msg, **kwargs):
self.message = msg.format(**kwargs)
self.status = code.target_error
self.alert = "danger"
self.keywords = [value for value in kwargs.values()]
super().__init__(
message=self.message, status=self.status, keywords=self.keywords
)
super().__init__(message=self.message, alert=self.alert, keywords=self.keywords)
class RestError(HyperglassError):
@ -87,11 +77,9 @@ class RestError(HyperglassError):
def __init__(self, msg, **kwargs):
self.message = msg.format(**kwargs)
self.status = code.target_error
self.alert = "danger"
self.keywords = [value for value in kwargs.values()]
super().__init__(
message=self.message, status=self.status, keywords=self.keywords
)
super().__init__(message=self.message, alert=self.alert, keywords=self.keywords)
class InputInvalid(HyperglassError):
@ -99,11 +87,9 @@ class InputInvalid(HyperglassError):
def __init__(self, unformatted_msg, **kwargs):
self.message = unformatted_msg.format(**kwargs)
self.status = code.invalid
self.alert = "warning"
self.keywords = [value for value in kwargs.values()]
super().__init__(
message=self.message, status=self.status, keywords=self.keywords
)
super().__init__(message=self.message, alert=self.alert, keywords=self.keywords)
class InputNotAllowed(HyperglassError):
@ -114,11 +100,9 @@ class InputNotAllowed(HyperglassError):
def __init__(self, unformatted_msg, **kwargs):
self.message = unformatted_msg.format(**kwargs)
self.status = code.invalid
self.alert = "warning"
self.keywords = [value for value in kwargs.values()]
super().__init__(
message=self.message, status=self.status, keywords=self.keywords
)
super().__init__(message=self.message, alert=self.alert, keywords=self.keywords)
class UnsupportedDevice(HyperglassError):
@ -126,11 +110,8 @@ class UnsupportedDevice(HyperglassError):
def __init__(self, **kwargs):
self.message = "".format(**kwargs)
self.status = code.target_error
self.keywords = [value for value in kwargs.values()]
super().__init__(
message=self.message, status=self.status, keywords=self.keywords
)
super().__init__(message=self.message, keywords=self.keywords)
class DeviceTimeout(HyperglassError):
@ -138,8 +119,6 @@ class DeviceTimeout(HyperglassError):
def __init__(self, msg, **kwargs):
self.message = msg.format(**kwargs)
self.status = code.target_error
self.alert = "danger"
self.keywords = [value for value in kwargs.values()]
super().__init__(
message=self.message, status=self.status, keywords=self.keywords
)
super().__init__(message=self.message, alert=self.alert, keywords=self.keywords)

View file

@ -1,5 +0,0 @@
<p><small>Powered by <a href="https://github.com/checktheroads/hyperglass" target="_blank">hyperglass</a>.
Source code
licensed <a href="https://github.com/checktheroads/hyperglass/blob/master/LICENSE" target="_blank">BSD
3-Clause
Clear.</a></small></p>