support_kit/hosts/
host_session.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use crate::SshError;

use super::{HostDetails, SshSession};

pub struct HostSession {
    _config: HostDetails,
    session: SshSession,
}

#[bon::bon]
impl HostSession {
    #[builder]
    #[tracing::instrument(skip(host), level = "trace")]
    pub async fn connect(#[builder(into)] host: HostDetails) -> Result<Self, SshError> {
        Ok(Self {
            session: SshSession::connect(&host).await?,
            _config: host,
        })
    }

    #[tracing::instrument(skip(self, cmd), level = "trace")]
    pub async fn run_cmd<T>(&self, cmd: Vec<T>) -> Result<(), SshError>
    where
        T: AsRef<str>,
    {
        self.session.run_cmd(cmd).await
    }
}