Allow passing args to ssh (#19336)
This is useful for passing a custom identity file, jump hosts, etc. Unlike with the v1 feature, we won't support `gh`/`gcloud` ssh wrappers (yet?). I think the right way of supporting those would be to let extensions provide remote projects. Closes #19118 Release Notes: - SSH remoting: restored ability to set arguments for SSH
This commit is contained in:
parent
f1d01d59ac
commit
378a2cf9d8
9 changed files with 216 additions and 89 deletions
|
@ -13,19 +13,19 @@ use futures::channel::oneshot;
|
|||
use futures::future::Shared;
|
||||
use futures::FutureExt;
|
||||
use gpui::canvas;
|
||||
use gpui::pulsating_between;
|
||||
use gpui::AsyncWindowContext;
|
||||
use gpui::ClipboardItem;
|
||||
use gpui::Task;
|
||||
use gpui::WeakView;
|
||||
use gpui::{
|
||||
Animation, AnimationExt, AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle,
|
||||
FocusableView, FontWeight, Model, PromptLevel, ScrollHandle, View, ViewContext,
|
||||
AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle, FocusableView, FontWeight,
|
||||
Model, PromptLevel, ScrollHandle, View, ViewContext,
|
||||
};
|
||||
use picker::Picker;
|
||||
use project::terminals::wrap_for_ssh;
|
||||
use project::terminals::SshCommand;
|
||||
use project::Project;
|
||||
use remote::SshConnectionOptions;
|
||||
use rpc::proto::DevServerStatus;
|
||||
use settings::update_settings_file;
|
||||
use settings::Settings;
|
||||
|
@ -65,8 +65,9 @@ pub struct DevServerProjects {
|
|||
|
||||
struct CreateDevServer {
|
||||
address_editor: View<Editor>,
|
||||
creating: Option<Task<Option<()>>>,
|
||||
address_error: Option<SharedString>,
|
||||
ssh_prompt: Option<View<SshPrompt>>,
|
||||
_creating: Option<Task<Option<()>>>,
|
||||
}
|
||||
|
||||
impl CreateDevServer {
|
||||
|
@ -77,8 +78,9 @@ impl CreateDevServer {
|
|||
});
|
||||
Self {
|
||||
address_editor,
|
||||
creating: None,
|
||||
address_error: None,
|
||||
ssh_prompt: None,
|
||||
_creating: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -378,34 +380,22 @@ impl DevServerProjects {
|
|||
}
|
||||
|
||||
fn create_ssh_server(&mut self, editor: View<Editor>, cx: &mut ViewContext<Self>) {
|
||||
let host = get_text(&editor, cx);
|
||||
if host.is_empty() {
|
||||
let input = get_text(&editor, cx);
|
||||
if input.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut host = host.trim_start_matches("ssh ");
|
||||
let mut username: Option<String> = None;
|
||||
let mut port: Option<u16> = None;
|
||||
|
||||
if let Some((u, rest)) = host.split_once('@') {
|
||||
host = rest;
|
||||
username = Some(u.to_string());
|
||||
}
|
||||
if let Some((rest, p)) = host.split_once(':') {
|
||||
host = rest;
|
||||
port = p.parse().ok()
|
||||
}
|
||||
|
||||
if let Some((rest, p)) = host.split_once(" -p") {
|
||||
host = rest;
|
||||
port = p.trim().parse().ok()
|
||||
}
|
||||
|
||||
let connection_options = remote::SshConnectionOptions {
|
||||
host: host.to_string(),
|
||||
username: username.clone(),
|
||||
port,
|
||||
password: None,
|
||||
let connection_options = match SshConnectionOptions::parse_command_line(&input) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
self.mode = Mode::CreateDevServer(CreateDevServer {
|
||||
address_editor: editor,
|
||||
address_error: Some(format!("could not parse: {:?}", e).into()),
|
||||
ssh_prompt: None,
|
||||
_creating: None,
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
let ssh_prompt = cx.new_view(|cx| SshPrompt::new(&connection_options, cx));
|
||||
|
||||
|
@ -417,6 +407,7 @@ impl DevServerProjects {
|
|||
)
|
||||
.prompt_err("Failed to connect", cx, |_, _| None);
|
||||
|
||||
let address_editor = editor.clone();
|
||||
let creating = cx.spawn(move |this, mut cx| async move {
|
||||
match connection.await {
|
||||
Some(_) => this
|
||||
|
@ -436,18 +427,31 @@ impl DevServerProjects {
|
|||
.log_err(),
|
||||
None => this
|
||||
.update(&mut cx, |this, cx| {
|
||||
this.mode = Mode::CreateDevServer(CreateDevServer::new(cx));
|
||||
address_editor.update(cx, |this, _| {
|
||||
this.set_read_only(false);
|
||||
});
|
||||
this.mode = Mode::CreateDevServer(CreateDevServer {
|
||||
address_editor,
|
||||
address_error: None,
|
||||
ssh_prompt: None,
|
||||
_creating: None,
|
||||
});
|
||||
cx.notify()
|
||||
})
|
||||
.log_err(),
|
||||
};
|
||||
None
|
||||
});
|
||||
let mut state = CreateDevServer::new(cx);
|
||||
state.address_editor = editor;
|
||||
state.ssh_prompt = Some(ssh_prompt.clone());
|
||||
state.creating = Some(creating);
|
||||
self.mode = Mode::CreateDevServer(state);
|
||||
|
||||
editor.update(cx, |this, _| {
|
||||
this.set_read_only(true);
|
||||
});
|
||||
self.mode = Mode::CreateDevServer(CreateDevServer {
|
||||
address_editor: editor,
|
||||
address_error: None,
|
||||
ssh_prompt: Some(ssh_prompt.clone()),
|
||||
_creating: Some(creating),
|
||||
});
|
||||
}
|
||||
|
||||
fn view_server_options(
|
||||
|
@ -547,9 +551,6 @@ impl DevServerProjects {
|
|||
return;
|
||||
}
|
||||
|
||||
state.address_editor.update(cx, |this, _| {
|
||||
this.set_read_only(true);
|
||||
});
|
||||
self.create_ssh_server(state.address_editor.clone(), cx);
|
||||
}
|
||||
Mode::EditNickname(state) => {
|
||||
|
@ -812,6 +813,7 @@ impl DevServerProjects {
|
|||
port: connection_options.port,
|
||||
projects: vec![],
|
||||
nickname: None,
|
||||
args: connection_options.args.unwrap_or_default(),
|
||||
})
|
||||
});
|
||||
}
|
||||
|
@ -825,10 +827,7 @@ impl DevServerProjects {
|
|||
|
||||
state.address_editor.update(cx, |editor, cx| {
|
||||
if editor.text(cx).is_empty() {
|
||||
editor.set_placeholder_text(
|
||||
"Enter the command you use to SSH into this server: e.g., ssh me@my.server",
|
||||
cx,
|
||||
);
|
||||
editor.set_placeholder_text("ssh user@example -p 2222", cx);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -854,27 +853,38 @@ impl DevServerProjects {
|
|||
.map(|this| {
|
||||
if let Some(ssh_prompt) = ssh_prompt {
|
||||
this.child(h_flex().w_full().child(ssh_prompt))
|
||||
} else if let Some(address_error) = &state.address_error {
|
||||
this.child(
|
||||
h_flex().p_2().w_full().gap_2().child(
|
||||
Label::new(address_error.clone())
|
||||
.size(LabelSize::Small)
|
||||
.color(Color::Error),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
let color = Color::Muted.color(cx);
|
||||
this.child(
|
||||
h_flex()
|
||||
.p_2()
|
||||
.w_full()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.gap_2()
|
||||
.gap_1()
|
||||
.child(
|
||||
div().size_1p5().rounded_full().bg(color).with_animation(
|
||||
"pulse-ssh-waiting-for-connection",
|
||||
Animation::new(Duration::from_secs(2))
|
||||
.repeat()
|
||||
.with_easing(pulsating_between(0.2, 0.5)),
|
||||
move |this, progress| this.bg(color.opacity(progress)),
|
||||
),
|
||||
Label::new(
|
||||
"Enter the command you use to SSH into this server.",
|
||||
)
|
||||
.color(Color::Muted)
|
||||
.size(LabelSize::Small),
|
||||
)
|
||||
.child(
|
||||
Label::new("Waiting for connection…")
|
||||
.size(LabelSize::Small),
|
||||
Button::new("learn-more", "Learn more…")
|
||||
.label_size(LabelSize::Small)
|
||||
.size(ButtonSize::None)
|
||||
.color(Color::Accent)
|
||||
.style(ButtonStyle::Transparent)
|
||||
.on_click(|_, cx| {
|
||||
cx.open_url(
|
||||
"https://zed.dev/docs/remote-development",
|
||||
);
|
||||
}),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ use picker::{
|
|||
use rpc::proto::DevServerStatus;
|
||||
use serde::Deserialize;
|
||||
use settings::Settings;
|
||||
use ssh_connections::SshSettings;
|
||||
pub use ssh_connections::SshSettings;
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
|
@ -384,11 +384,13 @@ impl PickerDelegate for RecentProjectsDelegate {
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
let args = SshSettings::get_global(cx).args_for(&ssh_project.host, ssh_project.port, &ssh_project.user);
|
||||
let connection_options = SshConnectionOptions {
|
||||
host: ssh_project.host.clone(),
|
||||
username: ssh_project.user.clone(),
|
||||
port: ssh_project.port,
|
||||
password: None,
|
||||
args,
|
||||
};
|
||||
|
||||
let paths = ssh_project.paths.iter().map(PathBuf::from).collect();
|
||||
|
|
|
@ -32,6 +32,23 @@ impl SshSettings {
|
|||
pub fn ssh_connections(&self) -> impl Iterator<Item = SshConnection> {
|
||||
self.ssh_connections.clone().into_iter().flatten()
|
||||
}
|
||||
|
||||
pub fn args_for(
|
||||
&self,
|
||||
host: &str,
|
||||
port: Option<u16>,
|
||||
user: &Option<String>,
|
||||
) -> Option<Vec<String>> {
|
||||
self.ssh_connections()
|
||||
.filter_map(|conn| {
|
||||
if conn.host == host && &conn.username == user && conn.port == port {
|
||||
Some(conn.args)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.next()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
|
||||
|
@ -45,6 +62,9 @@ pub struct SshConnection {
|
|||
/// Name to use for this server in UI.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub nickname: Option<SharedString>,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
#[serde(default)]
|
||||
pub args: Vec<String>,
|
||||
}
|
||||
impl From<SshConnection> for SshConnectionOptions {
|
||||
fn from(val: SshConnection) -> Self {
|
||||
|
@ -53,6 +73,7 @@ impl From<SshConnection> for SshConnectionOptions {
|
|||
username: val.username,
|
||||
port: val.port,
|
||||
password: None,
|
||||
args: Some(val.args),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -151,11 +172,9 @@ impl Render for SshPrompt {
|
|||
v_flex()
|
||||
.key_context("PasswordPrompt")
|
||||
.size_full()
|
||||
.justify_center()
|
||||
.child(
|
||||
h_flex()
|
||||
.p_2()
|
||||
.justify_center()
|
||||
.flex_wrap()
|
||||
.child(if self.error_message.is_some() {
|
||||
Icon::new(IconName::XCircle)
|
||||
|
@ -174,24 +193,19 @@ impl Render for SshPrompt {
|
|||
)
|
||||
.into_any_element()
|
||||
})
|
||||
.child(
|
||||
div()
|
||||
.ml_1()
|
||||
.child(Label::new("SSH Connection").size(LabelSize::Small)),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.text_ellipsis()
|
||||
.overflow_x_hidden()
|
||||
.when_some(self.error_message.as_ref(), |el, error| {
|
||||
el.child(Label::new(format!("-{}", error)).size(LabelSize::Small))
|
||||
el.child(Label::new(format!("{}", error)).size(LabelSize::Small))
|
||||
})
|
||||
.when(
|
||||
self.error_message.is_none() && self.status_message.is_some(),
|
||||
|el| {
|
||||
el.child(
|
||||
Label::new(format!(
|
||||
"-{}",
|
||||
"-{}…",
|
||||
self.status_message.clone().unwrap()
|
||||
))
|
||||
.size(LabelSize::Small),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue