Add Gitea repo sync for credentials (admtracksteel/Keys)
This commit is contained in:
33
main.py
33
main.py
@@ -12,7 +12,7 @@ import audio_handler
|
||||
|
||||
from ai_agent import query_agent
|
||||
from config import get_config, save_config
|
||||
from credential_manager import sync_credentials
|
||||
from credential_manager import sync_credentials, sync_from_gitea_repo
|
||||
|
||||
# Carrega as variáveis do .env
|
||||
load_dotenv()
|
||||
@@ -25,17 +25,20 @@ templates = Jinja2Templates(directory="templates")
|
||||
# ============================================================
|
||||
# AUTO-SYNC DE CREDENCIAIS NO STARTUP
|
||||
# ============================================================
|
||||
print("[INIT] Sincronizando credenciais...")
|
||||
print("[INIT] Sincronizando credenciais do repo Gitea...")
|
||||
sync_result = sync_from_gitea_repo()
|
||||
print(f"[INIT] Repo Gitea: {sync_result['status']} ({sync_result['services_count']} serviços)")
|
||||
print("[INIT] Sincronizando fallback local...")
|
||||
sync_result = sync_credentials()
|
||||
print(f"[INIT] Credenciais sincronizadas: {sync_result['status']}")
|
||||
print(f"[INIT] Services: {', '.join(sync_result['services'].keys())}")
|
||||
print(f"[INIT] Local: {sync_result['status']}")
|
||||
|
||||
# ============================================================
|
||||
# EVENTO DE STARTUP
|
||||
# ============================================================
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
print("[STARTUP] Sincronizando credenciais...")
|
||||
print("[STARTUP] Sincronizando credenciais do repo Gitea...")
|
||||
sync_from_gitea_repo()
|
||||
sync_credentials()
|
||||
print("[STARTUP] Credenciais sincronizadas com sucesso!")
|
||||
|
||||
@@ -298,10 +301,28 @@ async def list_llm_models(is_auth: bool = Depends(verify_password)):
|
||||
|
||||
@app.post("/api/sync-credentials")
|
||||
async def sync_creds(is_auth: bool = Depends(verify_password)):
|
||||
"""Força sincronização de credenciais."""
|
||||
"""Força sincronização de credenciais (fallback local)."""
|
||||
result = sync_credentials()
|
||||
return JSONResponse(content=result)
|
||||
|
||||
@app.post("/api/sync-from-repo")
|
||||
async def sync_from_repo(is_auth: bool = Depends(verify_password)):
|
||||
"""Força sincronização do repo Gitea admtracksteel/Keys."""
|
||||
from credential_manager import get_gitea_repo_credentials
|
||||
result = sync_from_gitea_repo(force=True)
|
||||
return JSONResponse(content=result)
|
||||
|
||||
@app.get("/api/credentials-repo")
|
||||
async def get_repo_credentials(is_auth: bool = Depends(verify_password)):
|
||||
"""Retorna credenciais do repo Gitea."""
|
||||
from credential_manager import get_gitea_repo_credentials
|
||||
creds = get_gitea_repo_credentials()
|
||||
return JSONResponse(content={
|
||||
"repo": "admtracksteel/Keys",
|
||||
"services": creds,
|
||||
"count": len(creds)
|
||||
})
|
||||
|
||||
@app.get("/api/tools")
|
||||
async def list_tools(is_auth: bool = Depends(verify_password)):
|
||||
"""Lista todas as ferramentas disponíveis."""
|
||||
|
||||
Reference in New Issue
Block a user