From 44b0dc065c8bce2408b7c52c33b6dd301b20a3c8 Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Tue, 16 Aug 2022 14:57:01 -0600 Subject: [PATCH] Split fallback_scheme into launch and connect choices --- CHANGELOG.md | 8 ++++++++ distant-core/src/manager/data/destination.rs | 8 ++++++++ distant-core/src/manager/server.rs | 8 ++++---- distant-core/src/manager/server/config.rs | 14 +++++++++++--- src/cli/commands/client.rs | 13 ++++++++++++- 5 files changed, 43 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8cab9e..5dab1b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added + +- `replace_scheme` method to `Destination` ### Fixed @@ -16,6 +19,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Map` implementation of `Display` now escapes `\` and `"` - `Map` implementation of `FromStr` now handles escaped `\` and `"` +- Split `fallback_scheme` for `DistantManagerConfig` into + `launch_fallback_scheme` (defaulting to ssh) and `connect_fallback_scheme` + (defaulting to distant); this means that subsequent use of + `distant client launch [user@]host[:port]` will now default to ssh instead of + failing due to lack of distant launch handler ## [0.17.1] - 2022-08-16 ### Added diff --git a/distant-core/src/manager/data/destination.rs b/distant-core/src/manager/data/destination.rs index 3dbbebe..8d5f537 100644 --- a/distant-core/src/manager/data/destination.rs +++ b/distant-core/src/manager/data/destination.rs @@ -29,6 +29,14 @@ impl Destination { self.0.scheme().map(Scheme::as_str) } + /// Replaces the current scheme of the destination with the provided scheme, returning the old + /// scheme as a string if it existed + pub fn replace_scheme(&mut self, scheme: &str) -> Result, URIReferenceError> { + self.0 + .set_scheme(Some(Scheme::try_from(scheme).map(Scheme::into_owned)?)) + .map(|s| s.map(|s| s.to_string())) + } + /// Returns the host of the destination as a string pub fn to_host_string(&self) -> String { // NOTE: We guarantee that there is a host for a destination during construction diff --git a/distant-core/src/manager/server.rs b/distant-core/src/manager/server.rs index e1c5da2..8e6e17a 100644 --- a/distant-core/src/manager/server.rs +++ b/distant-core/src/manager/server.rs @@ -148,9 +148,9 @@ impl DistantManager { None => { trace!( "Using fallback scheme of {}", - self.config.fallback_scheme.as_str() + self.config.launch_fallback_scheme.as_str() ); - self.config.fallback_scheme.as_str() + self.config.launch_fallback_scheme.as_str() } } .to_lowercase(); @@ -193,9 +193,9 @@ impl DistantManager { None => { trace!( "Using fallback scheme of {}", - self.config.fallback_scheme.as_str() + self.config.connect_fallback_scheme.as_str() ); - self.config.fallback_scheme.as_str() + self.config.connect_fallback_scheme.as_str() } } .to_lowercase(); diff --git a/distant-core/src/manager/server/config.rs b/distant-core/src/manager/server/config.rs index 207cb27..419940e 100644 --- a/distant-core/src/manager/server/config.rs +++ b/distant-core/src/manager/server/config.rs @@ -2,8 +2,11 @@ use crate::{BoxedConnectHandler, BoxedLaunchHandler}; use std::collections::HashMap; pub struct DistantManagerConfig { - /// Scheme to use when none is provided in a destination - pub fallback_scheme: String, + /// Scheme to use when none is provided in a destination for launch + pub launch_fallback_scheme: String, + + /// Scheme to use when none is provided in a destination for connect + pub connect_fallback_scheme: String, /// Buffer size for queue of incoming connections before blocking pub connection_buffer_size: usize, @@ -21,7 +24,12 @@ pub struct DistantManagerConfig { impl Default for DistantManagerConfig { fn default() -> Self { Self { - fallback_scheme: "distant".to_string(), + // Default to using ssh to launch distant + launch_fallback_scheme: "ssh".to_string(), + + // Default to distant server when connecting + connect_fallback_scheme: "distant".to_string(), + connection_buffer_size: 100, user: false, launch_handlers: HashMap::new(), diff --git a/src/cli/commands/client.rs b/src/cli/commands/client.rs index 60f8ddb..73bcdc9 100644 --- a/src/cli/commands/client.rs +++ b/src/cli/commands/client.rs @@ -421,7 +421,7 @@ impl ClientSubcommand { config: launcher_config, network, format, - destination, + mut destination, .. } => { let network = network.merge(config.network); @@ -445,6 +445,17 @@ impl ClientSubcommand { // Grab the host we are connecting to for later use let host = destination.to_host_string(); + // If we have no scheme on launch, we need to fill it in with something + // + // TODO: Can we have the server support this instead of the client? Right now, the + // server is failing because it cannot parse //localhost/ as it fails with + // an invalid IPv4 or registered name character error on host + if destination.scheme().is_none() { + destination + .replace_scheme("ssh") + .context("Failed to set a default scheme for a scheme-less destination")?; + } + // Start the server using our manager debug!("Launching server at {} with {}", destination, extra); let mut new_destination = client