mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
A command is now declared once, on the fn that implements it. A project-host command is an ide-host fn with #[command(trust = …)] listed in its module's domain!; its Tauri adapter, bindings entry, JSON-RPC handler, trust class and remote routing are derived from that declaration. Desktop-only commands keep their Tauri fn and add #[desktop_command(trust = …)]. This removes the hand-written pass-through adapters, collect_commands!, the per-domain register fns and the trust tables in trust.rs. The invoke handler looks up each command's declared trust class; a name nothing declares is denied. A remote window routes the project-host commands of the desktop's own build. Duplicate names are a compile error. CI runs ide-command's compile_fail doctests. Part of #3344. Co-authored-by: Mr0Bread <55754540+Mr0Bread@users.noreply.github.com>
61 lines
2.0 KiB
Rust
61 lines
2.0 KiB
Rust
//! SSH configuration commands shared by the desktop shell's IPC commands and the remote
|
|
//! server ([`crate::rpc`]). A remote window connects from the server (deployment, database
|
|
//! tunnels, run targets, SSH sessions), so the host keys it trusts and the passwords it is
|
|
//! given belong to the server's [`ide_ssh::SshManager`], not the desktop's.
|
|
use crate::Host;
|
|
use ide_command::command;
|
|
use ide_core::IdeResult;
|
|
use ide_core::remote_settings::SshConfiguration;
|
|
|
|
/// Test Connection: connects with `config` as edited (not necessarily saved).
|
|
#[command(trust = always)]
|
|
pub async fn ssh_test(host: &Host, config: SshConfiguration, secret: Option<String>) -> IdeResult<String> {
|
|
host.ssh.test(&config, secret).await
|
|
}
|
|
|
|
/// Remembers the password / passphrase of configuration `id` (`None` forgets it).
|
|
#[command(trust = always)]
|
|
pub fn ssh_set_secret(host: &Host, id: String, secret: Option<String>, save: bool) {
|
|
host.ssh.set_secret(&id, secret, save);
|
|
}
|
|
|
|
/// Whether a password is saved under `key` (an FTP deployment server's).
|
|
#[command(trust = always)]
|
|
pub fn ssh_password_saved(host: &Host, key: String) -> bool {
|
|
host.ssh.password_saved(&key)
|
|
}
|
|
|
|
/// Whether connecting with configuration `id` needs a password first.
|
|
#[command(trust = always)]
|
|
pub fn ssh_needs_secret(host: &Host, id: String) -> IdeResult<bool> {
|
|
Ok(host.ssh.needs_secret(&host.ssh.config(&id)?))
|
|
}
|
|
|
|
/// Trusts the host key that failed the last connection of configuration `id`.
|
|
#[command(trust = always)]
|
|
pub async fn ssh_trust_host(host: &Host, id: String) -> IdeResult<()> {
|
|
host.ssh.trust_host(&id).await
|
|
}
|
|
|
|
/// Ids of the configurations with an open connection.
|
|
#[command(trust = always)]
|
|
pub fn ssh_connected(host: &Host) -> Vec<String> {
|
|
host.ssh.connected()
|
|
}
|
|
|
|
#[command(trust = always)]
|
|
pub fn ssh_disconnect(host: &Host, id: String) {
|
|
host.ssh.disconnect(&id);
|
|
}
|
|
|
|
ide_command::domain!(
|
|
ssh:
|
|
ssh_connected,
|
|
ssh_disconnect,
|
|
ssh_needs_secret,
|
|
ssh_password_saved,
|
|
ssh_set_secret,
|
|
ssh_test,
|
|
ssh_trust_host,
|
|
);
|