mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-13 17:35:37 +00:00
513695297c
* [OHOS.with ai] 将配置管理/配置分享/路由聚合/实例状态解析下沉至 Rust 内核,收敛职责并提升性能 (#2209) * feat: add ohrs config store and startup error logging * feat: full ability core for ohos * feat: full ability core for ohos * feat: clean code --------- Co-authored-by: FrankHan <frankhan@FrankHans-Mac-mini.local> * fix: 添加缺失文件 * fix: 修复更新路由启动两次TUN问题,并调整日志 * fix: rustfmt * fix: 适配Cidr忽略/32格式路由 * fix: 修复Option适配错误 * fix: rustfmt * fix: rustfmt --------- Co-authored-by: FrankHan <frankhan@FrankHans-Mac-mini.local>
31 lines
950 B
Rust
31 lines
950 B
Rust
use easytier::proto::api::manage::NetworkConfig;
|
|
use serde_json::{Map, Value};
|
|
|
|
pub(super) fn normalize_config_id(
|
|
mut config: NetworkConfig,
|
|
requested_id: String,
|
|
) -> Result<NetworkConfig, String> {
|
|
if requested_id.is_empty() {
|
|
return Err("config_id is required".to_string());
|
|
}
|
|
config.instance_id = Some(requested_id);
|
|
Ok(config)
|
|
}
|
|
|
|
pub(super) fn validate_config_json(
|
|
config_json: &str,
|
|
config_id: String,
|
|
) -> Result<NetworkConfig, String> {
|
|
let config = serde_json::from_str::<NetworkConfig>(config_json)
|
|
.map_err(|e| format!("parse config json failed: {}", e))?;
|
|
let config = normalize_config_id(config, config_id)?;
|
|
config
|
|
.gen_config()
|
|
.map_err(|e| format!("generate toml failed: {}", e))?;
|
|
Ok(config)
|
|
}
|
|
|
|
pub(super) fn config_to_top_level_map(config: &NetworkConfig) -> Option<Map<String, Value>> {
|
|
serde_json::to_value(config).ok()?.as_object().cloned()
|
|
}
|