From a3b5ca711e095314b96499120092ffdc21a54b85 Mon Sep 17 00:00:00 2001 From: Mingzhuo Yin Date: Tue, 23 Jan 2024 13:13:12 +0800 Subject: [PATCH] docs(services/sftp): add more explanation for endpoint config Signed-off-by: Mingzhuo Yin --- core/src/services/sftp/backend.rs | 14 +++++++------- core/src/services/sftp/docs.md | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/src/services/sftp/backend.rs b/core/src/services/sftp/backend.rs index 3658922ef87..beb843110be 100644 --- a/core/src/services/sftp/backend.rs +++ b/core/src/services/sftp/backend.rs @@ -94,6 +94,7 @@ impl Debug for SftpBuilder { impl SftpBuilder { /// set endpoint for sftp backend. + /// The format is same as `openssh`, using either `[user@]hostname` or `ssh://[user@]hostname[:port]`. A username or port that is specified in the endpoint overrides the one set in the builder (but does not change the builder). pub fn endpoint(&mut self, endpoint: &str) -> &mut Self { self.config.endpoint = if endpoint.is_empty() { None @@ -173,10 +174,7 @@ impl Builder for SftpBuilder { None => return Err(Error::new(ErrorKind::ConfigInvalid, "endpoint is empty")), }; - let user = match self.config.user.clone() { - Some(v) => v, - None => return Err(Error::new(ErrorKind::ConfigInvalid, "user is empty")), - }; + let user = self.config.user.clone(); let root = self .config @@ -229,7 +227,7 @@ impl Builder for SftpBuilder { pub struct SftpBackend { endpoint: String, root: String, - user: String, + user: Option, key: Option, known_hosts_strategy: KnownHosts, copyable: bool, @@ -500,13 +498,15 @@ impl SftpBackend { async fn connect_sftp( endpoint: &str, root: String, - user: String, + user: Option, key: Option, known_hosts_strategy: KnownHosts, ) -> Result { let mut session = SessionBuilder::default(); - session.user(user); + if let Some(user) = user { + session.user(user); + } if let Some(key) = &key { session.keyfile(key); diff --git a/core/src/services/sftp/docs.md b/core/src/services/sftp/docs.md index 87c1effb197..d80bb0679f0 100644 --- a/core/src/services/sftp/docs.md +++ b/core/src/services/sftp/docs.md @@ -17,7 +17,7 @@ This service can be used to: ## Configuration -- `endpoint`: Set the endpoint for connection +- `endpoint`: Set the endpoint for connection. The format is same as `openssh`, using either `[user@]hostname` or `ssh://[user@]hostname[:port]`. A username or port that is specified in the endpoint overrides the one set in the builder (but does not change the builder). - `root`: Set the work directory for backend. It uses the default directory set by the remote `sftp-server` as default - `user`: Set the login user - `key`: Set the public key for login