➕ api: admin/credentials: only allow certain "name" values
This commit is contained in:
parent
049ae8fc56
commit
1ca9a2083e
1 changed files with 11 additions and 5 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from advent22_api.core.helpers import EventDates
|
from advent22_api.core.helpers import EventDates
|
||||||
|
|
@ -173,16 +174,21 @@ async def put_doors(
|
||||||
await cal_cfg.change(cfg)
|
await cal_cfg.change(cfg)
|
||||||
|
|
||||||
|
|
||||||
|
class CredentialsName(str, Enum):
|
||||||
|
DAV = "dav"
|
||||||
|
UI = "ui"
|
||||||
|
|
||||||
|
|
||||||
@router.get("/credentials/{name}")
|
@router.get("/credentials/{name}")
|
||||||
async def get_credentials(
|
async def get_credentials(
|
||||||
name: str,
|
name: CredentialsName,
|
||||||
_: None = Depends(require_admin),
|
_: None = Depends(require_admin),
|
||||||
cfg: Config = Depends(get_config),
|
cfg: Config = Depends(get_config),
|
||||||
) -> Credentials:
|
) -> Credentials:
|
||||||
|
|
||||||
if name == "dav":
|
if name == CredentialsName.DAV:
|
||||||
return SETTINGS.webdav.auth
|
return SETTINGS.webdav.auth
|
||||||
elif name == "ui":
|
elif name == CredentialsName.UI:
|
||||||
return cfg.admin
|
return cfg.admin
|
||||||
else:
|
else:
|
||||||
return Credentials()
|
raise HTTPException(status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue