diff --git a/hyperglass/configuration/__init__.py b/hyperglass/configuration/__init__.py index bd901d8..2c2b08c 100644 --- a/hyperglass/configuration/__init__.py +++ b/hyperglass/configuration/__init__.py @@ -2,6 +2,7 @@ # Standard Library Imports import asyncio +import copy from pathlib import Path # Third Party Imports @@ -22,7 +23,7 @@ from hyperglass.constants import DEFAULT_TERMS from hyperglass.constants import LOG_HANDLER from hyperglass.constants import LOG_HANDLER_FILE from hyperglass.constants import LOG_LEVELS -from hyperglass.constants import Supported +from hyperglass.constants import SUPPORTED_QUERY_TYPES from hyperglass.exceptions import ConfigError from hyperglass.exceptions import ConfigInvalid from hyperglass.exceptions import ConfigMissing @@ -317,12 +318,12 @@ def _build_queries(): """Build a dict of supported query types and their display names. Returns: - {dict} -- Supported query dict + {list} -- Supported query list """ queries = [] - for query in Supported.query_types: - display_name = getattr(params.branding.text, query) - queries.append({"name": query, "display_name": display_name}) + for query in SUPPORTED_QUERY_TYPES: + query_params = getattr(params.features, query) + queries.append({"name": query, "display_name": query_params.display_name}) return queries @@ -341,15 +342,18 @@ def _build_vrf_help(): """ all_help = {} for vrf in devices.vrf_objects: + vrf_help = {} - for command in Supported.query_types: + for command in SUPPORTED_QUERY_TYPES: cmd = getattr(vrf.info, command) - help_params = content_params - if cmd.params.title is None: - cmd.params.title = ( - f"{vrf.display_name}: {getattr(params.branding.text, command)}" - ) - help_params.update(cmd.params.dict()) + help_params = {**content_params, **cmd.params.dict()} + + if help_params["title"] is None: + command_params = getattr(params.features, command) + help_params[ + "title" + ] = f"{vrf.display_name}: {command_params.display_name}" + md = asyncio.run( get_markdown( config_path=cmd, @@ -357,25 +361,35 @@ def _build_vrf_help(): params=help_params, ) ) + vrf_help.update( {command: {"content": md, "enable": cmd.enable, "params": help_params}} ) + all_help.update({vrf.name: vrf_help}) + return all_help content_vrf = _build_vrf_help() +content_help_params = copy.copy(content_params) +content_help_params["title"] = params.branding.help_menu.title content_help = asyncio.run( get_markdown( config_path=params.branding.help_menu, default=DEFAULT_HELP, - params=content_params, + params=content_help_params, ) ) + +content_terms_params = copy.copy(content_params) +content_terms_params["title"] = params.branding.terms.title content_terms = asyncio.run( get_markdown( - config_path=params.branding.terms, default=DEFAULT_TERMS, params=content_params + config_path=params.branding.terms, + default=DEFAULT_TERMS, + params=content_terms_params, ) ) content_credit = CREDIT @@ -393,15 +407,15 @@ _frontend_fields = { "org_name", "google_analytics", "opengraph", - "site_descriptin", + "site_description", }, "branding": ..., "features": { - "bgp_route": {"enable"}, - "bgp_community": {"enable"}, - "bgp_aspath": {"enable"}, - "ping": {"enable"}, - "traceroute": {"enable"}, + "bgp_route": {"enable", "display_name"}, + "bgp_community": {"enable", "display_name"}, + "bgp_aspath": {"enable", "display_name"}, + "ping": {"enable", "display_name"}, + "traceroute": {"enable", "display_name"}, }, "messages": ..., } diff --git a/hyperglass/configuration/models/branding.py b/hyperglass/configuration/models/branding.py index 498f1c3..915aef8 100644 --- a/hyperglass/configuration/models/branding.py +++ b/hyperglass/configuration/models/branding.py @@ -167,11 +167,6 @@ class Branding(HyperglassModel): terms: StrictStr = "Terms" info: StrictStr = "Help" peeringdb = "PeeringDB" - bgp_route: StrictStr = "BGP Route" - bgp_community: StrictStr = "BGP Community" - bgp_aspath: StrictStr = "BGP AS Path" - ping: StrictStr = "Ping" - traceroute: StrictStr = "Traceroute" class Error404(HyperglassModel): """Validation model for 404 Error Page.""" diff --git a/hyperglass/configuration/models/features.py b/hyperglass/configuration/models/features.py index 4f951e6..67dbe58 100644 --- a/hyperglass/configuration/models/features.py +++ b/hyperglass/configuration/models/features.py @@ -20,11 +20,13 @@ class Features(HyperglassModel): """Validation model for params.features.bgp_route.""" enable: StrictBool = True + display_name: StrictStr = "BGP Route" class BgpCommunity(HyperglassModel): """Validation model for params.features.bgp_community.""" enable: StrictBool = True + display_name: StrictStr = "BGP Community" class Regex(HyperglassModel): """Validation model for params.features.bgp_community.regex.""" @@ -39,6 +41,7 @@ class Features(HyperglassModel): """Validation model for params.features.bgp_aspath.""" enable: StrictBool = True + display_name: StrictStr = "BGP AS Path" class Regex(HyperglassModel): """Validation model for params.bgp_aspath.regex.""" @@ -55,11 +58,13 @@ class Features(HyperglassModel): """Validation model for params.features.ping.""" enable: StrictBool = True + display_name: StrictStr = "Ping" class Traceroute(HyperglassModel): """Validation model for params.features.traceroute.""" enable: StrictBool = True + display_name: StrictStr = "Traceroute" class Cache(HyperglassModel): """Validation model for params.features.cache.""" @@ -81,38 +86,6 @@ class Features(HyperglassModel): "Prefix length must be smaller than /{m}. {i} is too specific." ) - class RateLimit(HyperglassModel): - """Validation model for params.features.rate_limit.""" - - redis_id: StrictInt = 1 - - class Query(HyperglassModel): - """Validation model for params.features.rate_limit.query.""" - - rate: StrictInt = 5 - period: StrictStr = "minute" - title: StrictStr = "Query Limit Reached" - message: StrictStr = ( - "Query limit of {rate} per {period} reached. " - "Please wait one minute and try again." - ).format(rate=rate, period=period) - button: StrictStr = "Try Again" - - class Site(HyperglassModel): - """Validation model for params.features.rate_limit.site.""" - - rate: StrictInt = 60 - period: StrictStr = "minute" - title: StrictStr = "Limit Reached" - subtitle: StrictStr = ( - "You have accessed this site more than {rate} " - "times in the last {period}." - ).format(rate=rate, period=period) - button: StrictStr = "Try Again" - - query: Query = Query() - site: Site = Site() - bgp_route: BgpRoute = BgpRoute() bgp_community: BgpCommunity = BgpCommunity() bgp_aspath: BgpAsPath = BgpAsPath() @@ -120,4 +93,3 @@ class Features(HyperglassModel): traceroute: Traceroute = Traceroute() cache: Cache = Cache() max_prefix: MaxPrefix = MaxPrefix() - rate_limit: RateLimit = RateLimit() diff --git a/ui/components/Results.js b/ui/components/Results.js index 52a0994..ccfeb4e 100644 --- a/ui/components/Results.js +++ b/ui/components/Results.js @@ -76,7 +76,7 @@ const Results = ({ queryLocation, queryType, queryVrf, queryTarget, setSubmittin transition={{ duration: 0.3, delay: 0.3 }} exit={{ opacity: 0, x: -100 }} label={config.branding.text.query_type} - value={config.branding.text[queryType]} + value={config.features[queryType].display_name} valueBg={theme.colors.cyan[500]} fontSize={["xs", "sm", "sm", "sm"]} />