MCPcopy Create free account
hub / github.com/GCWing/BitFun / ssh_connect

Function ssh_connect

src/apps/desktop/src/api/ssh_api.rs:87–143  ·  view source on GitHub ↗
(
    state: State<'_, AppState>,
    mut config: SSHConnectionConfig,
)

Source from the content-addressed store, hash-verified

85
86#[tauri::command]
87pub async fn ssh_connect(
88 state: State<'_, AppState>,
89 mut config: SSHConnectionConfig,
90) -> Result<SSHConnectionResult, String> {
91 log::info!(
92 "ssh_connect called: id={}, host={}, port={}, username={}",
93 config.id,
94 config.host,
95 config.port,
96 config.username
97 );
98
99 let manager = match state.get_ssh_manager_async().await {
100 Ok(m) => {
101 log::info!("ssh_connect: got SSH manager OK");
102 m
103 }
104 Err(e) => {
105 log::error!("ssh_connect: failed to get SSH manager: {}", e);
106 return Err(e.to_string());
107 }
108 };
109
110 if let SSHAuthMethod::Password { ref password } = config.auth {
111 if password.is_empty() {
112 match manager.load_stored_password(&config.id).await {
113 Ok(Some(pwd)) => {
114 config.auth = SSHAuthMethod::Password { password: pwd };
115 }
116 Ok(None) => {
117 return Err(
118 "SSH password is required (no saved password for this connection)"
119 .to_string(),
120 );
121 }
122 Err(e) => return Err(e.to_string()),
123 }
124 }
125 }
126
127 log::info!("ssh_connect: about to establish connection");
128 let config_to_save = config.clone();
129 let result = manager.connect(config).await.map_err(|e| e.to_string());
130 if result.is_ok() {
131 log::info!("ssh_connect: about to save successful connection config");
132 if let Err(e) = manager.save_connection(&config_to_save).await {
133 log::warn!(
134 "ssh_connect: Failed to save successful connection config: {}",
135 e
136 );
137 } else {
138 log::info!("ssh_connect: Connection config saved successfully");
139 }
140 }
141 log::info!("ssh_connect result: {:?}", result);
142 result
143}
144

Callers

nothing calls this directly

Calls 6

get_ssh_manager_asyncMethod · 0.80
connectMethod · 0.65
is_emptyMethod · 0.45
load_stored_passwordMethod · 0.45
cloneMethod · 0.45
save_connectionMethod · 0.45

Tested by

no test coverage detected