Redact Git credentials from pyproject.toml (#6074)

## Summary

We retain them if you use `--raw-sources`, but otherwise they're
removed. We still respect them in the subsequent `uv.lock` via an
in-process store.

Closes #6056.
This commit is contained in:
Charlie Marsh 2024-08-13 21:30:02 -04:00 committed by GitHub
parent 92263108cc
commit 8fac63d4ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 301 additions and 23 deletions

View file

@ -0,0 +1,21 @@
use std::collections::HashMap;
use std::sync::{Arc, RwLock};
use cache_key::RepositoryUrl;
use uv_auth::Credentials;
/// A store for Git credentials.
#[derive(Debug, Default)]
pub struct GitStore(RwLock<HashMap<RepositoryUrl, Arc<Credentials>>>);
impl GitStore {
/// Insert [`Credentials`] for the given URL into the store.
pub fn insert(&self, url: RepositoryUrl, credentials: Credentials) -> Option<Arc<Credentials>> {
self.0.write().unwrap().insert(url, Arc::new(credentials))
}
/// Get the [`Credentials`] for the given URL, if they exist.
pub fn get(&self, url: &RepositoryUrl) -> Option<Arc<Credentials>> {
self.0.read().unwrap().get(url).cloned()
}
}