Skip to content

Commit

Permalink
Replace dashes with underscores in index credential variables (#8452)
Browse files Browse the repository at this point in the history
## Summary

Closes #8448.
  • Loading branch information
charliermarsh authored Oct 22, 2024
1 parent 9a8ff85 commit 399d5ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion crates/uv-auth/src/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,17 @@ impl Credentials {
/// For example, given a name of `"pytorch"`, search for `UV_INDEX_PYTORCH_USERNAME` and
/// `UV_INDEX_PYTORCH_PASSWORD`.
pub fn from_env(name: &str) -> Option<Self> {
let name = name.to_uppercase();
// Convert to uppercase, and replace any non-alphanumeric characters with underscores.
let name = name
.chars()
.map(|c| {
if c.is_ascii_alphanumeric() {
c.to_ascii_uppercase()
} else {
'_'
}
})
.collect::<String>();
let username = std::env::var(EnvVars::index_username(&name)).ok();
let password = std::env::var(EnvVars::index_password(&name)).ok();
if username.is_none() && password.is_none() {
Expand Down
6 changes: 3 additions & 3 deletions crates/uv/tests/it/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6817,7 +6817,7 @@ fn lock_env_credentials() -> Result<()> {
build-backend = "setuptools.build_meta"

[[tool.uv.index]]
name = "proxy"
name = "internal-proxy"
url = "https://pypi-proxy.fly.dev/basic-auth/simple"
default = true
"#,
Expand All @@ -6838,8 +6838,8 @@ fn lock_env_credentials() -> Result<()> {

// Provide credentials via environment variables.
uv_snapshot!(context.filters(), context.lock()
.env(EnvVars::index_username("PROXY"), "public")
.env(EnvVars::index_password("PROXY"), "heron"), @r###"
.env(EnvVars::index_username("INTERNAL_PROXY"), "public")
.env(EnvVars::index_password("INTERNAL_PROXY"), "heron"), @r###"
success: true
exit_code: 0
----- stdout -----
Expand Down

0 comments on commit 399d5ab

Please sign in to comment.