Skip to main content

just_shield/
config.rs

1//! 저장소 설정 파일 (`.just-shield.conf`) — 탈출구 ②: 신뢰 org 선언.
2//!
3//! 의도적으로 단순한 행 기반 형식이다. 한 줄 = 한 선언, `#`은 주석.
4//!
5//! ```text
6//! # 파트너 조직의 액션은 퍼스트파티로 취급
7//! trust-org partner-org
8//! ```
9
10use std::io;
11use std::path::Path;
12
13pub const FILE_NAME: &str = ".just-shield.conf";
14
15#[derive(Default)]
16pub struct Config {
17    /// 퍼스트파티로 취급할 액션 소유자(org/계정) 목록.
18    pub trusted_owners: Vec<String>,
19    /// R10 쿨다운 기준 일수. None이면 기본값(7일).
20    pub cooldown_days: Option<u32>,
21}
22
23/// 설정을 읽는다. 파일이 없으면 기본값 — 오류가 아니다.
24pub fn load(root: &Path) -> io::Result<Config> {
25    let path = root.join(FILE_NAME);
26    if !path.is_file() {
27        return Ok(Config::default());
28    }
29    let content = std::fs::read_to_string(path)?;
30    let mut config = Config::default();
31    for line in content.lines() {
32        let line = line.trim();
33        if line.is_empty() || line.starts_with('#') {
34            continue;
35        }
36        if let Some(owner) = line.strip_prefix("trust-org") {
37            let owner = owner.trim();
38            if !owner.is_empty() {
39                config.trusted_owners.push(owner.to_string());
40            }
41        } else if let Some(days) = line.strip_prefix("cooldown-days") {
42            config.cooldown_days = days.trim().parse().ok();
43        }
44        // 알 수 없는 선언은 미래 버전과의 호환을 위해 조용히 무시한다.
45    }
46    Ok(config)
47}