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

Replace dashes with underscores in index credential variables #8452

Merged
merged 1 commit into from
Oct 22, 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
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()
Copy link
Member Author

Choose a reason for hiding this comment

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

(I am separately going to add validation that index names are ASCII.)

} 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
Loading