Skip to content

Commit

Permalink
removed unused fields
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Oct 10, 2022
1 parent 6f1eaec commit b353852
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ documentation = "https://docs.rs/remotefs-ftp"
edition = "2021"
homepage = "https://veeso.github.io/remotefs-rs-ftp/"
include = ["src/**/*", "LICENSE", "README.md", "CHANGELOG.md"]
keywords = ["remotefs", "s3-client"]
keywords = ["remotefs", "ftp-client"]
license = "MIT"
name = "remotefs-ftp"
readme = "README.md"
Expand Down
28 changes: 23 additions & 5 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ pub struct FtpFs {
#[cfg(any(feature = "native-tls", feature = "rustls"))]
/// use FTPS; default: `false`
secure: bool,
#[cfg(any(feature = "native-tls", feature = "rustls"))]
#[cfg(feature = "native-tls")]
/// Accept invalid certificates when building TLS connector. (Applies only if `secure`). Default: `false`
accept_invalid_certs: bool,
#[cfg(any(feature = "native-tls", feature = "rustls"))]
#[cfg(feature = "native-tls")]
/// Accept invalid hostnames when building TLS connector. (Applies only if `secure`). Default: `false`
accept_invalid_hostnames: bool,
}
Expand All @@ -59,9 +59,9 @@ impl FtpFs {
mode: Mode::Passive,
#[cfg(any(feature = "native-tls", feature = "rustls"))]
secure: false,
#[cfg(any(feature = "native-tls", feature = "rustls"))]
#[cfg(feature = "native-tls")]
accept_invalid_certs: false,
#[cfg(any(feature = "native-tls", feature = "rustls"))]
#[cfg(feature = "native-tls")]
accept_invalid_hostnames: false,
}
}
Expand Down Expand Up @@ -92,7 +92,7 @@ impl FtpFs {
self
}

#[cfg(any(feature = "native-tls", feature = "rustls"))]
#[cfg(feature = "native-tls")]
/// enable FTPS and configure options
pub fn secure(mut self, accept_invalid_certs: bool, accept_invalid_hostnames: bool) -> Self {
self.secure = true;
Expand All @@ -101,6 +101,12 @@ impl FtpFs {
self
}

#[cfg(feature = "rustls")]
pub fn secure(mut self) -> Self {
self.secure = true;
self
}

// -- as_ref

/// Get reference to inner stream
Expand Down Expand Up @@ -232,7 +238,9 @@ impl RemoteFs for FtpFs {
#[cfg(any(feature = "native-tls", feature = "rustls"))]
if self.secure {
debug!("Setting up TLS stream...");
#[cfg(feature = "native-tls")]
trace!("Accept invalid certs: {}", self.accept_invalid_certs);
#[cfg(feature = "native-tls")]
trace!(
"Accept invalid hostnames: {}",
self.accept_invalid_hostnames
Expand Down Expand Up @@ -556,20 +564,30 @@ mod test {
#[test]
#[cfg(any(feature = "native-tls", feature = "rustls"))]
fn should_build_secure_ftp_filesystem() {
#[cfg(feature = "native-tls")]
let client = FtpFs::new("127.0.0.1", 21)
.username("test")
.password("omar")
.secure(true, true)
.passive_mode()
.active_mode();
#[cfg(feature = "rustls")]
let client = FtpFs::new("127.0.0.1", 21)
.username("test")
.password("omar")
.secure()
.passive_mode()
.active_mode();
assert!(client.stream.is_none());
assert_eq!(client.hostname.as_str(), "127.0.0.1");
assert_eq!(client.port, 21);
assert_eq!(client.username.as_str(), "test");
assert_eq!(client.password.as_deref().unwrap(), "omar");
assert_eq!(client.mode, Mode::Active);
assert_eq!(client.secure, true);
#[cfg(feature = "native-tls")]
assert_eq!(client.accept_invalid_certs, true);
#[cfg(feature = "native-tls")]
assert_eq!(client.accept_invalid_hostnames, true);
}

Expand Down

0 comments on commit b353852

Please sign in to comment.