Skip to main content

purple_ssh/
ssh_context.rs

1use std::path::{Path, PathBuf};
2
3/// Common SSH connection context passed to remote operations.
4pub struct SshContext<'a> {
5    pub alias: &'a str,
6    pub config_path: &'a Path,
7    pub askpass: Option<&'a str>,
8    /// Password typed in the TUI for this session only. Reaches ssh through
9    /// the one-shot askpass channel and is never written to disk.
10    pub session_password: Option<&'a str>,
11    pub bw_session: Option<&'a str>,
12    pub has_tunnel: bool,
13    /// Set only by a retry that follows the trust dialog: ssh runs with
14    /// `StrictHostKeyChecking=accept-new` for that one run so the host key
15    /// is recorded on first contact.
16    pub trust_new_host_key: bool,
17    pub env: &'a crate::runtime::env::Env,
18}
19
20/// Owned variant for spawning into threads.
21pub struct OwnedSshContext {
22    pub alias: String,
23    pub config_path: PathBuf,
24    pub askpass: Option<String>,
25    pub session_password: Option<String>,
26    pub bw_session: Option<String>,
27    pub has_tunnel: bool,
28    pub trust_new_host_key: bool,
29    pub env: std::sync::Arc<crate::runtime::env::Env>,
30}
31
32impl OwnedSshContext {
33    /// Borrow every field for a synchronous call inside the worker thread.
34    pub fn borrow(&self) -> SshContext<'_> {
35        SshContext {
36            alias: &self.alias,
37            config_path: &self.config_path,
38            askpass: self.askpass.as_deref(),
39            session_password: self.session_password.as_deref(),
40            bw_session: self.bw_session.as_deref(),
41            has_tunnel: self.has_tunnel,
42            trust_new_host_key: self.trust_new_host_key,
43            env: &self.env,
44        }
45    }
46}