From 06f3175c2254542e56cb51aa639aecbf92940f3d Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 24 Sep 2026 20:05:48 +0800 Subject: [PATCH] feat(gateway): wire plugin toggle (load+set_current+dispatch skip); short-name config keys (R19); drop empty deps/ Co-Authored-By: Claude Opus 4.8 --- data-seed/plugin-config.json | 2 +- rust/gateway/src/lib.rs | 12 ++++++++++++ scripts/collect-plugin-dist.sh | 34 +++++++++++++++++++++++----------- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/data-seed/plugin-config.json b/data-seed/plugin-config.json index 6d77169..6c770c1 100644 --- a/data-seed/plugin-config.json +++ b/data-seed/plugin-config.json @@ -1 +1 @@ -{"plugins":{"plugin-sso":{"enabled":true,"admin_prefix":"plugin-sso"}}} \ No newline at end of file +{"plugins":{"sso":{"enabled":true,"admin_prefix":"sso"}}} diff --git a/rust/gateway/src/lib.rs b/rust/gateway/src/lib.rs index 43d4b9b..aa6112d 100644 --- a/rust/gateway/src/lib.rs +++ b/rust/gateway/src/lib.rs @@ -105,6 +105,11 @@ impl HttpRequestHandler for ApiHandler { /// 管理 API 分发:按 PLUGINS 顺序问每个插件,都不认领才统一 JSON 信封 404。 fn dispatch_api(r: *mut ngx_http_request_t) -> Status { for p in PLUGINS { + // R19:被禁插件不认领路由(自然落到下面的统一 404)。 + // core 是网关身份底座,永不跳过。 + if p.name() != "core" && !ipass_core::plugin_registry::plugin_enabled(p.name()) { + continue; + } if let Some(s) = p.dispatch_api(r) { return s; } @@ -204,6 +209,13 @@ impl HttpModule for Module { unsafe extern "C" fn postconfiguration(cf: *mut ngx_conf_t) -> ngx_int_t { let cf = unsafe { &mut *cf }; + // R19:装载插件启停注册表。`ipass_data_dir` 指令在配置解析阶段已写入 + // store;postconfiguration 在 master 单次执行(reload 重进 = 热更新)。 + let cfg = ipass_core::plugin_registry::load(&format!( + "{}/plugin-config.json", + store::data_dir() + )); + ipass_core::plugin_registry::set_current(cfg); // 插件先注册自己的阶段处理器(如 IAP 的 access 门禁) for p in PLUGINS { if !p.postconfig(cf) { diff --git a/scripts/collect-plugin-dist.sh b/scripts/collect-plugin-dist.sh index bdadbe2..784acf1 100755 --- a/scripts/collect-plugin-dist.sh +++ b/scripts/collect-plugin-dist.sh @@ -6,13 +6,17 @@ # - 核心壳来自 ipass-core/www(index.html + assets) # - 插件管理页是 UMD 产物,壳按 # /static/plugins//dist/-admin.umd.js 动态加载 -# (寻址约定见 ipass-core www/src/loader.ts, 即 plugin-config.json 的键) +# (寻址约定见 ipass-core www/src/loader.ts;R19 起 统一为 +# Plugin::name() 短名(sso),即 plugin-config.json 的键, +# 也即 /api/core/plugins 返回的 name) # Docker 构建上下文只覆盖本仓,COPY 不到兄弟仓库,故本脚本先把产物聚合进 # $ASSEMBLY_DIR,再由 Dockerfile / nginx 静态目录消费。 # # 输出布局(默认 ASSEMBLY_DIR=deploy,供 docker build 前的准备步骤): # $ASSEMBLY_DIR/shell/ ← ../ipass-core/www/dist -# $ASSEMBLY_DIR/static-plugins//dist/ ← ../ipass-/www/dist(仅 enabled) +# $ASSEMBLY_DIR/static-plugins//dist/ ← ../ipass-plugin-/www/dist(仅 enabled) +# ( = R19 统一后的短名;UMD 产物原名 plugin--admin.umd.js, +# 脚本另存一份 -admin.umd.js 别名供壳按短名加载) # # 用法: # bash scripts/collect-plugin-dist.sh # → deploy/ @@ -48,13 +52,14 @@ CONFIG="$ROOT/data/plugin-config.json" PYTHON="${PYTHON:-python3}" command -v "$PYTHON" >/dev/null 2>&1 || { echo "!! 缺 python3(解析 plugin-config.json 用)" >&2; exit 1; } -# enabled 插件名清单(如 plugin-sso;对应仓库目录 ipass-) +# enabled 插件短名清单(R19 统一键 = Plugin::name(),如 sso;对应仓库 ipass-plugin-<短名>。 +# 兼容旧 plugin- 前缀拼写:一律去掉前缀再映射目录) PLUGINS="$("$PYTHON" - "$CONFIG" <<'PY' import json, sys cfg = json.load(open(sys.argv[1], encoding="utf-8")) for name, p in cfg.get("plugins", {}).items(): if p.get("enabled"): - print(name) + print(name.removeprefix("plugin-")) PY )" @@ -77,16 +82,23 @@ mkdir -p "$PLUGINS_OUT" find "$PLUGINS_OUT" -mindepth 1 -maxdepth 1 ! -name .gitkeep -exec rm -rf {} + count=0 -while IFS= read -r name; do - [ -n "$name" ] || continue - src="$IPASS_DIR/ipass-${name}/www/dist" +while IFS= read -r short; do + [ -n "$short" ] || continue + src="$IPASS_DIR/ipass-plugin-${short}/www/dist" if [ ! -d "$src" ]; then - echo "!! $name:$src 缺失(先在 ipass-${name}/www 跑 npm run build),跳过" >&2 + echo "!! $short:$src 缺失(先在 ipass-plugin-${short}/www 跑 npm run build),跳过" >&2 continue fi - mkdir -p "$PLUGINS_OUT/$name/dist" - rsync -a --delete "$src/" "$PLUGINS_OUT/$name/dist/" - echo "plugin: $src → $PLUGINS_OUT/$name/dist" + mkdir -p "$PLUGINS_OUT/$short/dist" + rsync -a --delete "$src/" "$PLUGINS_OUT/$short/dist/" + # 产物原文件名是 plugin-<短名>-admin.umd.js;壳按短名请求 + # /static/plugins/<短名>/dist/<短名>-admin.umd.js(loader.ts 约定)→ 补一份短名别名 + if [ ! -f "$PLUGINS_OUT/$short/dist/${short}-admin.umd.js" ] \ + && [ -f "$PLUGINS_OUT/$short/dist/plugin-${short}-admin.umd.js" ]; then + cp "$PLUGINS_OUT/$short/dist/plugin-${short}-admin.umd.js" \ + "$PLUGINS_OUT/$short/dist/${short}-admin.umd.js" + fi + echo "plugin: $src → $PLUGINS_OUT/$short/dist" count=$((count + 1)) done <