From 604d3be6dc04892cdef71935d1117855c1cc7bb4 Mon Sep 17 00:00:00 2001 From: Mica White Date: Sun, 29 Mar 2026 10:54:31 -0400 Subject: Get password from root config --- src/lib.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index d592003..2882039 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,7 @@ * - allow force */ -use std::collections::HashSet; +use std::collections::{HashMap, HashSet}; use std::fs::Metadata; use std::path::{Path, PathBuf}; @@ -49,9 +49,25 @@ use serde::{Deserialize, Serialize}; use thiserror::Error; use uuid::Uuid; -#[derive(Default, Serialize, Deserialize)] +#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Config { repositories: HashSet, + passwords: HashMap, String)>, + passphrases: HashMap, +} + +impl Config { + pub fn username_for_url(&self, url: &str) -> Option<&String> { + self.passwords.get(url)?.0.as_ref() + } + + pub fn password_for_url(&self, url: &str) -> Option<&String> { + Some(&self.passwords.get(url)?.1) + } + + pub fn passphrase_for_key(&self, key: &Path) -> Option<&String> { + self.passphrases.get(key) + } } #[derive(Debug, Error)] -- cgit v1.2.3