feat: 新增交通银行数据导出插件及测试通道机制
This commit is contained in:
+32
-13
@@ -32,6 +32,7 @@ agent 友好:
|
||||
运行(任意 cwd,用仓库 .venv 的 python;本文件已迁出已废弃的 desktop/controlplane):
|
||||
.venv\\Scripts\\python.exe tools\\agent_cli.py --admin puddy --password 123456 ping
|
||||
.venv\\Scripts\\python.exe tools\\agent_cli.py --admin puddy --password 123456 publish plugin.zip --id report --version 1.2.0
|
||||
(publish 默认进测试通道:状态=testing、仅管理员可见;验证通过后 plugin-status report --status published 转正)
|
||||
.venv\\Scripts\\python.exe tools\\agent_cli.py --admin puddy --password 123456 --json plugins
|
||||
.venv\\Scripts\\python.exe tools\\agent_cli.py --admin puddy --password 123456 grant alice report # 默认授予 download+run
|
||||
.venv\\Scripts\\python.exe tools\\agent_cli.py --admin puddy --password 123456 file push setup.exe --category shell --version 2.1.0
|
||||
@@ -176,10 +177,12 @@ class Client:
|
||||
except ValueError:
|
||||
return {"http": r.status_code, "raw": r.text[:200]}
|
||||
|
||||
def upload_pkg(self, path: str, plugin_id: str, name: str, version: str) -> dict:
|
||||
def upload_pkg(self, path: str, plugin_id: str, name: str, version: str,
|
||||
channel: str = "test") -> dict:
|
||||
import requests
|
||||
import urllib.parse
|
||||
qs = urllib.parse.urlencode({"plugin_id": plugin_id, "name": name, "version": version})
|
||||
qs = urllib.parse.urlencode({"plugin_id": plugin_id, "name": name,
|
||||
"version": version, "channel": channel})
|
||||
with open(path, "rb") as fp:
|
||||
r = requests.post(f"{self.base}/api/admin/pkg?{qs}",
|
||||
headers=self._headers(False),
|
||||
@@ -230,12 +233,13 @@ def _plugin_rows(plugins) -> None:
|
||||
if not rows:
|
||||
print("(暂无插件)")
|
||||
return
|
||||
print(f"{'ID':<28}{'名称':<16}{'最新版':<10}{'状态':<12}账号数")
|
||||
print(f"{'ID':<28}{'名称':<16}{'正式版':<10}{'在测版':<10}{'状态':<12}账号数")
|
||||
for p in rows:
|
||||
if not isinstance(p, dict):
|
||||
continue
|
||||
print(f"{str(p.get('id', '')):<28}{str(p.get('name') or ''):<16}"
|
||||
f"{str(p.get('latest_version') or ''):<10}{str(p.get('status') or ''):<12}{len(p.get('accounts') or [])}")
|
||||
f"{str(p.get('latest_version') or '-'):<10}{str(p.get('test_version') or '-'):<10}"
|
||||
f"{str(p.get('status') or ''):<12}{len(p.get('accounts') or [])}")
|
||||
|
||||
|
||||
def _run_file(args: argparse.Namespace, c: Client) -> int:
|
||||
@@ -350,21 +354,24 @@ def _build_parser() -> argparse.ArgumentParser:
|
||||
parser.add_argument("--json", action="store_true", help="结果以 JSON 输出(便于 agent 机器解析)")
|
||||
sub = parser.add_subparsers(dest="command", required=True)
|
||||
|
||||
p_pub = sub.add_parser("publish", help="发布插件包 zip(自动裁剪保留最近 3 版)")
|
||||
p_pub = sub.add_parser("publish", help="发布插件包 zip(默认进测试通道,仅管理员可见)")
|
||||
p_pub.add_argument("pkg", help="插件 zip 路径")
|
||||
p_pub.add_argument("--id", dest="plugin_id", required=True, help="插件 ID(须与 plugin.json 内 id 一致)")
|
||||
p_pub.add_argument("--name", default="", help="插件名称(缺省取 plugin.json 内 name 或 ID)")
|
||||
p_pub.add_argument("--version", required=True, help="版本号,如 1.2.0")
|
||||
p_pub.add_argument("--version", required=True,
|
||||
help="版本号,如 1.2.0(测试版须高于当前正式版;执行机只升不降)")
|
||||
p_pub.add_argument("--prod", action="store_true",
|
||||
help="直发正式通道(跳过测试,全量已授权账号立即升级;默认走测试通道)")
|
||||
|
||||
sub.add_parser("plugins", help="列出插件清单")
|
||||
|
||||
p_del = sub.add_parser("plugin-del", help="删除插件(连带全部版本、授权、磁盘包)")
|
||||
p_del.add_argument("plugin_id")
|
||||
|
||||
p_status = sub.add_parser("plugin-status", help="变更插件状态/强制更新阈值")
|
||||
p_status = sub.add_parser("plugin-status", help="变更插件状态/强制更新阈值(published 即把在测版本转正)")
|
||||
p_status.add_argument("plugin_id")
|
||||
p_status.add_argument("--status", choices=["published", "disabled", "revoked"], default="",
|
||||
help="新状态(留空不改变)")
|
||||
p_status.add_argument("--status", choices=["published", "testing", "disabled", "revoked"], default="",
|
||||
help="新状态:published=转正并全量生效 / testing=回到测试通道 / disabled / revoked")
|
||||
p_status.add_argument("--force-min-version", default="", help="强制最低版本(与 --force-deadline 成对)")
|
||||
p_status.add_argument("--force-deadline", default="", help="强制更新截止时间(ISO 字符串)")
|
||||
p_status.add_argument("--clear-force", action="store_true", help="清除强制更新配置")
|
||||
@@ -485,10 +492,22 @@ def _run(args: argparse.Namespace) -> int:
|
||||
return _run_file(args, c)
|
||||
|
||||
if cmd == "publish":
|
||||
r = c.upload_pkg(args.pkg, args.plugin_id, args.name, args.version)
|
||||
_emit(args, {"ok": True, "plugin_id": r.get("plugin_id"), "version": r.get("version"),
|
||||
"filename": r.get("filename")},
|
||||
f"[ok] 已发布 {r.get('plugin_id')} v{r.get('version')} → {r.get('filename')}")
|
||||
channel = "prod" if getattr(args, "prod", False) else "test"
|
||||
r = c.upload_pkg(args.pkg, args.plugin_id, args.name, args.version, channel)
|
||||
if channel == "test":
|
||||
_emit(args, {"ok": True, "plugin_id": r.get("plugin_id"), "version": r.get("version"),
|
||||
"channel": "test", "status": r.get("status"),
|
||||
"test_version": r.get("test_version"), "filename": r.get("filename")},
|
||||
f"[ok] 已发布测试版 {r.get('plugin_id')} v{r.get('version')} → {r.get('filename')}\n"
|
||||
f" 状态={r.get('status') or 'testing'},仅管理员账号可见(其他账号继续用正式版 "
|
||||
f"v{r.get('latest_version') or '(暂无)'})。\n"
|
||||
f" 验证通过后转正:plugin-status {r.get('plugin_id')} --status published")
|
||||
else:
|
||||
_emit(args, {"ok": True, "plugin_id": r.get("plugin_id"), "version": r.get("version"),
|
||||
"channel": "prod", "latest_version": r.get("latest_version"),
|
||||
"filename": r.get("filename")},
|
||||
f"[ok] 已直发正式 {r.get('plugin_id')} v{r.get('version')} → {r.get('filename')}\n"
|
||||
f" 已授权账号下次同步即升级(跳过了测试通道)。")
|
||||
|
||||
elif cmd == "plugins":
|
||||
data = c.call("GET", "/api/admin/overview")
|
||||
|
||||
Reference in New Issue
Block a user