Feature/subscription table #2

Merged
florian merged 7 commits from feature/subscription-table into main 2026-11-04 17:44:50 +00:00
2 changed files with 35 additions and 2 deletions
Showing only changes of commit f64f613ab4 - Show all commits

No files matched your search

+2
View File
@@ -6,8 +6,10 @@ from service_auth import KeySource, ServiceAuth
class Caller(StrEnum): class Caller(StrEnum):
GATEWAY = "gateway" GATEWAY = "gateway"
SCHEDULER = "scheduler" SCHEDULER = "scheduler"
ADMIN = "admin"
auth = ServiceAuth({ auth = ServiceAuth({
Caller.GATEWAY: KeySource("GATEWAY_KEY", "/etc/secrets/gateway_key"), Caller.GATEWAY: KeySource("GATEWAY_KEY", "/etc/secrets/gateway_key"),
Caller.SCHEDULER: KeySource("SCHEDULER_KEY", "/etc/secrets/scheduler_key"), Caller.SCHEDULER: KeySource("SCHEDULER_KEY", "/etc/secrets/scheduler_key"),
Caller.ADMIN: KeySource("ADMIN_KEY","/etc/secrets/admin_key")
}) })
+33 -2
View File
@@ -62,6 +62,7 @@ api = FastAPI(
register_handlers(api) register_handlers(api)
user_router = APIRouter(dependencies=[Depends(auth.require(Caller.GATEWAY))]) user_router = APIRouter(dependencies=[Depends(auth.require(Caller.GATEWAY))])
scheduler_router = APIRouter(dependencies=[Depends(auth.require(Caller.SCHEDULER))]) scheduler_router = APIRouter(dependencies=[Depends(auth.require(Caller.SCHEDULER))])
admin_router = APIRouter(dependencies=[Depends(auth.require(Caller.ADMIN))])
def to_iso(dt: datetime) -> str: def to_iso(dt: datetime) -> str:
return dt.astimezone(UTC).isoformat(timespec="microseconds") return dt.astimezone(UTC).isoformat(timespec="microseconds")
@@ -315,15 +316,45 @@ def list_active_and_inactive_anime(
return anime_list return anime_list
@admin_router.post("/admin/update/names")
def update_all_names_to_most_recently_available(db=Depends(get_db)):
logger.info("[FastAPI] ADMIN: Got request to update all existing names")
try:
with db.cursor() as cursor:
cursor.execute(
"SELECT id, anilist_id from seadex_state"
)
rows = cursor.fetchall()
for id, anilist_id in rows:
anime_name = get_anime_name(anilist_id)
cursor.execute(
"UPDATE seadex_state SET anime_name = %s "
"WHERE id = %s",
(anime_name,id),
)
db.commit()
logger.info(
"[FastAPI] ADMIN: Updated id=%s, anilist_id=%s with name=%s",
id, anilist_id, anime_name,
)
except Exception as e:
db.rollback()
logger.exception("[FastAPI] ADMIN: Failed to update all existing names")
raise HTTPException(status_code=500) from e
logger.info("[FastAPI] ADMIN: Updated %s entries", len(rows))
return {"status": "ok", "detail": f"Updated {len(rows)} entries"}
api.include_router(user_router) api.include_router(user_router)
api.include_router(scheduler_router) api.include_router(scheduler_router)
api.include_router(admin_router)
async def start_servers(): async def start_servers():
logger.info("[Server] Starting main API (port 5000) and metrics server (port 9000)...") logger.info("[Server] Starting main API (port 5000) and metrics server (port 9000)...")
logger.info("[Server] Build commit id=%s", os.getenv("COMMIT_ID", "unknown")) logger.info("[Server] Build commit id=%s", os.getenv("COMMIT_ID", "unknown"))
auth.load_keys(api, Caller.GATEWAY, Caller.SCHEDULER) auth.load_keys(api, Caller.GATEWAY, Caller.SCHEDULER, Caller.ADMIN)
cleanup_secret_files(auth.key_paths(Caller.GATEWAY, Caller.SCHEDULER)) cleanup_secret_files(auth.key_paths(Caller.GATEWAY, Caller.SCHEDULER, Caller.ADMIN))
config_main = uvicorn.Config(api, host="0.0.0.0", port=5000, log_level=LOG_LEVEL.lower(),log_config=None) config_main = uvicorn.Config(api, host="0.0.0.0", port=5000, log_level=LOG_LEVEL.lower(),log_config=None)
config_metrics = uvicorn.Config(metrics_api, host="0.0.0.0", port=9000, log_level=LOG_LEVEL.lower(),log_config=None) config_metrics = uvicorn.Config(metrics_api, host="0.0.0.0", port=9000, log_level=LOG_LEVEL.lower(),log_config=None)