mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
use custom fork of sshtunnel; remove ujson
This commit is contained in:
@@ -7,7 +7,7 @@ from pathlib import Path
|
||||
# Third Party
|
||||
from fastapi import FastAPI
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
from starlette.responses import UJSONResponse
|
||||
from starlette.responses import JSONResponse
|
||||
from starlette.exceptions import HTTPException as StarletteHTTPException
|
||||
from fastapi.openapi.utils import get_openapi
|
||||
from starlette.staticfiles import StaticFiles
|
||||
@@ -71,7 +71,7 @@ app = FastAPI(
|
||||
title=params.site_title,
|
||||
description=params.site_description,
|
||||
version=__version__,
|
||||
default_response_class=UJSONResponse,
|
||||
default_response_class=JSONResponse,
|
||||
**DOCS_PARAMS,
|
||||
)
|
||||
|
||||
@@ -169,7 +169,7 @@ app.add_api_route(
|
||||
endpoint=routers,
|
||||
methods=["GET"],
|
||||
response_model=List[RoutersResponse],
|
||||
response_class=UJSONResponse,
|
||||
response_class=JSONResponse,
|
||||
summary=params.docs.devices.summary,
|
||||
description=params.docs.devices.description,
|
||||
tags=[params.docs.devices.title],
|
||||
@@ -178,7 +178,7 @@ app.add_api_route(
|
||||
path="/api/queries",
|
||||
endpoint=queries,
|
||||
methods=["GET"],
|
||||
response_class=UJSONResponse,
|
||||
response_class=JSONResponse,
|
||||
response_model=List[SupportedQueryResponse],
|
||||
summary=params.docs.queries.summary,
|
||||
description=params.docs.queries.description,
|
||||
@@ -197,7 +197,7 @@ app.add_api_route(
|
||||
},
|
||||
response_model=QueryResponse,
|
||||
tags=[params.docs.query.title],
|
||||
response_class=UJSONResponse,
|
||||
response_class=JSONResponse,
|
||||
)
|
||||
|
||||
# Enable certificate import route only if a device using
|
||||
|
@@ -1,7 +1,7 @@
|
||||
"""API Error Handlers."""
|
||||
|
||||
# Third Party
|
||||
from starlette.responses import UJSONResponse
|
||||
from starlette.responses import JSONResponse
|
||||
|
||||
# Project
|
||||
from hyperglass.configuration import params
|
||||
@@ -9,7 +9,7 @@ from hyperglass.configuration import params
|
||||
|
||||
async def default_handler(request, exc):
|
||||
"""Handle uncaught errors."""
|
||||
return UJSONResponse(
|
||||
return JSONResponse(
|
||||
{"output": params.messages.general, "level": "danger", "keywords": []},
|
||||
status_code=500,
|
||||
)
|
||||
@@ -17,7 +17,7 @@ async def default_handler(request, exc):
|
||||
|
||||
async def http_handler(request, exc):
|
||||
"""Handle web server errors."""
|
||||
return UJSONResponse(
|
||||
return JSONResponse(
|
||||
{"output": exc.detail, "level": "danger", "keywords": []},
|
||||
status_code=exc.status_code,
|
||||
)
|
||||
@@ -25,7 +25,7 @@ async def http_handler(request, exc):
|
||||
|
||||
async def app_handler(request, exc):
|
||||
"""Handle application errors."""
|
||||
return UJSONResponse(
|
||||
return JSONResponse(
|
||||
{"output": exc.message, "level": exc.level, "keywords": exc.keywords},
|
||||
status_code=exc.status_code,
|
||||
)
|
||||
@@ -34,7 +34,7 @@ async def app_handler(request, exc):
|
||||
async def validation_handler(request, exc):
|
||||
"""Handle Pydantic validation errors raised by FastAPI."""
|
||||
error = exc.errors()[0]
|
||||
return UJSONResponse(
|
||||
return JSONResponse(
|
||||
{"output": error["msg"], "level": "error", "keywords": error["loc"]},
|
||||
status_code=422,
|
||||
)
|
||||
|
@@ -8,7 +8,6 @@ from typing import List, Union, Optional
|
||||
from datetime import datetime
|
||||
|
||||
# Third Party
|
||||
import ujson
|
||||
from pydantic import BaseModel, StrictInt, StrictStr, StrictFloat, constr, validator
|
||||
|
||||
|
||||
@@ -27,8 +26,6 @@ GET /.well-known/looking-glass/v1/cmd
|
||||
|
||||
class _HyperglassQuery(BaseModel):
|
||||
class Config:
|
||||
json_loads = ujson.loads
|
||||
json_dumps = ujson.dumps
|
||||
validate_all = True
|
||||
validate_assignment = True
|
||||
|
||||
|
@@ -179,7 +179,7 @@ def validate_aspath(value):
|
||||
mode = params.queries.bgp_aspath.pattern.mode
|
||||
pattern = getattr(params.queries.bgp_aspath.pattern, mode)
|
||||
|
||||
if not re.match(pattern, value):
|
||||
if not bool(re.match(pattern, value)):
|
||||
raise InputInvalid(
|
||||
params.messages.invalid_input,
|
||||
target=value,
|
||||
|
1
hyperglass/compat/__init__.py
Normal file
1
hyperglass/compat/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Functions for maintaining compatability with older Python versions or libraries."""
|
@@ -1,4 +1,4 @@
|
||||
"""Functions for maintaining compatability with older Python versions."""
|
||||
"""Functions for maintaining asyncio compatability with other versions of Python."""
|
||||
|
||||
# Standard Library
|
||||
import sys
|
1624
hyperglass/compat/_sshtunnel.py
Normal file
1624
hyperglass/compat/_sshtunnel.py
Normal file
File diff suppressed because it is too large
Load Diff
@@ -3,18 +3,17 @@
|
||||
# Standard Library
|
||||
import os
|
||||
import copy
|
||||
import json
|
||||
import math
|
||||
from pathlib import Path
|
||||
|
||||
# Third Party
|
||||
import yaml
|
||||
import ujson as json
|
||||
from aiofile import AIOFile
|
||||
from pydantic import ValidationError
|
||||
|
||||
# Project
|
||||
from hyperglass.util import log, check_path, set_app_path
|
||||
from hyperglass.compat import aiorun
|
||||
from hyperglass.constants import (
|
||||
CREDIT,
|
||||
LOG_LEVELS,
|
||||
@@ -27,6 +26,7 @@ from hyperglass.constants import (
|
||||
__version__,
|
||||
)
|
||||
from hyperglass.exceptions import ConfigError, ConfigInvalid, ConfigMissing
|
||||
from hyperglass.compat._asyncio import aiorun
|
||||
from hyperglass.configuration.models import params as _params
|
||||
from hyperglass.configuration.models import routers as _routers
|
||||
from hyperglass.configuration.models import commands as _commands
|
||||
@@ -100,6 +100,7 @@ def _set_log_level(debug, log_file=None):
|
||||
log_level = "DEBUG"
|
||||
stdout_handler["level"] = log_level
|
||||
file_handler["level"] = log_level
|
||||
os.environ["HYPERGLASS_LOG_LEVEL"] = log_level
|
||||
|
||||
if log_file is not None:
|
||||
file_handler.update({"sink": log_file})
|
||||
|
@@ -1,7 +1,7 @@
|
||||
"""Custom exceptions for hyperglass."""
|
||||
|
||||
# Third Party
|
||||
import ujson as _json
|
||||
# Standard Library
|
||||
import json as _json
|
||||
|
||||
# Project
|
||||
from hyperglass.util import log
|
||||
|
@@ -150,7 +150,7 @@ async def write_env(variables):
|
||||
RuntimeError: Raised on any errors.
|
||||
"""
|
||||
from aiofile import AIOFile
|
||||
import ujson as json
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
env_file = Path("/tmp/hyperglass.env.json") # noqa: S108
|
||||
@@ -390,14 +390,14 @@ async def read_package_json():
|
||||
{dict} -- NPM package.json as dict
|
||||
"""
|
||||
from pathlib import Path
|
||||
import ujson
|
||||
import json
|
||||
|
||||
package_json_file = Path(__file__).parent / "ui" / "package.json"
|
||||
|
||||
try:
|
||||
|
||||
with package_json_file.open("r") as file:
|
||||
package_json = ujson.load(file)
|
||||
package_json = json.load(file)
|
||||
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Error reading package.json: {str(e)}")
|
||||
|
Reference in New Issue
Block a user