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

also check if credentials stored under wildcard host #252

Merged
merged 2 commits into from
Jul 7, 2023
Merged
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
19 changes: 18 additions & 1 deletion crates/rattler_networking/src/authentication_storage/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,31 @@ impl AuthenticationStorage {
}

/// Retrieve the authentication information for the given URL
/// (including the authentication information for the wildcard
/// host if no credentials are found for the given host)
///
/// E.g. if credentials are stored for `*.prefix.dev` and the
/// given URL is `https://repo.prefix.dev`, the credentials
/// for `*.prefix.dev` will be returned.
pub fn get_by_url<U: IntoUrl>(
&self,
url: U,
) -> Result<(Url, Option<Authentication>), reqwest::Error> {
let url = url.into_url()?;

if let Some(host) = url.host_str() {
let credentials = self.get(host);

let credentials = match credentials {
Ok(None) => {
// Check for credentials under e.g. `*.prefix.dev`
let mut parts = host.rsplitn(2, '.').collect::<Vec<&str>>();
parts.reverse();
let wildcard_host = format!("*.{}", parts.join("."));
self.get(&wildcard_host)
}
_ => credentials,
};

match credentials {
Ok(None) => Ok((url, None)),
Ok(Some(credentials)) => Ok((url, Some(credentials))),
Expand Down