//! `/api/agents/{name}/ssh-connections`: the named SSH connections declared for //! one agent. The agent's ssh config gets one `Host` block for each while its //! `ssh` switch is on. use serde::{Deserialize, Serialize}; /// One named connection: `ssh ` connects as `user` to `host` on `port`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "schema", derive(utoipa::ToSchema))] pub struct SshConnection { /// The alias the agent types: lower-case letters, digits and hyphens, at /// most 63, not starting with a hyphen. #[cfg_attr(feature = "schema", schema(example = "k8s-lab-vm"))] pub name: String, /// The account to log in as. #[cfg_attr(feature = "schema", schema(example = "root"))] pub user: String, /// A DNS name or an IPv4 address. #[cfg_attr(feature = "schema", schema(example = "muede-pc2"))] pub host: String, /// The TCP port, 1 to 65535 except 80 and 443. #[cfg_attr(feature = "schema", schema(example = 2222))] pub port: u16, } /// The body of `PUT /api/agents/{name}/ssh-connections/{conn}`; the name is the /// path's. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "schema", derive(utoipa::ToSchema))] #[serde(deny_unknown_fields)] pub struct PutSshConnection { /// The account to log in as. #[cfg_attr(feature = "schema", schema(example = "root"))] pub user: String, /// A DNS name or an IPv4 address. #[cfg_attr(feature = "schema", schema(example = "muede-pc2"))] pub host: String, /// The TCP port, 1 to 65535 except 80 and 443. #[cfg_attr(feature = "schema", schema(example = 2222))] pub port: u16, } /// The answer to `GET /api/agents/{name}/ssh-connections`. #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "schema", derive(utoipa::ToSchema))] pub struct SshConnections { /// The agent's connections, in the order they were added. pub connections: Vec, } #[cfg(test)] mod tests { use super::*; #[test] fn bodies_round_trip_and_the_put_refuses_other_fields() { let put = PutSshConnection { user: "root".to_owned(), host: "muede-pc2".to_owned(), port: 2222, }; let wire = r#"{"user":"root","host":"muede-pc2","port":2222}"#; assert_eq!(serde_json::to_string(&put).unwrap(), wire); assert_eq!(serde_json::from_str::(wire).unwrap(), put); assert!( serde_json::from_str::( r#"{"name":"x","user":"root","host":"h","port":22}"# ) .is_err(), "the name is the path's" ); assert_eq!( serde_json::to_string(&SshConnections::default()).unwrap(), r#"{"connections":[]}"# ); } }