mirror of https://github.com/astral-sh/uv
Respect `UV_CREDENTIALS_DIR` (#15598)
This commit is contained in:
parent
4d79fd2c04
commit
a13fb3ec64
|
|
@ -5095,11 +5095,11 @@ dependencies = [
|
|||
"toml",
|
||||
"tracing",
|
||||
"url",
|
||||
"uv-dirs",
|
||||
"uv-keyring",
|
||||
"uv-once-map",
|
||||
"uv-redacted",
|
||||
"uv-small-str",
|
||||
"uv-state",
|
||||
"uv-static",
|
||||
"uv-warnings",
|
||||
"wiremock",
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ doctest = false
|
|||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
uv-dirs = { workspace = true }
|
||||
uv-keyring = { workspace = true, features = ["apple-native", "secret-service", "windows-native"] }
|
||||
uv-once-map = { workspace = true }
|
||||
uv-redacted = { workspace = true }
|
||||
uv-small-str = { workspace = true }
|
||||
uv-static = { workspace = true }
|
||||
uv-state = { workspace = true }
|
||||
uv-warnings = { workspace = true }
|
||||
|
||||
anyhow = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -65,25 +65,25 @@ impl Default for TextStoreMode {
|
|||
// TODO(zanieb): Reconsider this pattern. We're just mirroring the [`NetrcMode`]
|
||||
// implementation for now.
|
||||
Self::Automatic(LazyLock::new(|| {
|
||||
let state_dir = uv_dirs::user_state_dir()?;
|
||||
let credentials_path = state_dir.join("credentials").join("credentials.toml");
|
||||
let path = TextCredentialStore::default_file()
|
||||
.inspect_err(|err| {
|
||||
warn!("Failed to determine credentials file path: {}", err);
|
||||
})
|
||||
.ok()?;
|
||||
|
||||
match TextCredentialStore::from_file(&credentials_path) {
|
||||
match TextCredentialStore::from_file(&path) {
|
||||
Ok(store) => {
|
||||
debug!("Loaded credential file {}", credentials_path.display());
|
||||
debug!("Loaded credential file {}", path.display());
|
||||
Some(store)
|
||||
}
|
||||
Err(TomlCredentialError::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => {
|
||||
debug!(
|
||||
"No credentials file found at {}",
|
||||
credentials_path.display()
|
||||
);
|
||||
debug!("No credentials file found at {}", path.display());
|
||||
None
|
||||
}
|
||||
Err(err) => {
|
||||
warn!(
|
||||
"Failed to load credentials from {}: {}",
|
||||
credentials_path.display(),
|
||||
path.display(),
|
||||
err
|
||||
);
|
||||
None
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@ use tracing::debug;
|
|||
use url::Url;
|
||||
use uv_redacted::DisplaySafeUrl;
|
||||
|
||||
use uv_state::{StateBucket, StateStore};
|
||||
use uv_static::EnvVars;
|
||||
|
||||
use crate::Credentials;
|
||||
use crate::credentials::{Password, Username};
|
||||
use crate::realm::Realm;
|
||||
|
|
@ -182,12 +185,22 @@ pub struct TextCredentialStore {
|
|||
}
|
||||
|
||||
impl TextCredentialStore {
|
||||
/// Return the default credential file path.
|
||||
/// Return the directory for storing credentials.
|
||||
fn directory_path() -> Result<PathBuf, TomlCredentialError> {
|
||||
if let Some(dir) = std::env::var_os(EnvVars::UV_CREDENTIALS_DIR)
|
||||
.filter(|s| !s.is_empty())
|
||||
.map(PathBuf::from)
|
||||
{
|
||||
return Ok(dir);
|
||||
}
|
||||
|
||||
Ok(StateStore::from_settings(None)?.bucket(StateBucket::Credentials))
|
||||
}
|
||||
|
||||
/// Return the standard file path for storing credentials.
|
||||
pub fn default_file() -> Result<PathBuf, TomlCredentialError> {
|
||||
let state_dir =
|
||||
uv_dirs::user_state_dir().ok_or(TomlCredentialError::CredentialsDirError)?;
|
||||
let credentials_dir = state_dir.join("credentials");
|
||||
Ok(credentials_dir.join("credentials.toml"))
|
||||
let dir = Self::directory_path()?;
|
||||
Ok(dir.join("credentials.toml"))
|
||||
}
|
||||
|
||||
/// Read credentials from a file.
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@ impl EnvVars {
|
|||
/// directory for caching instead of the default cache directory.
|
||||
pub const UV_CACHE_DIR: &'static str = "UV_CACHE_DIR";
|
||||
|
||||
/// The directory for storage of credentials when using a plain text backend.
|
||||
pub const UV_CREDENTIALS_DIR: &'static str = "UV_CREDENTIALS_DIR";
|
||||
|
||||
/// Equivalent to the `--no-cache` command-line argument. If set, uv will not use the
|
||||
/// cache for any operations.
|
||||
pub const UV_NO_CACHE: &'static str = "UV_NO_CACHE";
|
||||
|
|
|
|||
|
|
@ -55,6 +55,10 @@ local `uv.toml` file to use as the configuration file.
|
|||
Equivalent to the `--constraint` command-line argument. If set, uv will use this
|
||||
file as the constraints file. Uses space-separated list of files.
|
||||
|
||||
### `UV_CREDENTIALS_DIR`
|
||||
|
||||
The directory for storage of credentials when using a plain text backend.
|
||||
|
||||
### `UV_CUSTOM_COMPILE_COMMAND`
|
||||
|
||||
Equivalent to the `--custom-compile-command` command-line argument.
|
||||
|
|
|
|||
Loading…
Reference in New Issue