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

Resolve issues related to custom index URL and environment variables #8335

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions crates/uv-auth/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ impl AuthMiddleware {
/// Run a request to completion.
///
/// If credentials are present, insert them into the cache on success.

fn fetch_env_credentials(&self, url: &Url) -> Option<Credentials> {
let host = url.host_str()?;
let index_name = host.replace('.', "_").to_uppercase();
Credentials::from_env(&index_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is quite right -- the index name is not necessarily the same as the URL host, it's a user-provided string.

}

async fn complete_request(
&self,
credentials: Option<Arc<Credentials>>,
Expand Down Expand Up @@ -380,6 +387,9 @@ impl AuthMiddleware {
// falls back to the host, but we cache the result per realm so if a keyring
// implementation returns different credentials for different URLs in the
// same realm we will use the wrong credentials.
} else if let Some(credentials) = self.fetch_env_credentials(url) {
debug!("Found credentials in environment variables for {url}");
Some(credentials)
} else if let Some(credentials) = match self.keyring {
Some(ref keyring) => {
if let Some(username) = credentials.and_then(|credentials| credentials.username()) {
Expand Down
Loading