feat: Guests API keys. Closes #3
This commit is contained in:
11
main.py
11
main.py
@@ -2,7 +2,7 @@ import logging
|
||||
import asyncio
|
||||
import os
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, Depends
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from app.core.database import init_db, async_session
|
||||
@@ -10,7 +10,8 @@ from app.core.scheduler import start_scheduler
|
||||
from app.core.state import state_manager, discovery_service
|
||||
from sqlalchemy import select
|
||||
from app.models.device import GroupModel
|
||||
from app.api.routes import devices, control, schedules
|
||||
from app.api.routes import devices, control, schedules, api_keys
|
||||
from app.api.deps import verify_token
|
||||
|
||||
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO").upper()
|
||||
|
||||
@@ -48,6 +49,7 @@ app = FastAPI(title="Ignis Core API", lifespan=lifespan)
|
||||
app.include_router(devices.router, prefix="/devices", tags=["Devices & Groups"])
|
||||
app.include_router(control.router, prefix="/control", tags=["Control"])
|
||||
app.include_router(schedules.router, prefix="/schedules", tags=["Schedules"])
|
||||
app.include_router(api_keys.router, prefix="/api-keys", tags=["API Keys"])
|
||||
|
||||
# Статика
|
||||
# Мы убираем html=True из корня, чтобы 404-е ошибки API не превращались в загрузку index.html
|
||||
@@ -61,6 +63,11 @@ async def read_index():
|
||||
return FileResponse("static/index.html")
|
||||
|
||||
|
||||
@app.get("/auth/me")
|
||||
async def auth_me(auth = Depends(verify_token)):
|
||||
return {"is_admin": auth.is_admin, "name": auth.key_name}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
|
||||
Reference in New Issue
Block a user