```
feat(ai_agent): 完善AI适配器和服务功能 - 添加OpenClaw和Hermes健康检查接口 - 实现OpenClaw工具调用功能 - 重构AI适配器使用常量定义 - 增加AI技能系统支持 - 更新配置文件中的默认模型提供者设置 refactor(scheduler): 使用常量替换硬编码值 - 将硬编码的actor值替换为ActorValue常量 - 将receive_id_type替换为FeishuReceiveIdType枚举 refactor(audit): 统一审计日志常量使用 - 将硬编码的actor、source、risk_level等值替换为对应常量 - 更新审核服务中的状态和操作常量引用 refactor(approvals): 标准化审批模块常量使用 - 将applicant默认值替换为ActorValue.API常量 - 使用ApprovalStatus常量替代硬编码状态值 - 更新审核操作常量引用 ```
This commit is contained in:
39
app/modules/audit/constants.py
Normal file
39
app/modules/audit/constants.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from enum import StrEnum
|
||||
|
||||
|
||||
class AuditAction(StrEnum):
|
||||
AI_ASK = "ai.ask"
|
||||
AI_PROVIDER_HEALTH = "ai.provider_health"
|
||||
OPENCLAW_TOOLS_INVOKE = "openclaw.tools.invoke"
|
||||
GENERATE_EVENTS = "generate_events"
|
||||
FEISHU_SEND_TEXT = "send_text"
|
||||
FEISHU_SEND_CARD = "send_card"
|
||||
APPROVAL_CREATE = "approval.create"
|
||||
APPROVAL_APPROVE = "approval.approve"
|
||||
APPROVAL_REJECT = "approval.reject"
|
||||
LEGACY_SYNC_PROJECTS = "sync_projects"
|
||||
|
||||
|
||||
class AuditRiskLevel(StrEnum):
|
||||
LOW = "low"
|
||||
MEDIUM = "medium"
|
||||
HIGH = "high"
|
||||
|
||||
|
||||
class AuditSource(StrEnum):
|
||||
API = "api"
|
||||
OPENCLAW = "openclaw"
|
||||
RISK = "risk"
|
||||
FEISHU = "feishu"
|
||||
APPROVAL = "approval"
|
||||
LEGACY_MYSQL = "legacy_mysql"
|
||||
|
||||
|
||||
class AuditTargetType(StrEnum):
|
||||
AI = "ai"
|
||||
OPENCLAW_TOOL = "openclaw_tool"
|
||||
RISK_EVENTS = "risk-events"
|
||||
|
||||
|
||||
class AuditStatus(StrEnum):
|
||||
SUCCESS = "success"
|
||||
@@ -3,20 +3,22 @@ from datetime import datetime
|
||||
from sqlalchemy import DateTime, Integer, String, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.core.constants import ActorValue
|
||||
from app.core.database import Base
|
||||
from app.modules.audit.constants import AuditRiskLevel, AuditSource, AuditStatus
|
||||
|
||||
|
||||
class AuditLog(Base):
|
||||
__tablename__ = "audit_logs"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
actor: Mapped[str] = mapped_column(String(128), default="system", index=True)
|
||||
source: Mapped[str] = mapped_column(String(64), default="api", index=True)
|
||||
actor: Mapped[str] = mapped_column(String(128), default=ActorValue.SYSTEM, index=True)
|
||||
source: Mapped[str] = mapped_column(String(64), default=AuditSource.API, index=True)
|
||||
action: Mapped[str] = mapped_column(String(128), index=True)
|
||||
target_type: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
||||
target_id: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
||||
risk_level: Mapped[str] = mapped_column(String(32), default="low", index=True)
|
||||
risk_level: Mapped[str] = mapped_column(String(32), default=AuditRiskLevel.LOW, index=True)
|
||||
request_payload: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
response_payload: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
status: Mapped[str] = mapped_column(String(32), default="success", index=True)
|
||||
status: Mapped[str] = mapped_column(String(32), default=AuditStatus.SUCCESS, index=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, index=True)
|
||||
|
||||
@@ -3,17 +3,20 @@ from typing import Any
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from app.core.constants import ActorValue
|
||||
from app.modules.audit.constants import AuditRiskLevel, AuditSource, AuditStatus
|
||||
|
||||
|
||||
class AuditLogCreate(BaseModel):
|
||||
actor: str = "system"
|
||||
source: str = "api"
|
||||
actor: str = ActorValue.SYSTEM
|
||||
source: str = AuditSource.API
|
||||
action: str
|
||||
target_type: str | None = None
|
||||
target_id: str | None = None
|
||||
risk_level: str = "low"
|
||||
risk_level: str = AuditRiskLevel.LOW
|
||||
request_payload: Any | None = None
|
||||
response_payload: Any | None = None
|
||||
status: str = "success"
|
||||
status: str = AuditStatus.SUCCESS
|
||||
|
||||
|
||||
class AuditLogRead(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user