csaf2cusa/src/config.rs
Jia Chao 0063dc4ae5 release v0.1.2: 子命令 auto 支持参数指定源和目标路径
Signed-off-by: Jia Chao <jiac13@chinaunicom.cn>
2024-09-11 14:08:30 +08:00

84 lines
2.0 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.

use std::path::Path;
use serde::{Deserialize, Serialize};
/// csaf2cusa 自动化执行所需的配置
#[derive(Clone, Debug, Deserialize, Serialize)]
pub(crate) struct AutoConfig {
// 对应cuavrs-db-csaf
source: String,
// cuavrs-db-sa
target: String,
}
impl AutoConfig {
// 新建一个配置结构
pub fn new(source: String, target: String) -> Self {
Self { source, target }
}
// 从文件中读取配置
pub fn from<P: AsRef<Path>>(path: P) -> crate::Result<Self> {
let data = std::fs::read_to_string(path)?;
Ok(serde_json::from_str::<Self>(&data)?)
}
// 获取 source 字段
pub fn source(&self) -> &str {
&self.source
}
// 获取 target 字段
pub fn target(&self) -> &str {
&self.target
}
}
/// cuvars 中,关于源码追踪,自动修复相关的配置项,一般位于组件最底层的目录,`config.json`
#[derive(Clone, Debug, Deserialize, Serialize)]
pub(crate) struct RepairConfig {
// 对应了 openEuelr 的上游版本, 例 22.03-LST不可包含 openEuler 字段
upstream: String,
// 此组件是否支持自动修复
autobuild: bool,
// 当前已修复的最新版本号
fixed_version: String,
}
#[allow(dead_code)]
impl RepairConfig {
pub fn new(upstream: String, autobuild: bool, fixed_version: String) -> Self {
RepairConfig {
upstream,
autobuild,
fixed_version,
}
}
/// 从指定的路径读取文件并将之转换为 `RepairConfig`
pub fn from<P: AsRef<Path>>(path: P) -> crate::Result<Self> {
let data = std::fs::read_to_string(path)?;
Ok(serde_json::from_str::<Self>(&data)?)
}
/// 获取对应的上游代码分支
pub fn upstream(&self) -> &str {
&self.upstream
}
/// 此组件是否支持自动构建发布
pub fn autobuild(&self) -> bool {
self.autobuild
}
/// 已修复的最新代码版本
pub fn fixed_version(&self) -> &str {
&self.fixed_version
}
}