forked from mirrors/thatmattlove-hyperglass
add /api/info route, fix api docs logo
This commit is contained in:
parent
76b42e6b63
commit
24cb5ab9a7
4 changed files with 58 additions and 4 deletions
|
|
@ -20,6 +20,7 @@ from hyperglass.constants import TRANSPORT_REST, __version__
|
|||
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.error_handlers import (
|
|||
)
|
||||
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 @@ app.add_middleware(
|
|||
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,
|
||||
|
|
|
|||
|
|
@ -180,7 +180,6 @@ class RoutersResponse(BaseModel):
|
|||
|
||||
name: StrictStr
|
||||
network: Network
|
||||
location: StrictStr
|
||||
display_name: StrictStr
|
||||
vrfs: List[Vrf]
|
||||
|
||||
|
|
@ -225,3 +224,28 @@ class SupportedQueryResponse(BaseModel):
|
|||
{"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",
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ from hyperglass.util import clean_name, process_headers, import_public_key
|
|||
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]
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue