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

Restore seeding of authentication cache from index URLs #3124

Merged
merged 1 commit into from
Apr 19, 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
16 changes: 16 additions & 0 deletions crates/uv-auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,32 @@ mod keyring;
mod middleware;
mod netloc;

use std::sync::Arc;

use cache::CredentialsCache;
use credentials::Credentials;

pub use keyring::KeyringProvider;
pub use middleware::AuthMiddleware;
use netloc::NetLoc;
use once_cell::sync::Lazy;
use url::Url;

// TODO(zanieb): Consider passing a cache explicitly throughout

/// Global authentication cache for a uv invocation
///
/// This is used to share credentials across uv clients.
pub(crate) static CREDENTIALS_CACHE: Lazy<CredentialsCache> = Lazy::new(CredentialsCache::default);

/// Populate the global authentication store with credentials on a URL, if there are any.
///
/// Returns `true` if the store was updated.
pub fn store_credentials_from_url(url: &Url) -> bool {
if let Some(credentials) = Credentials::from_url(url) {
CREDENTIALS_CACHE.insert(url, Arc::new(credentials));
true
} else {
false
}
}
6 changes: 6 additions & 0 deletions crates/uv/src/commands/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use distribution_types::{IndexLocations, LocalEditable, LocalEditables, Verbatim
use install_wheel_rs::linker::LinkMode;
use platform_tags::Tags;
use requirements_txt::EditableRequirement;
use uv_auth::store_credentials_from_url;
use uv_cache::Cache;
use uv_client::{BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClientBuilder};
use uv_configuration::KeyringProviderType;
Expand Down Expand Up @@ -219,6 +220,11 @@ pub(crate) async fn pip_compile(
let index_locations =
index_locations.combine(index_url, extra_index_urls, find_links, no_index);

// Add all authenticated sources to the cache.
for url in index_locations.urls() {
store_credentials_from_url(url);
}

// Initialize the registry client.
let client = RegistryClientBuilder::new(cache.clone())
.native_tls(native_tls)
Expand Down
6 changes: 6 additions & 0 deletions crates/uv/src/commands/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use pep508_rs::{MarkerEnvironment, Requirement};
use platform_tags::Tags;
use pypi_types::{Metadata23, Yanked};
use requirements_txt::EditableRequirement;
use uv_auth::store_credentials_from_url;
use uv_cache::Cache;
use uv_client::{
BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClient, RegistryClientBuilder,
Expand Down Expand Up @@ -203,6 +204,11 @@ pub(crate) async fn pip_install(
let index_locations =
index_locations.combine(index_url, extra_index_urls, find_links, no_index);

// Add all authenticated sources to the cache.
for url in index_locations.urls() {
store_credentials_from_url(url);
}

// Initialize the registry client.
let client = RegistryClientBuilder::new(cache.clone())
.native_tls(native_tls)
Expand Down
6 changes: 6 additions & 0 deletions crates/uv/src/commands/pip_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use install_wheel_rs::linker::LinkMode;
use platform_tags::Tags;
use pypi_types::Yanked;
use requirements_txt::EditableRequirement;
use uv_auth::store_credentials_from_url;
use uv_cache::{ArchiveTarget, ArchiveTimestamp, Cache};
use uv_client::{
BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClient, RegistryClientBuilder,
Expand Down Expand Up @@ -150,6 +151,11 @@ pub(crate) async fn pip_sync(
let index_locations =
index_locations.combine(index_url, extra_index_urls, find_links, no_index);

// Add all authenticated sources to the cache.
for url in index_locations.urls() {
store_credentials_from_url(url);
}

// Initialize the registry client.
let client = RegistryClientBuilder::new(cache.clone())
.native_tls(native_tls)
Expand Down
6 changes: 6 additions & 0 deletions crates/uv/src/commands/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use thiserror::Error;
use distribution_types::{DistributionMetadata, IndexLocations, Name, ResolvedDist};
use install_wheel_rs::linker::LinkMode;
use pep508_rs::Requirement;
use uv_auth::store_credentials_from_url;
use uv_cache::Cache;
use uv_client::{Connectivity, FlatIndexClient, RegistryClientBuilder};
use uv_configuration::KeyringProviderType;
Expand Down Expand Up @@ -119,6 +120,11 @@ async fn venv_impl(
find_default_python(cache).into_diagnostic()?
};

// Add all authenticated sources to the cache.
for url in index_locations.urls() {
store_credentials_from_url(url);
}

writeln!(
printer.stderr(),
"Using Python {} interpreter at: {}",
Expand Down
Loading