新增:ekb agent rule-create 命令,支持新建审核规则
This commit is contained in:
1 parent
0f5b4c6272
commit
21d8832e44
3 files changed
+41
No files matched your search
@@ -0,0 +1,38 @@
|
||||
"""ekb agent rule-create:新建审核规则"""
|
||||
|
||||
import typer
|
||||
from rich import print as rprint
|
||||
|
||||
from ekb_cli.api import get_client
|
||||
from ekb_cli.api.agent import save_rule
|
||||
|
||||
VALID_LEVELS = {"严重", "一般"}
|
||||
|
||||
|
||||
def cmd_rule_create(
|
||||
purpose: str = typer.Option(..., "--purpose", "-p", help="适用场景(规则名称)"),
|
||||
description: str = typer.Option(..., "--desc", "-d", help="规则描述"),
|
||||
level: str = typer.Option("严重", "--level", "-l", help="风险等级:严重 / 一般"),
|
||||
):
|
||||
"""新建审核规则"""
|
||||
if level not in VALID_LEVELS:
|
||||
rprint(f"[red]错误:--level 只接受 严重 / 一般,当前值:{level}[/red]")
|
||||
raise typer.Exit(1)
|
||||
|
||||
payload = {"purpose": purpose, "description": description, "level": level}
|
||||
|
||||
with get_client() as client:
|
||||
resp = save_rule(client, payload)
|
||||
|
||||
data = resp.get("data", {})
|
||||
if not data:
|
||||
rprint(f"[red]创建失败:{resp}[/red]")
|
||||
raise typer.Exit(1)
|
||||
|
||||
rprint(f"[green]✓ 规则创建成功[/green]")
|
||||
rprint(f" 编码:[bold]{data.get('code')}[/bold]")
|
||||
rprint(f" ID:[dim]{data.get('id')}[/dim]")
|
||||
rprint(f" 适用场景:{data.get('purpose')}")
|
||||
rprint(f" 描述:{data.get('description')}")
|
||||
rprint(f" 风险等级:{'[red]' if data.get('level') == '严重' else '[yellow]'}{data.get('level')}[/{'red' if data.get('level') == '严重' else 'yellow'}]")
|
||||
rprint(f" 创建时间:[dim]{data.get('createTime')}[/dim]")
|
||||
Reference in new issue
Block a user