- AuditRule模型: 新增code/config_json字段,支持规则编码和阈值参数持久化 - audit_engine_v2: _load_rules从DB读config_json覆盖默认config - audit_rule_sync: 启动时自动从_RULE_REGISTRY同步规则到DB(239条) - settings API: update后刷新query_service配置缓存 - query_service: MAX_ROWS/QUERY_TIMEOUT/MAX_QUERY_LENGTH/MAX_RESULT_MEMORY改为动态读取system_settings - ticket_executor: SQL_TIMEOUT/REDIS_TIMEOUT/MONGO_TIMEOUT改为动态获取 - settings_seeds: 新增executor分组(sql/redis/mongo超时) + query_result_max_memory_mb - audit_rule endpoint: 移除无效的AuditEngine缓存清理(每次audit是新实例) - 测试: 1057 passed(修复所有新引入失败,17个历史遗留)
243 lines
8.1 KiB
Python
243 lines
8.1 KiB
Python
"""系统设置种子数据 — 首次启动自动初始化。"""
|
||
|
||
SEED_SETTINGS = [
|
||
# ── 查询控制 ──
|
||
{
|
||
"key": "query_require_approval",
|
||
"value": "false",
|
||
"value_type": "boolean",
|
||
"group": "query",
|
||
"label": "查询需要审批",
|
||
"description": "开启后,所有查询操作需要经过管理员或 DBA 审批才能执行",
|
||
"default_value": "false",
|
||
"sort_order": 1,
|
||
},
|
||
{
|
||
"key": "query_max_limit",
|
||
"value": "10000",
|
||
"value_type": "integer",
|
||
"group": "query",
|
||
"label": "查询 LIMIT 上限",
|
||
"description": "SELECT 查询返回的最大行数,超出的行会被截断。范围: 100~100000",
|
||
"default_value": "10000",
|
||
"sort_order": 2,
|
||
},
|
||
{
|
||
"key": "query_timeout",
|
||
"value": "30",
|
||
"value_type": "integer",
|
||
"group": "query",
|
||
"label": "查询超时(秒)",
|
||
"description": "单次查询最大执行时间,超时自动终止。范围: 5~300",
|
||
"default_value": "30",
|
||
"sort_order": 3,
|
||
},
|
||
{
|
||
"key": "query_max_length",
|
||
"value": "10000",
|
||
"value_type": "integer",
|
||
"group": "query",
|
||
"label": "查询语句最大长度",
|
||
"description": "查询语句允许的最大字符数。范围: 500~50000",
|
||
"default_value": "10000",
|
||
"sort_order": 4,
|
||
},
|
||
{
|
||
"key": "query_auto_limit",
|
||
"value": "true",
|
||
"value_type": "boolean",
|
||
"group": "query",
|
||
"label": "自动添加 LIMIT",
|
||
"description": "当 SELECT 语句没有 LIMIT 时自动追加,防止返回海量数据",
|
||
"default_value": "true",
|
||
"sort_order": 5,
|
||
},
|
||
{
|
||
"key": "query_enable_masking",
|
||
"value": "true",
|
||
"value_type": "boolean",
|
||
"group": "query",
|
||
"label": "启用数据脱敏",
|
||
"description": "自动对手机号、身份证、邮箱等敏感字段进行脱敏处理",
|
||
"default_value": "true",
|
||
"sort_order": 6,
|
||
},
|
||
{
|
||
"key": "query_save_history",
|
||
"value": "true",
|
||
"value_type": "boolean",
|
||
"group": "query",
|
||
"label": "保存查询历史",
|
||
"description": "自动记录每次查询内容,方便后续复用和审计",
|
||
"default_value": "true",
|
||
"sort_order": 7,
|
||
},
|
||
|
||
# ── 安全控制 ──
|
||
{
|
||
"key": "security_max_login_attempts",
|
||
"value": "5",
|
||
"value_type": "integer",
|
||
"group": "security",
|
||
"label": "最大登录失败次数",
|
||
"description": "连续登录失败达到次数后锁定账号(0 表示不限制)",
|
||
"default_value": "5",
|
||
"sort_order": 10,
|
||
},
|
||
{
|
||
"key": "security_password_min_length",
|
||
"value": "6",
|
||
"value_type": "integer",
|
||
"group": "security",
|
||
"label": "密码最小长度",
|
||
"description": "用户密码的最小字符数",
|
||
"default_value": "6",
|
||
"sort_order": 11,
|
||
},
|
||
{
|
||
"key": "security_enable_audit_log",
|
||
"value": "true",
|
||
"value_type": "boolean",
|
||
"group": "security",
|
||
"label": "启用审计日志",
|
||
"description": "记录所有关键操作(查询、工单、权限变更等)",
|
||
"default_value": "true",
|
||
"sort_order": 12,
|
||
},
|
||
|
||
# ── 工单控制 ──
|
||
{
|
||
"key": "ticket_default_workflow",
|
||
"value": "standard",
|
||
"value_type": "string",
|
||
"group": "ticket",
|
||
"label": "默认审批流程",
|
||
"description": "新建工单使用的默认审批流程: standard(标准三级) / simple(简单一级) / urgent(紧急快速)",
|
||
"default_value": "standard",
|
||
"sort_order": 20,
|
||
},
|
||
{
|
||
"key": "ticket_allow_rollback",
|
||
"value": "true",
|
||
"value_type": "boolean",
|
||
"group": "ticket",
|
||
"label": "允许工单回滚",
|
||
"description": "执行失败的工单是否允许重新执行(回到 approved 状态)",
|
||
"default_value": "true",
|
||
"sort_order": 21,
|
||
},
|
||
|
||
# ── 日志清理 ──
|
||
{
|
||
"key": "cleanup_enabled",
|
||
"value": "true",
|
||
"value_type": "boolean",
|
||
"group": "cleanup",
|
||
"label": "启用自动清理",
|
||
"description": "开启后每天凌晨自动清理过期记录",
|
||
"default_value": "true",
|
||
"sort_order": 30,
|
||
},
|
||
{
|
||
"key": "cleanup_run_hour",
|
||
"value": "3",
|
||
"value_type": "integer",
|
||
"group": "cleanup",
|
||
"label": "清理执行时间(时)",
|
||
"description": "每天几点执行自动清理(0-23),默认凌晨 3 点",
|
||
"default_value": "3",
|
||
"sort_order": 31,
|
||
},
|
||
{
|
||
"key": "cleanup_ticket_days",
|
||
"value": "90",
|
||
"value_type": "integer",
|
||
"group": "cleanup",
|
||
"label": "数据变更工单保留天数",
|
||
"description": "已完成/已拒绝的工单超过保留天数将被自动清理(0 表示不清理)",
|
||
"default_value": "90",
|
||
"sort_order": 32,
|
||
},
|
||
{
|
||
"key": "cleanup_audit_log_days",
|
||
"value": "180",
|
||
"value_type": "integer",
|
||
"group": "cleanup",
|
||
"label": "审计日志保留天数",
|
||
"description": "审计日志超过保留天数将被自动清理(0 表示不清理)",
|
||
"default_value": "180",
|
||
"sort_order": 33,
|
||
},
|
||
{
|
||
"key": "cleanup_query_history_days",
|
||
"value": "30",
|
||
"value_type": "integer",
|
||
"group": "cleanup",
|
||
"label": "查询历史保留天数",
|
||
"description": "查询历史超过保留天数将被自动清理(0 表示不清理)",
|
||
"default_value": "30",
|
||
"sort_order": 34,
|
||
},
|
||
{
|
||
"key": "cleanup_scheduled_task_log_days",
|
||
"value": "30",
|
||
"value_type": "integer",
|
||
"group": "cleanup",
|
||
"label": "定时任务日志保留天数",
|
||
"description": "定时任务执行日志超过保留天数将被自动清理(0 表示不清理)",
|
||
"default_value": "30",
|
||
"sort_order": 35,
|
||
},
|
||
|
||
# ── 执行器 ──
|
||
{
|
||
"key": "executor_sql_timeout",
|
||
"value": "60",
|
||
"value_type": "integer",
|
||
"group": "executor",
|
||
"label": "SQL 执行超时(秒)",
|
||
"description": "MySQL/PostgreSQL 工单执行单条 SQL 最大时间。范围: 10~600",
|
||
"default_value": "60",
|
||
"sort_order": 40,
|
||
},
|
||
{
|
||
"key": "executor_redis_timeout",
|
||
"value": "30",
|
||
"value_type": "integer",
|
||
"group": "executor",
|
||
"label": "Redis 执行超时(秒)",
|
||
"description": "Redis 工单执行单条命令最大时间。范围: 5~120",
|
||
"default_value": "30",
|
||
"sort_order": 41,
|
||
},
|
||
{
|
||
"key": "executor_mongo_timeout",
|
||
"value": "60",
|
||
"value_type": "integer",
|
||
"group": "executor",
|
||
"label": "MongoDB 执行超时(秒)",
|
||
"description": "MongoDB 工单执行单条命令最大时间。范围: 10~600",
|
||
"default_value": "60",
|
||
"sort_order": 42,
|
||
},
|
||
{
|
||
"key": "query_result_max_memory_mb",
|
||
"value": "50",
|
||
"value_type": "integer",
|
||
"group": "query",
|
||
"label": "查询结果内存上限(MB)",
|
||
"description": "单次查询结果集最大内存占用,超限自动截断。范围: 10~500",
|
||
"default_value": "50",
|
||
"sort_order": 8,
|
||
},
|
||
]
|
||
|
||
# 分组元信息
|
||
SETTING_GROUPS = {
|
||
"query": {"label": "查询控制", "icon": "🔍", "description": "控制查询行为、LIMIT、超时和脱敏策略"},
|
||
"security": {"label": "安全设置", "icon": "🔒", "description": "登录安全、密码策略、审计日志"},
|
||
"ticket": {"label": "工单设置", "icon": "📋", "description": "审批流程、回滚策略"},
|
||
"cleanup": {"label": "日志清理", "icon": "🧹", "description": "数据变更工单、审计日志、查询历史的自动清理策略"},
|
||
"executor": {"label": "执行器", "icon": "⚙️", "description": "SQL/Redis 执行超时、批量限制、连接参数"},
|
||
}
|