Files
ipass__ipass/rust/crates/plugin-domain/src/lib.rs
T
admin 74aeefee58 refactor(plugin): P0-P2 插件化落地 —— workspace 化 + ipass-core + plugin-domain
- P0: rust/ 改 workspace(ipass-core 内核 + gateway 唯一 cdylib),
  [profile.release] 上移根、依赖收敛 workspace.dependencies;
  users::delete 的 stats::forget 依赖改为 on_delete 钩子注册表
- P1: 契约层 core/plugin.rs(Plugin trait)+ core/loc.rs(Switch 并集 +
  set_switch_fn,未实现变体保守 false);gateway PLUGINS 分发循环,
  不认领统一 404(插件绝不自行 404)
- P2: 身份端点下沉 core/api.rs(CorePlugin + CoreExt 扩展注册表,
  gateway 作装配根回填域名数/用量/连带回收/白名单校验);
  plugin-domain crate(domains + DomainEntry + sub: 前缀 + ResolveHandler
  + $proxy_backend_addr + 域名类端点含 purge)
- 行为等价:conf/nginx.conf、Dockerfile、tests 零改动,262 回归全绿
- 方案文档 docs/plugin/PLUGINIZATION_PLAN.md
2026-09-13 11:43:22 +08:00

55 lines
1.6 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! plugin-domain —— 动态域名插件。
//!
//! 职责:子域名 → 后端映射(`sub:` 键空间)、申请与审批、转发决策
//! (access 阶段查共享内存)。数据文件 `data/domains.json`。
//!
//! ## 与旧版最大的差异:写穿
//!
//! 热路径**永不回源**(未命中即 404),所以每个写操作都必须
//! **同时更新共享内存与文件**——这就是 `domains::sync_shm` 的存在理由。
//! 漏掉一处,就会出现「审核通过了但立刻 404」。
//!
//! ## 装配点(gateway)
//!
//! * `preconfig` —— 注册 `$proxy_backend_addr` 变量(`proxy_pass` 依赖)
//! * `postconfig` —— 注册 `ResolveHandler`(access 阶段)
//! * `zone_load` —— 全量装载 `sub:` 映射
//! * `dispatch_api` —— 认领域名类管理/账号端点
pub mod api;
pub mod config;
pub mod domains;
pub mod models;
pub mod resolve;
pub mod store;
use ngx::core::Status;
use ngx::ffi::{ngx_conf_t, ngx_http_request_t};
use ipass_core::plugin::Plugin;
pub struct DomainPlugin;
impl Plugin for DomainPlugin {
fn name(&self) -> &'static str {
"domain"
}
fn preconfig(&self, cf: *mut ngx_conf_t) -> bool {
resolve::preconfig(cf)
}
fn postconfig(&self, cf: *mut ngx_conf_t) -> bool {
// SAFETY: cf 由 nginx 传入且有效
ngx::http::add_phase_handler::<resolve::ResolveHandler>(unsafe { &mut *cf }).is_ok()
}
fn dispatch_api(&self, r: *mut ngx_http_request_t) -> Option<Status> {
api::dispatch(r)
}
fn zone_load(&self) -> usize {
domains::reload_shm()
}
}