Skip to main content

cfgd_core/config/
origin.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4#[serde(rename_all = "camelCase", deny_unknown_fields)]
5pub struct OriginSpec {
6    #[serde(rename = "type")]
7    pub origin_type: OriginType,
8    pub url: String,
9    #[serde(default = "default_branch")]
10    pub branch: String,
11    #[serde(default, skip_serializing_if = "Option::is_none")]
12    pub auth: Option<String>,
13    /// SSH `StrictHostKeyChecking` policy for git operations.
14    /// `AcceptNew` (default): accept first-seen keys, reject changed keys.
15    /// `Yes`: require keys to already exist in known_hosts (high-security).
16    /// `No`: accept any key (insecure, not recommended).
17    #[serde(default)]
18    pub ssh_strict_host_key_checking: SshHostKeyPolicy,
19}
20
21/// SSH `StrictHostKeyChecking` policy for git operations over SSH.
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
23pub enum SshHostKeyPolicy {
24    /// Accept first-seen keys, reject changed keys (safe default for automation).
25    #[default]
26    AcceptNew,
27    /// Require keys to already exist in known_hosts (high-security environments).
28    Yes,
29    /// Accept any key without verification (insecure, not recommended).
30    No,
31}
32
33impl SshHostKeyPolicy {
34    pub fn as_ssh_option(&self) -> &'static str {
35        match self {
36            SshHostKeyPolicy::AcceptNew => "accept-new",
37            SshHostKeyPolicy::Yes => "yes",
38            SshHostKeyPolicy::No => "no",
39        }
40    }
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub enum OriginType {
45    Git,
46    Server,
47}
48
49fn default_branch() -> String {
50    "master".to_string()
51}