Skip to content

Commit

Permalink
Add argument
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Mar 11, 2024
1 parent e18fb29 commit 628672b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -423,7 +423,7 @@ In addition, uv respects the following environment variables:

uv supports custom CA certificates (such as those needed by corporate proxies) by utilizing the
system's trust store. To ensure this works out of the box, ensure your certificates are added to the
system's trust store.
system's trust store, and run uv with the `--native-tls` command-line Flag.

If a direct path to the certificate is required (e.g., in CI), set the `SSL_CERT_FILE` environment
variable to the path of the certificate bundle, to instruct uv to use that file instead of the
Expand Down
2 changes: 2 additions & 0 deletions crates/uv-client/Cargo.toml
Expand Up @@ -48,6 +48,8 @@ tokio-util = { workspace = true }
tracing = { workspace = true }
url = { workspace = true }
urlencoding = { workspace = true }

# These must be kept in-sync with those used by `reqwest`.
rustls = { version = "0.21.10" }
rustls-native-certs = { version = "0.6.3" }
webpki-roots = { version = "0.25.4" }
Expand Down
10 changes: 5 additions & 5 deletions crates/uv-client/src/registry_client.rs
Expand Up @@ -39,7 +39,7 @@ use crate::{CachedClient, CachedClientError, Error, ErrorKind};
#[derive(Debug, Clone)]
pub struct RegistryClientBuilder {
index_urls: IndexUrls,
native_roots: bool,
native_tls: bool,
retries: u32,
connectivity: Connectivity,
cache: Cache,
Expand All @@ -50,7 +50,7 @@ impl RegistryClientBuilder {
pub fn new(cache: Cache) -> Self {
Self {
index_urls: IndexUrls::default(),
native_roots: false,
native_tls: false,
cache,
connectivity: Connectivity::Online,
retries: 3,
Expand Down Expand Up @@ -79,8 +79,8 @@ impl RegistryClientBuilder {
}

#[must_use]
pub fn native_roots(mut self, native_roots: bool) -> Self {
self.native_roots = native_roots;
pub fn native_tls(mut self, native_tls: bool) -> Self {
self.native_tls = native_tls;
self
}

Expand Down Expand Up @@ -120,7 +120,7 @@ impl RegistryClientBuilder {
// Initialize the base client.
let client = self.client.unwrap_or_else(|| {
// Load the TLS configuration.
let roots = if self.native_roots {
let roots = if self.native_tls {
Roots::Native
} else {
Roots::Webpki
Expand Down
2 changes: 2 additions & 0 deletions crates/uv/src/commands/pip_compile.rs
Expand Up @@ -67,6 +67,7 @@ pub(crate) async fn pip_compile(
python_version: Option<PythonVersion>,
exclude_newer: Option<DateTime<Utc>>,
annotation_style: AnnotationStyle,
native_tls: bool,
quiet: bool,
cache: Cache,
printer: Printer,
Expand Down Expand Up @@ -188,6 +189,7 @@ pub(crate) async fn pip_compile(

// Initialize the registry client.
let client = RegistryClientBuilder::new(cache.clone())
.native_tls(native_tls)
.connectivity(connectivity)
.index_urls(index_locations.index_urls())
.build();
Expand Down
2 changes: 2 additions & 0 deletions crates/uv/src/commands/pip_install.rs
Expand Up @@ -67,6 +67,7 @@ pub(crate) async fn pip_install(
python: Option<String>,
system: bool,
break_system_packages: bool,
native_tls: bool,
cache: Cache,
printer: Printer,
) -> Result<ExitStatus> {
Expand Down Expand Up @@ -177,6 +178,7 @@ pub(crate) async fn pip_install(

// Initialize the registry client.
let client = RegistryClientBuilder::new(cache.clone())
.native_tls(native_tls)
.connectivity(connectivity)
.index_urls(index_locations.index_urls())
.build();
Expand Down
2 changes: 2 additions & 0 deletions crates/uv/src/commands/pip_sync.rs
Expand Up @@ -45,6 +45,7 @@ pub(crate) async fn pip_sync(
python: Option<String>,
system: bool,
break_system_packages: bool,
native_tls: bool,
cache: Cache,
printer: Printer,
) -> Result<ExitStatus> {
Expand Down Expand Up @@ -116,6 +117,7 @@ pub(crate) async fn pip_sync(

// Initialize the registry client.
let client = RegistryClientBuilder::new(cache.clone())
.native_tls(native_tls)
.connectivity(connectivity)
.index_urls(index_locations.index_urls())
.build();
Expand Down
10 changes: 10 additions & 0 deletions crates/uv/src/main.rs
Expand Up @@ -88,6 +88,13 @@ struct Cli {
)]
color: ColorChoice,

/// Whether to load TLS certificates from the platform's native certificate store.
///
/// By default, `uv` loads certificates from the bundled `webpki-roots` crate, which contains
/// Mozilla's root certificates.
#[arg(global = true, long)]
native_tls: bool,

#[command(flatten)]
cache_args: CacheArgs,
}
Expand Down Expand Up @@ -1384,6 +1391,7 @@ async fn run() -> Result<ExitStatus> {
args.python_version,
args.exclude_newer,
args.annotation_style,
cli.native_tls,
cli.quiet,
cache,
printer,
Expand Down Expand Up @@ -1440,6 +1448,7 @@ async fn run() -> Result<ExitStatus> {
args.python,
args.system,
args.break_system_packages,
cli.native_tls,
cache,
printer,
)
Expand Down Expand Up @@ -1535,6 +1544,7 @@ async fn run() -> Result<ExitStatus> {
args.python,
args.system,
args.break_system_packages,
cli.native_tls,
cache,
printer,
)
Expand Down

0 comments on commit 628672b

Please sign in to comment.