- 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
62 lines
1.9 KiB
Rust
62 lines
1.9 KiB
Rust
//! 域名持久化模型(`domains.json`:一条记录 = 一个子域名)。
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// 单条域名记录。
|
|
///
|
|
/// 字段名与旧版 `data/domains.json` **逐字对应**,以便新版直接接管旧数据文件。
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct DomainEntry {
|
|
pub id: String,
|
|
pub subdomain: String,
|
|
/// `host:port`
|
|
pub backend: String,
|
|
/// `temp`(临时,到时自动停止转发) | `long`(长期)
|
|
#[serde(rename = "type")]
|
|
pub dtype: String,
|
|
/// 归属账号
|
|
pub owner: String,
|
|
/// `pending` | `approved` | `rejected`
|
|
pub status: String,
|
|
#[serde(default)]
|
|
pub created_at: i64,
|
|
/// 仅 temp 有意义;long 恒为 0
|
|
#[serde(default)]
|
|
pub expires_at: i64,
|
|
/// `auto` 表示凭临时授权权限免审放行
|
|
#[serde(default)]
|
|
pub reviewed_by: String,
|
|
#[serde(default)]
|
|
pub reviewed_at: i64,
|
|
}
|
|
|
|
impl DomainEntry {
|
|
/// 实际状态:approved 的临时域名过期后视为 `expired`。
|
|
///
|
|
/// 这是「到期不等于删除」语义的落点——记录保留,只是不再转发。
|
|
pub fn effective_status(&self, now: i64) -> &'static str {
|
|
if self.status == "approved" && self.dtype == "temp" {
|
|
if self.expires_at > 0 && self.expires_at <= now {
|
|
return "expired";
|
|
}
|
|
}
|
|
match self.status.as_str() {
|
|
"approved" => "approved",
|
|
"rejected" => "rejected",
|
|
_ => "pending",
|
|
}
|
|
}
|
|
|
|
/// 转发侧判定:返回该域名当前是否可转发(已放行且未过期)
|
|
pub fn is_forwardable(&self, now: i64) -> bool {
|
|
if self.status != "approved" {
|
|
return false;
|
|
}
|
|
if self.dtype == "temp" {
|
|
// 临时域名必须有明确的、尚未到达的到期时刻
|
|
return self.expires_at > now;
|
|
}
|
|
true
|
|
}
|
|
}
|