Skip to main content

shuttle/
pool.rs

1use crate::client::{ClientError, SshClient};
2use crate::config::ShuttleConfig;
3use std::sync::Arc;
4use styrene_identity::signer::RootSecret;
5use tokio::sync::Mutex;
6
7pub struct ConnectionPool;
8
9impl ConnectionPool {
10    pub fn new() -> Self {
11        Self
12    }
13
14    /// Create a fresh SSH connection to a host.
15    ///
16    /// Each call opens a new connection and authenticates. This is
17    /// intentional for v1 — connection reuse requires liveness probes
18    /// and careful session lifecycle management that will come later.
19    pub async fn acquire(
20        &self,
21        host_name: &str,
22        config: &ShuttleConfig,
23        root: &RootSecret,
24    ) -> Result<Arc<Mutex<SshClient>>, ClientError> {
25        let entry = config
26            .resolve_host(host_name)
27            .map_err(|e| ClientError::Auth(e.to_string()))?;
28
29        let client =
30            SshClient::connect(host_name, entry, root, &config.known_hosts_file).await?;
31
32        Ok(Arc::new(Mutex::new(client)))
33    }
34}