mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-04-28 19:50:34 +00:00
chore: fix pre commit format and pipeline issue (#1144)
This commit is contained in:
parent
2256497dff
commit
893f51fc82
970 changed files with 11235 additions and 9533 deletions
|
|
@ -12,15 +12,22 @@
|
|||
# limitations under the License.
|
||||
# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
|
||||
|
||||
from typing import List, Optional
|
||||
from fastapi import Depends, HTTPException, Query, Response, APIRouter
|
||||
from sqlmodel import Session, select, or_
|
||||
from app.component.database import session
|
||||
from app.component.auth import Auth, auth_must
|
||||
from fastapi_babel import _
|
||||
from app.model.config.config import Config, ConfigCreate, ConfigUpdate, ConfigInfo, ConfigOut
|
||||
import logging
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Response
|
||||
from fastapi_babel import _
|
||||
from sqlmodel import Session, select
|
||||
|
||||
from app.component.auth import Auth, auth_must
|
||||
from app.component.database import session
|
||||
from app.model.config.config import (
|
||||
Config,
|
||||
ConfigCreate,
|
||||
ConfigInfo,
|
||||
ConfigOut,
|
||||
ConfigUpdate,
|
||||
)
|
||||
|
||||
logger = logging.getLogger("server_config_controller")
|
||||
|
||||
router = APIRouter(tags=["Config Management"])
|
||||
|
|
@ -28,15 +35,15 @@ router = APIRouter(tags=["Config Management"])
|
|||
|
||||
@router.get("/configs", name="list configs", response_model=list[ConfigOut])
|
||||
async def list_configs(
|
||||
config_group: Optional[str] = None, session: Session = Depends(session), auth: Auth = Depends(auth_must)
|
||||
config_group: str | None = None, session: Session = Depends(session), auth: Auth = Depends(auth_must)
|
||||
):
|
||||
"""List user's configurations with optional group filtering."""
|
||||
user_id = auth.user.id
|
||||
query = select(Config).where(Config.user_id == user_id)
|
||||
|
||||
|
||||
if config_group is not None:
|
||||
query = query.where(Config.config_group == config_group)
|
||||
|
||||
|
||||
configs = session.exec(query).all()
|
||||
logger.debug("Configs listed", extra={"user_id": user_id, "config_group": config_group, "count": len(configs)})
|
||||
return configs
|
||||
|
|
@ -58,7 +65,7 @@ async def get_config(
|
|||
if not config:
|
||||
logger.warning("Config not found")
|
||||
raise HTTPException(status_code=404, detail=_("Configuration not found"))
|
||||
|
||||
|
||||
logger.debug("Config retrieved")
|
||||
return config
|
||||
|
||||
|
|
@ -67,9 +74,12 @@ async def get_config(
|
|||
async def create_config(config: ConfigCreate, session: Session = Depends(session), auth: Auth = Depends(auth_must)):
|
||||
"""Create new configuration."""
|
||||
user_id = auth.user.id
|
||||
|
||||
|
||||
if not ConfigInfo.is_valid_env_var(config.config_group, config.config_name):
|
||||
logger.warning("Config validation failed", extra={"user_id": user_id, "config_group": config.config_group, "config_name": config.config_name})
|
||||
logger.warning(
|
||||
"Config validation failed",
|
||||
extra={"user_id": user_id, "config_group": config.config_group, "config_name": config.config_name},
|
||||
)
|
||||
raise HTTPException(status_code=400, detail=_("Invalid config name or group"))
|
||||
|
||||
# Check if configuration already exists
|
||||
|
|
@ -78,7 +88,9 @@ async def create_config(config: ConfigCreate, session: Session = Depends(session
|
|||
).first()
|
||||
|
||||
if existing_config:
|
||||
logger.warning("Config creation failed: already exists", extra={"user_id": user_id, "config_name": config.config_name})
|
||||
logger.warning(
|
||||
"Config creation failed: already exists", extra={"user_id": user_id, "config_name": config.config_name}
|
||||
)
|
||||
raise HTTPException(status_code=400, detail=_("Configuration already exists for this user"))
|
||||
|
||||
try:
|
||||
|
|
@ -91,11 +103,23 @@ async def create_config(config: ConfigCreate, session: Session = Depends(session
|
|||
session.add(db_config)
|
||||
session.commit()
|
||||
session.refresh(db_config)
|
||||
logger.info("Config created", extra={"user_id": user_id, "config_id": db_config.id, "config_group": config.config_group, "config_name": config.config_name})
|
||||
logger.info(
|
||||
"Config created",
|
||||
extra={
|
||||
"user_id": user_id,
|
||||
"config_id": db_config.id,
|
||||
"config_group": config.config_group,
|
||||
"config_name": config.config_name,
|
||||
},
|
||||
)
|
||||
return db_config
|
||||
except Exception as e:
|
||||
session.rollback()
|
||||
logger.error("Config creation failed", extra={"user_id": user_id, "config_name": config.config_name, "error": str(e)}, exc_info=True)
|
||||
logger.error(
|
||||
"Config creation failed",
|
||||
extra={"user_id": user_id, "config_name": config.config_name, "error": str(e)},
|
||||
exc_info=True,
|
||||
)
|
||||
raise HTTPException(status_code=500, detail="Internal server error")
|
||||
|
||||
|
||||
|
|
@ -113,7 +137,10 @@ async def update_config(
|
|||
|
||||
# Check if configuration group is valid
|
||||
if not ConfigInfo.is_valid_env_var(config_update.config_group, config_update.config_name):
|
||||
logger.warning("Config update validation failed", extra={"user_id": user_id, "config_id": config_id, "config_group": config_update.config_group})
|
||||
logger.warning(
|
||||
"Config update validation failed",
|
||||
extra={"user_id": user_id, "config_id": config_id, "config_group": config_update.config_group},
|
||||
)
|
||||
raise HTTPException(status_code=400, detail=_("Invalid configuration group"))
|
||||
|
||||
# Check for conflicts with other configurations
|
||||
|
|
@ -126,7 +153,10 @@ async def update_config(
|
|||
).first()
|
||||
|
||||
if existing_config:
|
||||
logger.warning("Config update failed: duplicate name", extra={"user_id": user_id, "config_id": config_id, "config_name": config_update.config_name})
|
||||
logger.warning(
|
||||
"Config update failed: duplicate name",
|
||||
extra={"user_id": user_id, "config_id": config_id, "config_name": config_update.config_name},
|
||||
)
|
||||
raise HTTPException(status_code=400, detail=_("Configuration already exists for this user"))
|
||||
|
||||
try:
|
||||
|
|
@ -136,11 +166,16 @@ async def update_config(
|
|||
session.add(db_config)
|
||||
session.commit()
|
||||
session.refresh(db_config)
|
||||
logger.info("Config updated", extra={"user_id": user_id, "config_id": config_id, "config_group": config_update.config_group})
|
||||
logger.info(
|
||||
"Config updated",
|
||||
extra={"user_id": user_id, "config_id": config_id, "config_group": config_update.config_group},
|
||||
)
|
||||
return db_config
|
||||
except Exception as e:
|
||||
session.rollback()
|
||||
logger.error("Config update failed", extra={"user_id": user_id, "config_id": config_id, "error": str(e)}, exc_info=True)
|
||||
logger.error(
|
||||
"Config update failed", extra={"user_id": user_id, "config_id": config_id, "error": str(e)}, exc_info=True
|
||||
)
|
||||
raise HTTPException(status_code=500, detail="Internal server error")
|
||||
|
||||
|
||||
|
|
@ -157,11 +192,15 @@ async def delete_config(config_id: int, session: Session = Depends(session), aut
|
|||
try:
|
||||
session.delete(db_config)
|
||||
session.commit()
|
||||
logger.info("Config deleted", extra={"user_id": user_id, "config_id": config_id, "config_name": db_config.config_name})
|
||||
logger.info(
|
||||
"Config deleted", extra={"user_id": user_id, "config_id": config_id, "config_name": db_config.config_name}
|
||||
)
|
||||
return Response(status_code=204)
|
||||
except Exception as e:
|
||||
session.rollback()
|
||||
logger.error("Config deletion failed", extra={"user_id": user_id, "config_id": config_id, "error": str(e)}, exc_info=True)
|
||||
logger.error(
|
||||
"Config deletion failed", extra={"user_id": user_id, "config_id": config_id, "error": str(e)}, exc_info=True
|
||||
)
|
||||
raise HTTPException(status_code=500, detail="Internal server error")
|
||||
|
||||
|
||||
|
|
@ -174,7 +213,9 @@ async def get_config_info(
|
|||
if show_all:
|
||||
logger.debug("Config info retrieved", extra={"show_all": True, "count": len(configs)})
|
||||
return configs
|
||||
|
||||
|
||||
filtered = {k: v for k, v in configs.items() if v.get("env_vars") and len(v["env_vars"]) > 0}
|
||||
logger.debug("Config info retrieved", extra={"show_all": False, "total_count": len(configs), "filtered_count": len(filtered)})
|
||||
return filtered
|
||||
logger.debug(
|
||||
"Config info retrieved", extra={"show_all": False, "total_count": len(configs), "filtered_count": len(filtered)}
|
||||
)
|
||||
return filtered
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue