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

Re-introduce rustls feature and add a native-tls feature #768

Merged
merged 1 commit into from
Jan 9, 2022
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
84 changes: 84 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,19 @@ semver = "1.0.4"
configparser = { version = "3.0.0", optional = true }
multipart = { version = "0.18.0", features = ["client"], default-features = false, optional = true }
rpassword = { version = "5.0.1", optional = true }
ureq = { version = "2.3.1", optional = true }
ureq = { version = "2.3.1", features = ["gzip"], default-features = false, optional = true }
native-tls-crate = { package = "native-tls", version = "0.2.8", optional = true }

[dev-dependencies]
indoc = "1.0.3"

[features]
default = ["log", "upload", "human-panic"]
default = ["log", "upload", "rustls", "human-panic"]
upload = ["ureq", "multipart", "rpassword", "configparser"]
password-storage = ["upload", "keyring"]
log = ["pretty_env_logger"]
rustls = ["ureq/tls"]
native-tls = ["ureq/native-tls", "native-tls-crate"]
# Internal feature to speed up the tests significantly
faster-tests = []

Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
//!
//! # Cargo features
//!
//! Default features: log, upload, human-panic
//! Default features: log, upload, rustls, human-panic
//!
//! - log: Configures pretty-env-logger, even though maturin doesn't use logging itself.
//!
//! - upload: Uses ureq to add the upload command.
//!
//! - rustls: Makes ureq use the rustls stack so that we can build maturin in a CentOS 6
//! docker container and which maturin itself manylinux compliant.
//!
//! - native-tls: Makes ureq use the platform native tls stack
//!
//! - human-panic: Adds https://github.com/rust-clique/human-panic
//!
//! - password-storage (off by default): Uses the keyring package to store the password. keyring
Expand Down
26 changes: 25 additions & 1 deletion src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ pub enum UploadError {
/// Read package metadata error
#[error("Could not read the metadata from the package at {0}")]
PkgInfoError(PathBuf, #[source] python_pkginfo::Error),
/// TLS error
#[cfg(feature = "native-tls")]
#[error("TLS Error")]
TlsError(#[source] native_tls_crate::Error),
}

impl From<io::Error> for UploadError {
Expand All @@ -77,6 +81,13 @@ impl From<ureq::Error> for UploadError {
}
}

#[cfg(feature = "native-tls")]
impl From<native_tls_crate::Error> for UploadError {
fn from(error: native_tls_crate::Error) -> Self {
UploadError::TlsError(error)
}
}

/// A pip registry such as pypi or testpypi with associated credentials, used
/// for uploading wheels
#[derive(Debug, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -300,7 +311,20 @@ pub fn upload(registry: &Registry, wheel_path: &Path) -> Result<(), UploadError>
let multipart_data = form.prepare().map_err(|e| e.error)?;

let encoded = base64::encode(&format!("{}:{}", registry.username, registry.password));
let response = ureq::post(registry.url.as_str())

#[cfg(not(feature = "native-tls"))]
let agent = ureq::agent();

#[cfg(feature = "native-tls")]
let agent = {
use std::sync::Arc;
ureq::builder()
.tls_connector(Arc::new(native_tls_crate::TlsConnector::new()?))
.build()
};

let response = agent
.post(registry.url.as_str())
.set(
"Content-Type",
&format!(
Expand Down