This commit is contained in:
parent
fb1376b23d
commit
f0bc59a1a2
@ -1,4 +1,5 @@
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.routing import APIRoute
|
from fastapi.routing import APIRoute
|
||||||
|
|
||||||
from .routers import health, machines, root
|
from .routers import health, machines, root
|
||||||
@ -9,6 +10,14 @@ def setup_app() -> FastAPI:
|
|||||||
app.include_router(health.router)
|
app.include_router(health.router)
|
||||||
app.include_router(machines.router)
|
app.include_router(machines.router)
|
||||||
app.include_router(root.router)
|
app.include_router(root.router)
|
||||||
|
# TODO make this configurable
|
||||||
|
app.add_middleware(
|
||||||
|
CORSMiddleware,
|
||||||
|
allow_origins="http://localhost:3000",
|
||||||
|
allow_credentials=True,
|
||||||
|
allow_methods=["*"],
|
||||||
|
allow_headers=["*"],
|
||||||
|
)
|
||||||
|
|
||||||
for route in app.routes:
|
for route in app.routes:
|
||||||
if isinstance(route, APIRoute):
|
if isinstance(route, APIRoute):
|
||||||
|
@ -1,54 +1,24 @@
|
|||||||
from enum import Enum
|
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
|
|
||||||
from fastapi import APIRouter, Body
|
from fastapi import APIRouter, Body
|
||||||
from pydantic import BaseModel, Field
|
|
||||||
|
|
||||||
from ...machines.create import create_machine as _create_machine
|
from ...machines.create import create_machine as _create_machine
|
||||||
from ...machines.list import list_machines as _list_machines
|
from ...machines.list import list_machines as _list_machines
|
||||||
|
from ..schemas import (
|
||||||
|
Config,
|
||||||
|
ConfigResponse,
|
||||||
|
Machine,
|
||||||
|
MachineCreate,
|
||||||
|
MachineResponse,
|
||||||
|
MachinesResponse,
|
||||||
|
Schema,
|
||||||
|
SchemaResponse,
|
||||||
|
Status,
|
||||||
|
)
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
class Status(Enum):
|
|
||||||
ONLINE = "online"
|
|
||||||
OFFLINE = "offline"
|
|
||||||
UNKNOWN = "unknown"
|
|
||||||
|
|
||||||
|
|
||||||
class Machine(BaseModel):
|
|
||||||
name: str
|
|
||||||
status: Status
|
|
||||||
|
|
||||||
|
|
||||||
class MachineCreate(BaseModel):
|
|
||||||
name: str
|
|
||||||
|
|
||||||
|
|
||||||
class MachinesResponse(BaseModel):
|
|
||||||
machines: list[Machine]
|
|
||||||
|
|
||||||
|
|
||||||
class MachineResponse(BaseModel):
|
|
||||||
machine: Machine
|
|
||||||
|
|
||||||
|
|
||||||
class Config(BaseModel):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigResponse(BaseModel):
|
|
||||||
config: Config
|
|
||||||
|
|
||||||
|
|
||||||
class Schema(BaseModel):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class SchemaResponse(BaseModel):
|
|
||||||
schema_: Schema = Field(alias="schema")
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/machines")
|
@router.get("/api/machines")
|
||||||
async def list_machines() -> MachinesResponse:
|
async def list_machines() -> MachinesResponse:
|
||||||
machines = []
|
machines = []
|
||||||
|
42
pkgs/clan-cli/clan_cli/webui/schemas.py
Normal file
42
pkgs/clan-cli/clan_cli/webui/schemas.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
|
||||||
|
class Status(Enum):
|
||||||
|
ONLINE = "online"
|
||||||
|
OFFLINE = "offline"
|
||||||
|
UNKNOWN = "unknown"
|
||||||
|
|
||||||
|
|
||||||
|
class Machine(BaseModel):
|
||||||
|
name: str
|
||||||
|
status: Status
|
||||||
|
|
||||||
|
|
||||||
|
class MachineCreate(BaseModel):
|
||||||
|
name: str
|
||||||
|
|
||||||
|
|
||||||
|
class MachinesResponse(BaseModel):
|
||||||
|
machines: list[Machine]
|
||||||
|
|
||||||
|
|
||||||
|
class MachineResponse(BaseModel):
|
||||||
|
machine: Machine
|
||||||
|
|
||||||
|
|
||||||
|
class Config(BaseModel):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigResponse(BaseModel):
|
||||||
|
config: Config
|
||||||
|
|
||||||
|
|
||||||
|
class Schema(BaseModel):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class SchemaResponse(BaseModel):
|
||||||
|
schema_: Schema = Field(alias="schema")
|
Loading…
Reference in New Issue
Block a user