Watch
0
0
Fork
You've already forked hyperhive
0

agent ssh connections: declare per agent, render into the agent's ssh config

This commit is contained in:
atlas 2026-11-20 01:38:49 +01:00
commit 934da6f31f

View file

@ -102,6 +102,13 @@ pub struct AgentPermissions {
/// to the agent's store login role while this is `true`.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub ssh: Option<bool>,
/// The named SSH connections the operator declared for the agent. The
/// agent renders them into its ssh config while `ssh` is on. Each passes
/// [`crate::ssh_connection::SshConnection::checked`] before it is stored,
/// and names are unique. A controller built before this field decodes the
/// record without it and stores it back without it.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub ssh_connections: Vec<crate::ssh_connection::SshConnection>,
}
/// What an agent whose record has no `max_repos` may create: no repositories.
@ -237,6 +244,41 @@ mod tests {
assert_eq!(before.internet_log, None);
}
/// The connections are left out when empty, so a record that never named
/// them encodes as before, and an older reader keeps the fields it knows.
#[test]
fn ssh_connections_are_left_out_when_empty_and_old_readers_skip_them() {
use crate::ssh_connection::SshConnection;
// A reader built before the field existed.
#[derive(serde::Deserialize)]
struct Old {
ssh: Option<bool>,
}
let none = AgentPermissions {
ssh: Some(true),
..AgentPermissions::default()
};
assert_eq!(serde_json::to_string(&none).unwrap(), r#"{"ssh":true}"#);
let before: AgentPermissions = serde_json::from_str(r#"{"ssh":true}"#).unwrap();
assert!(before.ssh_connections.is_empty());
assert_eq!(before, none);
let one = AgentPermissions {
ssh: Some(true),
ssh_connections: vec![SshConnection {
name: "k8s-lab-vm".to_owned(),
user: "root".to_owned(),
host: "muede-pc2".to_owned(),
port: 2222,
}],
..AgentPermissions::default()
};
let wire = r#"{"ssh":true,"ssh_connections":[{"name":"k8s-lab-vm","user":"root","host":"muede-pc2","port":2222}]}"#;
assert_eq!(serde_json::to_string(&one).unwrap(), wire);
assert_eq!(serde_json::from_str::<AgentPermissions>(wire).unwrap(), one);
assert_eq!(serde_json::from_str::<Old>(wire).unwrap().ssh, Some(true));
}
/// The repository limit is left out when unset, so a record that never
/// named it encodes as before; a negative number (Forgejo's "unlimited")
/// does not decode.