Skip to content

Commit

Permalink
docs(services/sftp): add more explanation for endpoint config (#4055)
Browse files Browse the repository at this point in the history
Signed-off-by: Mingzhuo Yin <yinmingzhuo@gmail.com>
  • Loading branch information
silver-ymz authored Jan 23, 2024
1 parent 126622f commit 409a25a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions core/src/services/sftp/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/sftp/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 409a25a

Please sign in to comment.