1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 11:18:11 +00:00

Symbols endpoints (except upload) don't require authentication.

This commit is contained in:
grossmj 2021-06-16 20:22:49 +09:30
parent 91a6384a59
commit 1f0ceb6f74
2 changed files with 20 additions and 15 deletions

View File

@ -95,7 +95,6 @@ router.include_router(
router.include_router(
symbols.router,
dependencies=[Depends(get_current_active_user)],
prefix="/symbols", tags=["Symbols"]
)

View File

@ -21,7 +21,7 @@ API routes for symbols.
import os
from fastapi import APIRouter, Request, status
from fastapi import APIRouter, Request, Depends, status
from fastapi.responses import FileResponse
from typing import List
@ -29,6 +29,8 @@ from gns3server.controller import Controller
from gns3server import schemas
from gns3server.controller.controller_error import ControllerError, ControllerNotFoundError
from .dependencies.authentication import get_current_active_user
import logging
log = logging.getLogger(__name__)
@ -57,7 +59,7 @@ async def get_symbol(symbol_id: str) -> FileResponse:
symbol = controller.symbols.get_path(symbol_id)
return FileResponse(symbol)
except (KeyError, OSError) as e:
return ControllerNotFoundError(f"Could not get symbol file: {e}")
raise ControllerNotFoundError(f"Could not get symbol file: {e}")
@router.get(
@ -75,10 +77,24 @@ async def get_symbol_dimensions(symbol_id: str) -> dict:
symbol_dimensions = {"width": width, "height": height}
return symbol_dimensions
except (KeyError, OSError, ValueError) as e:
return ControllerNotFoundError(f"Could not get symbol file: {e}")
raise ControllerNotFoundError(f"Could not get symbol file: {e}")
@router.post("/{symbol_id:path}/raw", status_code=status.HTTP_204_NO_CONTENT)
@router.get("/default_symbols")
def get_default_symbols() -> dict:
"""
Return all default symbols.
"""
controller = Controller.instance()
return controller.symbols.default_symbols()
@router.post(
"/{symbol_id:path}/raw",
dependencies=[Depends(get_current_active_user)],
status_code=status.HTTP_204_NO_CONTENT
)
async def upload_symbol(symbol_id: str, request: Request) -> None:
"""
Upload a symbol file.
@ -95,13 +111,3 @@ async def upload_symbol(symbol_id: str, request: Request) -> None:
# Reset the symbol list
controller.symbols.list()
@router.get("/default_symbols")
def get_default_symbols() -> dict:
"""
Return all default symbols.
"""
controller = Controller.instance()
return controller.symbols.default_symbols()