Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(services/sftp): add more explanation for endpoint config #4055

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading