diff --git a/hyperglass/api/__init__.py b/hyperglass/api/__init__.py index 65e145b0..e0b52b77 100644 --- a/hyperglass/api/__init__.py +++ b/hyperglass/api/__init__.py @@ -20,6 +20,7 @@ from hyperglass.api.events import on_startup, on_shutdown from hyperglass.api.routes import ( docs, + info, query, queries, routers, @@ -36,6 +37,7 @@ ) from hyperglass.api.models.response import ( QueryError, + InfoResponse, QueryResponse, RoutersResponse, CommunityResponse, @@ -116,7 +118,9 @@ def _custom_openapi(): description=params.docs.description, routes=app.routes, ) - openapi_schema["info"]["x-logo"] = {"url": "/" + str(params.web.logo.dark)} + openapi_schema["info"]["x-logo"] = { + "url": "/images/light" + params.web.logo.light.suffix + } query_samples = [] queries_samples = [] @@ -177,6 +181,17 @@ def _custom_openapi(): allow_headers=["*"], ) +app.add_api_route( + path="/api/info", + endpoint=info, + methods=["GET"], + response_model=InfoResponse, + response_class=JSONResponse, + summary=params.docs.info.summary, + description=params.docs.info.description, + tags=[params.docs.info.title], +) + app.add_api_route( path="/api/devices", endpoint=routers, diff --git a/hyperglass/api/models/response.py b/hyperglass/api/models/response.py index 5f34677b..77e4a178 100644 --- a/hyperglass/api/models/response.py +++ b/hyperglass/api/models/response.py @@ -180,7 +180,6 @@ class RoutersResponse(BaseModel): name: StrictStr network: Network - location: StrictStr display_name: StrictStr vrfs: List[Vrf] @@ -225,3 +224,28 @@ class Config: {"name": "bgp_route", "display_name": "BGP Route", "enable": True} ] } + + +class InfoResponse(BaseModel): + """Response model for /api/info endpoint.""" + + name: StrictStr + organization: StrictStr + primary_asn: StrictInt + version: StrictStr + + class Config: + """Pydantic model configuration.""" + + title = "System Information" + description = "General information about this looking glass." + schema_extra = { + "examples": [ + { + "name": "hyperglass", + "organization": "Company Name", + "primary_asn": 65000, + "version": "hyperglass 1.0.0-beta.52", + } + ] + } diff --git a/hyperglass/api/routes.py b/hyperglass/api/routes.py index cf753165..304953f4 100644 --- a/hyperglass/api/routes.py +++ b/hyperglass/api/routes.py @@ -17,6 +17,7 @@ from hyperglass.cache import AsyncCache from hyperglass.encode import jwt_decode from hyperglass.external import Webhook, bgptools +from hyperglass.constants import __version__ from hyperglass.exceptions import HyperglassError from hyperglass.configuration import REDIS_CONFIG, params, devices from hyperglass.api.models.query import Query @@ -211,7 +212,6 @@ async def routers(): include={ "name": ..., "network": ..., - "location": ..., "display_name": ..., "vrfs": {-1: {"name", "display_name"}}, } @@ -233,4 +233,14 @@ async def queries(): return params.queries.list -endpoints = [query, docs, routers] +async def info(): + """Serve general information about this instance of hyperglass.""" + return { + "name": params.site_title, + "organization": params.org_name, + "primary_asn": int(params.primary_asn), + "version": f"hyperglass {__version__}", + } + + +endpoints = [query, docs, routers, info] diff --git a/hyperglass/configuration/models/docs.py b/hyperglass/configuration/models/docs.py index 0abcd9a3..b9f0dfb2 100644 --- a/hyperglass/configuration/models/docs.py +++ b/hyperglass/configuration/models/docs.py @@ -84,6 +84,11 @@ class Docs(HyperglassModel): description="List of BGP communities.", summary="BGP Communities List", ) + info: EndpointConfig = EndpointConfig( + title="System Information", + description="General information about this looking glass.", + summary="System Information", + ) class Config: """Pydantic model configuration."""