All checks were successful
Deploy Dev / Build (pull_request) Successful in 6s
Deploy Dev / Push (pull_request) Successful in 8s
Deploy Dev / Deploy dev (pull_request) Successful in 8s
Deploy Prod / Build (pull_request) Successful in 5s
Deploy Prod / Push (pull_request) Successful in 7s
Deploy Prod / Deploy prod (pull_request) Successful in 7s
61 lines
1.5 KiB
Python
61 lines
1.5 KiB
Python
import bson
|
|
import fastapi
|
|
import pydantic
|
|
|
|
from app.storage.mongo import configs
|
|
|
|
|
|
class RequestPostBody(pydantic.BaseModel):
|
|
name: str
|
|
stage: str
|
|
project: str
|
|
|
|
|
|
class RequestPutBody(pydantic.BaseModel):
|
|
id: str
|
|
value: dict|list
|
|
|
|
|
|
class RequestDeleteBody(pydantic.BaseModel):
|
|
id: str
|
|
|
|
|
|
class Config(pydantic.BaseModel):
|
|
id: str
|
|
name: str
|
|
value: dict|list
|
|
|
|
|
|
router = fastapi.APIRouter()
|
|
|
|
|
|
@router.post('/api/v1/configs', status_code=fastapi.status.HTTP_202_ACCEPTED)
|
|
async def post(body: RequestPostBody):
|
|
await configs.create(configs.Config(name=body.name, project=body.project, stage=body.stage, value={}))
|
|
|
|
|
|
@router.put('/api/v1/configs', status_code=fastapi.status.HTTP_202_ACCEPTED, responses={404: {'description': 'Not found'}})
|
|
async def put(body: RequestPutBody):
|
|
changed = await configs.update_data(id=bson.ObjectId(body.id), value=body.value)
|
|
if not changed:
|
|
raise fastapi.HTTPException(404)
|
|
|
|
|
|
@router.delete('/api/v1/configs', status_code=fastapi.status.HTTP_202_ACCEPTED, responses={404: {'description': 'Not found'}})
|
|
async def delete(body: RequestDeleteBody):
|
|
changed = await configs.delete(id=bson.ObjectId(body.id))
|
|
if not changed:
|
|
raise fastapi.HTTPException(404)
|
|
|
|
|
|
@router.get('/api/v1/configs')
|
|
async def get(stage: str, project: str) -> list[Config]:
|
|
return [
|
|
Config(
|
|
id=str(config._id),
|
|
name=config.name,
|
|
value=config.value,
|
|
)
|
|
for config in await configs.get(project=project, stage=stage)
|
|
]
|