Skip to content

Commit 6186dcb

Browse files
authored
remove pyx authentication (#21186)
1 parent f61b300 commit 6186dcb

21 files changed

Lines changed: 24 additions & 1744 deletions

File tree

‎Cargo.lock‎

Lines changed: 0 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ md-5 = { version = "0.11.0" }
179179
memchr = { version = "2.7.4" }
180180
miette = { version = "7.2.0", features = ["fancy-no-backtrace"] }
181181
nix = { version = "0.31.2", features = ["resource", "signal"] }
182-
open = { version = "5.4.0" }
183182
owo-colors = { version = "4.1.0" }
184183
papaya = { version = "0.2.4" }
185184
path-slash = { version = "0.2.1" }
@@ -288,7 +287,6 @@ tracing-tree = { version = "0.4.0" }
288287
unicode-width = { version = "0.2.0" }
289288
unscanny = { version = "0.1.0" }
290289
url = { version = "2.5.2", features = ["serde"] }
291-
uuid = { version = "1.16.0" }
292290
version-ranges = { version = "0.2.2", package = "astral-version-ranges" }
293291
walkdir = { version = "2.5.0" }
294292
webpki-root-certs = { version = "1" }

‎crates/uv-auth/Cargo.toml‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ doctest = false
1616
workspace = true
1717

1818
[dependencies]
19-
uv-cache-key = { workspace = true }
2019
uv-fs = { workspace = true }
2120
uv-keyring = { workspace = true, features = ["apple-native", "secret-service", "windows-native"] }
2221
uv-netrc = { workspace = true }
@@ -29,21 +28,17 @@ uv-static = { workspace = true }
2928
uv-warnings = { workspace = true }
3029

3130
anyhow = { workspace = true }
32-
arcstr = { workspace = true }
3331
async-trait = { workspace = true }
3432
base64 = { workspace = true }
35-
etcetera = { workspace = true }
3633
fs-err = { workspace = true, features = ["tokio"] }
3734
http = { workspace = true }
38-
jiff = { workspace = true }
3935
percent-encoding = { workspace = true }
4036
reqsign = { workspace = true }
4137
reqwest = { workspace = true }
4238
reqwest-middleware = { workspace = true }
4339
rustc-hash = { workspace = true }
4440
schemars = { workspace = true, optional = true }
4541
serde = { workspace = true, features = ["derive"] }
46-
serde_json = { workspace = true }
4742
thiserror = { workspace = true }
4843
tokio = { workspace = true }
4944
toml = { workspace = true }

‎crates/uv-auth/src/access_token.rs‎

Lines changed: 0 additions & 34 deletions
This file was deleted.

‎crates/uv-auth/src/credentials.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl Credentials {
382382
/// Attach the credentials to the given request.
383383
///
384384
/// Any existing credentials will be overridden.
385-
pub fn authenticate(&self, mut request: Request) -> Result<Request, InvalidHeaderValue> {
385+
fn authenticate(&self, mut request: Request) -> Result<Request, InvalidHeaderValue> {
386386
request
387387
.headers_mut()
388388
.insert(reqwest::header::AUTHORIZATION, Self::to_header_value(self)?);

‎crates/uv-auth/src/lib.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
1-
pub use access_token::AccessToken;
21
pub use cache::CredentialsCache;
32
pub use credentials::{Credentials, CredentialsFromUrlError, Username};
43
pub use index::{AuthPolicy, Index, Indexes};
54
pub use keyring::KeyringProvider;
65
pub use middleware::AuthMiddleware;
7-
pub use pyx::{
8-
DEFAULT_TOLERANCE_SECS, PyxJwt, PyxOAuthTokens, PyxTokenStore, PyxTokens, TokenStoreError,
9-
is_default_pyx_domain,
10-
};
116
pub use realm::{Realm, RealmRef};
127
pub use service::Service;
138
pub use store::{AuthBackend, TextCredentialStore, TomlCredentialError};
149

15-
mod access_token;
1610
mod cache;
1711
mod credentials;
1812
mod index;
1913
mod keyring;
2014
mod middleware;
2115
mod providers;
22-
mod pyx;
2316
mod realm;
2417
mod service;
2518
mod store;

‎crates/uv-auth/src/middleware.rs‎

Lines changed: 4 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,20 @@ use std::sync::{Arc, LazyLock};
33
use anyhow::{anyhow, format_err};
44
use http::{Extensions, StatusCode};
55
use reqwest::{Request, Response};
6-
use reqwest_middleware::{ClientWithMiddleware, Error, Middleware, Next};
6+
use reqwest_middleware::{Error, Middleware, Next};
77
use tokio::sync::Mutex;
88
use tracing::{debug, trace, warn};
99

1010
use uv_netrc::Netrc;
1111
use uv_preview::{Preview, PreviewFeature};
1212
use uv_redacted::DisplaySafeUrl;
1313
use uv_static::EnvVars;
14-
use uv_warnings::owo_colors::OwoColorize;
1514

1615
use crate::providers::{
1716
AzureEndpointProvider, GcsEndpointProvider, HuggingFaceProvider, S3EndpointProvider,
1817
};
19-
use crate::pyx::{DEFAULT_TOLERANCE_SECS, PyxTokenStore};
2018
use crate::{
21-
AccessToken, CredentialsCache, KeyringProvider,
19+
CredentialsCache, KeyringProvider,
2220
cache::FetchUrl,
2321
credentials::{
2422
Authentication, AuthenticationError, Credentials, CredentialsFromUrlError, Username,
@@ -143,15 +141,6 @@ impl TextStoreMode {
143141
}
144142
}
145143

146-
#[derive(Debug, Clone)]
147-
enum TokenState {
148-
/// The token state has not yet been initialized from the store.
149-
Uninitialized,
150-
/// The token state has been initialized, and the store either returned tokens or `None` if
151-
/// the user has not yet authenticated.
152-
Initialized(Option<AccessToken>),
153-
}
154-
155144
#[derive(Clone)]
156145
enum S3CredentialState {
157146
/// The S3 credential state has not yet been initialized.
@@ -194,12 +183,6 @@ pub struct AuthMiddleware {
194183
/// Set all endpoints as needing authentication. We never try to send an
195184
/// unauthenticated request, avoiding cloning an uncloneable request.
196185
only_authenticated: bool,
197-
/// The base client to use for requests within the middleware.
198-
base_client: Option<ClientWithMiddleware>,
199-
/// The pyx token store to use for persistent credentials.
200-
pyx_token_store: Option<PyxTokenStore>,
201-
/// Tokens to use for persistent credentials.
202-
pyx_token_state: Mutex<TokenState>,
203186
/// Cached S3 credentials to avoid running the credential helper multiple times.
204187
s3_credential_state: Mutex<S3CredentialState>,
205188
/// Cached GCS credentials to avoid running the credential helper multiple times.
@@ -225,9 +208,6 @@ impl AuthMiddleware {
225208
cache: Arc::new(CredentialsCache::default()),
226209
indexes: Indexes::new(),
227210
only_authenticated: false,
228-
base_client: None,
229-
pyx_token_store: None,
230-
pyx_token_state: Mutex::new(TokenState::Uninitialized),
231211
s3_credential_state: Mutex::new(S3CredentialState::Uninitialized),
232212
gcs_credential_state: Mutex::new(GcsCredentialState::Uninitialized),
233213
azure_credential_state: Mutex::new(AzureCredentialState::Uninitialized),
@@ -307,20 +287,6 @@ impl AuthMiddleware {
307287
self
308288
}
309289

310-
/// Configure the [`ClientWithMiddleware`] to use for requests within the middleware.
311-
#[must_use]
312-
pub fn with_base_client(mut self, client: ClientWithMiddleware) -> Self {
313-
self.base_client = Some(client);
314-
self
315-
}
316-
317-
/// Configure the [`PyxTokenStore`] to use for persistent credentials.
318-
#[must_use]
319-
pub fn with_pyx_token_store(mut self, token_store: PyxTokenStore) -> Self {
320-
self.pyx_token_store = Some(token_store);
321-
self
322-
}
323-
324290
/// Global authentication cache for a uv invocation to share credentials across uv clients.
325291
fn cache(&self) -> &CredentialsCache {
326292
&self.cache
@@ -428,18 +394,8 @@ impl Middleware for AuthMiddleware {
428394
.as_ref()
429395
.is_some_and(|credentials| credentials.username().is_some());
430396

431-
// Determine whether this is a "known" URL.
432-
let is_known_url = self
433-
.pyx_token_store
434-
.as_ref()
435-
.is_some_and(|token_store| token_store.is_known_url(request.url()));
436-
437397
let must_authenticate = self.only_authenticated
438-
|| (match auth_policy {
439-
AuthPolicy::Auto => is_known_url,
440-
AuthPolicy::Always => true,
441-
AuthPolicy::Never => false,
442-
}
398+
|| (matches!(auth_policy, AuthPolicy::Always)
443399
// Dependabot intercepts HTTP requests and injects credentials, which means that we
444400
// cannot eagerly enforce an `AuthPolicy` as we don't know whether credentials will be
445401
// added outside of uv.
@@ -551,19 +507,6 @@ impl Middleware for AuthMiddleware {
551507

552508
if let Some(response) = response {
553509
Ok(response)
554-
} else if let Some(store) = is_known_url
555-
.then_some(self.pyx_token_store.as_ref())
556-
.flatten()
557-
{
558-
let domain = store
559-
.api()
560-
.domain()
561-
.unwrap_or("pyx.dev")
562-
.trim_start_matches("api.");
563-
Err(Error::Middleware(format_err!(
564-
"Run `{}` to authenticate uv with pyx",
565-
format!("uv auth login {domain}").green()
566-
)))
567510
} else {
568511
Err(Error::Middleware(format_err!(
569512
"Missing credentials for {url}"
@@ -809,45 +752,8 @@ impl AuthMiddleware {
809752
}
810753
}
811754

812-
// If this is a known URL, authenticate it via the token store.
813-
let credentials = if let Some(credentials) = async {
814-
let base_client = self.base_client.as_ref()?;
815-
let token_store = self.pyx_token_store.as_ref()?;
816-
if !token_store.is_known_url(url) {
817-
return None;
818-
}
819-
820-
let mut token_state = self.pyx_token_state.lock().await;
821-
822-
// If the token store is uninitialized, initialize it.
823-
let token = match *token_state {
824-
TokenState::Uninitialized => {
825-
trace!("Initializing token store for {url}");
826-
let generated = match token_store
827-
.access_token(base_client, DEFAULT_TOLERANCE_SECS)
828-
.await
829-
{
830-
Ok(Some(token)) => Some(token),
831-
Ok(None) => None,
832-
Err(err) => {
833-
warn!("Failed to generate access tokens: {err}");
834-
None
835-
}
836-
};
837-
*token_state = TokenState::Initialized(generated.clone());
838-
generated
839-
}
840-
TokenState::Initialized(ref tokens) => tokens.clone(),
841-
};
842-
843-
token.map(Credentials::from)
844-
}
845-
.await
846-
{
847-
debug!("Found credentials from token store for {url}");
848-
Some(credentials)
849755
// Netrc support based on: <https://github.com/gribouille/netrc>.
850-
} else if let Some(credentials) = self.netrc.get().and_then(|netrc| {
756+
let credentials = if let Some(credentials) = self.netrc.get().and_then(|netrc| {
851757
debug!("Checking netrc for credentials for {url}");
852758
Credentials::from_netrc(
853759
netrc,

0 commit comments

Comments
 (0)