Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Class model for params.branding"""
site_name: str = "hyperglass"
class Colors(BaseSettings):
"""Class model for params.colors"""
primary: Color = "#40798c"
secondary: Color = "#330036"
danger: Color = "#a21024"
warning: Color = "#eec643"
light: Color = "#fbfffe"
dark: Color = "#383541"
background: Color = "#fbfffe"
class Credit(BaseSettings):
"""Class model for params.branding.credit"""
enable: bool = True
class Font(BaseSettings):
"""Class model for params.branding.font"""
primary: str = "Nunito"
mono: str = "Fira Code"
class HelpMenu(BaseSettings):
"""Class model for params.branding.help_menu"""
enable: bool = True
class Logo(BaseSettings):
def is_pydantic(test_object):
try:
instance = isinstance(test_object, BaseSettings) or isinstance(test_object, BaseModel)
except TypeError:
instance = False
try:
subclass = issubclass(test_object, BaseSettings) or issubclass(test_object, BaseModel)
except TypeError:
subclass = False
return instance or subclass
hostnames.append(dev)
for vrf in router_params.dict()["vrfs"]:
vrfs.add(vrf)
Routers.routers = routers
Routers.hostnames = hostnames
Routers.vrfs = list(vrfs)
return Routers()
class Config:
"""Pydantic Config"""
validate_all = True
validate_assignment = True
class Network(BaseSettings):
"""Model for per-network/asn config in devices.yaml"""
display_name: str
class Networks(BaseSettings):
"""Base model for networks class"""
@classmethod
def import_params(cls, input_params):
"""
Imports passed dict from YAML config, removes unsupported
characters from device names, dynamically sets attributes for
the credentials class.
"""
obj = Networks()
from pydantic import BaseSettings
class Settings(BaseSettings):
redis_host = 'localhost' # set os env APP_REDIS_HOST to overwrite
redis_port = 6379
redis_database = 0
debug = False # 'true' and '1' are True, 'false' and '0' are False
class Config:
env_prefix = 'APP_'
def main():
settings = Settings()
print(settings.redis_host)
print(settings.redis_port, type(settings.redis_port))
print(settings.debug)
pg_dsn_default = 'postgres://postgres@localhost:5432/app'
try:
from cryptography.fernet import Fernet
except ImportError:
auth_key_default = None
else:
# generate_key is used to avoid a public default value ever being used in production
auth_key_default = Fernet.generate_key().decode()
# see https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha-what-should-i-do
GREPAPTCHA_TEST_SECRET = '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe'
class BaseSettings(_BaseSettings):
worker_func: str = None
create_app: str = 'main.create_app'
patch_paths: List[str] = []
sql_path: Path = 'models.sql'
pg_dsn: Optional[str] = pg_dsn_default
# eg. the db already exists on heroku and never has to be created
pg_db_exists = False
redis_settings: Optional[RedisSettings] = redis_settings_default
port: int = 8000
auth_key: str = auth_key_default
max_request_size = 10 * 1024 ** 2 # 10MB
locale = 'en_US.utf8'
bgp_aspath: str = 'show bgp {afi} unicast quote-regexp "{target}"'
bgp_route: str = "show bgp {afi} unicast {target} | exclude pathid:|Epoch"
ping: str = (
"ping {afi} {target} repeat 5 source {source} | exclude Type escape"
)
traceroute: str = (
"traceroute ipv6 {target} timeout 1 probe 2 source {source} "
"| exclude Type escape"
)
vpnv4: VPNv4 = VPNv4()
vpnv6: VPNv6 = VPNv6()
ipv4: IPv4 = IPv4()
ipv6: IPv6 = IPv6()
class CiscoXR(BaseSettings):
"""Class model for default cisco_xr commands"""
class Dual(BaseSettings):
"""Default commands for dual afi commands"""
bgp_community: str = (
"show bgp all unicast community {target} | utility egrep -v "
'"\\(BGP |Table |Non-stop\\)"'
)
bgp_aspath: str = (
"show bgp all unicast regexp {target} | utility egrep -v "
'"\\(BGP |Table |Non-stop\\)"'
)
class IPv4(BaseSettings):
"""Default commands for ipv4 commands"""
from pydantic import BaseSettings
from typing import List
class Settings(BaseSettings):
"""
Configuration settings for this library.
For now you could only change the settings
via CONTRIB_ environment variables.
:param logger: Dotted path to the logger (using this attribute, standard
logging methods will be used: logging.debug(), .info(), etc.
:param log_level: Standard LEVEL for logging (DEBUG/INFO/WARNING/etc.)
:param debug_timing: Whether to enable time logging for decorated functions
:param request_id_header: String name for header, that is expected to have
unique request id for tracing purposes.
Might go away when we add opentracing here.
:param mongodb_dsn: DSN connection string to MongoDB
:param mongodb_dbname: String name of a database to connect to in MongoDB
:param mongodb_id_generator: Dotted path to the function, which will
"""Class model for params.branding.credit"""
enable: bool = True
class Font(BaseSettings):
"""Class model for params.branding.font"""
primary: str = "Nunito"
mono: str = "Fira Code"
class HelpMenu(BaseSettings):
"""Class model for params.branding.help_menu"""
enable: bool = True
class Logo(BaseSettings):
"""Class model for params.branding.logo"""
path: str = "ui/images/hyperglass-dark.png"
width: int = 384
favicons: str = "ui/images/favicons/"
class PeeringDb(BaseSettings):
"""Class model for params.branding.peering_db"""
enable: bool = True
class Terms(BaseSettings):
"""Class model for params.branding.terms"""
enable: bool = True
networks = {}
for (netname, params) in input_params.items():
netname = clean_name(netname)
setattr(Networks, netname, Network(**params))
networks.update({netname: Network(**params).dict()})
Networks.networks = networks
return obj
class Config:
"""Pydantic Config"""
validate_all = True
validate_assignment = True
class Credential(BaseSettings):
"""Model for per-credential config in devices.yaml"""
username: str
password: SecretStr
class Credentials(BaseSettings):
"""Base model for credentials class"""
@classmethod
def import_params(cls, input_params):
"""
Imports passed dict from YAML config, removes unsupported
characters from device names, dynamically sets attributes for
the credentials class.
"""
class BgpCommunity(BaseSettings):
"""Class model for params.features.bgp_community"""
enable: bool = True
class Regex(BaseSettings):
"""Class model for params.features.bgp_community.regex"""
decimal: str = r"^[0-9]{1,10}$"
extended_as: str = r"^([0-9]{0,5})\:([0-9]{1,5})$"
large: str = r"^([0-9]{1,10})\:([0-9]{1,10})\:[0-9]{1,10}$"
regex: Regex = Regex()
class BgpAsPath(BaseSettings):
"""Class model for params.features.bgp_aspath"""
enable: bool = True
class Regex(BaseSettings):
"""Class model for params.bgp_aspath.regex"""
mode: constr(regex="asplain|asdot") = "asplain"
asplain: str = r"^(\^|^\_)(\d+\_|\d+\$|\d+\(\_\.\+\_\))+$"
asdot: str = (
r"^(\^|^\_)((\d+\.\d+)\_|(\d+\.\d+)\$|(\d+\.\d+)\(\_\.\+\_\))+$"
)
regex: Regex = Regex()
class Ping(BaseSettings):