uv_configuration/
authentication.rs

1use uv_auth::{self, KeyringProvider};
2
3/// Keyring provider type to use for credential lookup.
4#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
5#[serde(deny_unknown_fields, rename_all = "kebab-case")]
6#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
7#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
8pub enum KeyringProviderType {
9    /// Do not use keyring for credential lookup.
10    #[default]
11    Disabled,
12    /// Use the `keyring` command for credential lookup.
13    Subprocess,
14    // /// Not yet implemented
15    // Auto,
16    // /// Not implemented yet. Maybe use <https://docs.rs/keyring/latest/keyring/> for this?
17    // Import,
18}
19// See <https://pip.pypa.io/en/stable/topics/authentication/#keyring-support> for details.
20
21impl KeyringProviderType {
22    pub fn to_provider(&self) -> Option<KeyringProvider> {
23        match self {
24            Self::Disabled => None,
25            Self::Subprocess => Some(KeyringProvider::subprocess()),
26        }
27    }
28}
29
30impl std::fmt::Display for KeyringProviderType {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        match self {
33            Self::Disabled => write!(f, "disabled"),
34            Self::Subprocess => write!(f, "subprocess"),
35        }
36    }
37}