This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 409a25aa11 docs(services/sftp): add more explanation for endpoint
config (#4055)
409a25aa11 is described below
commit 409a25aa11eeaee7bbf1cf2a9e96188569e48e7e
Author: Mingzhuo Yin <[email protected]>
AuthorDate: Tue Jan 23 13:22:44 2024 +0800
docs(services/sftp): add more explanation for endpoint config (#4055)
Signed-off-by: Mingzhuo Yin <[email protected]>
---
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 3658922ef8..beb843110b 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<String>,
key: Option<String>,
known_hosts_strategy: KnownHosts,
copyable: bool,
@@ -500,13 +498,15 @@ impl SftpBackend {
async fn connect_sftp(
endpoint: &str,
root: String,
- user: String,
+ user: Option<String>,
key: Option<String>,
known_hosts_strategy: KnownHosts,
) -> Result<Sftp> {
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 87c1effb19..d80bb0679f 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