Implemented support for local synchronization to a remote Git repo

This commit is contained in:
2025-09-09 12:49:35 -06:00
parent 8ac9ca40df
commit a0b710b96b
7 changed files with 471 additions and 33 deletions
+31 -19
View File
@@ -1,17 +1,24 @@
use crate::providers::{SecretProvider, SupportedProvider};
use log::debug;
use serde::{Deserialize, Serialize};
use serde_with::DisplayFromStr;
use serde_with::serde_as;
use std::path::PathBuf;
use log::{debug};
use validator::Validate;
#[serde_as]
#[derive(Debug, Validate, Serialize, Deserialize)]
#[derive(Debug, Clone, Validate, Serialize, Deserialize)]
pub struct Config {
#[serde_as(as = "DisplayFromStr")]
pub provider: SupportedProvider,
pub password_file: Option<PathBuf>,
pub git_branch: Option<String>,
/// The git remote URL to push changes to (e.g. git@github.com:user/repo.git)
pub git_remote_url: Option<String>,
pub git_user_name: Option<String>,
#[validate(email)]
pub git_user_email: Option<String>,
pub git_executable: Option<PathBuf>,
}
impl Default for Config {
@@ -19,28 +26,33 @@ impl Default for Config {
Self {
provider: SupportedProvider::Local(Default::default()),
password_file: Config::local_provider_password_file(),
git_branch: Some("main".into()),
git_remote_url: None,
git_user_name: None,
git_user_email: None,
git_executable: None,
}
}
}
impl Config {
pub fn extract_provider(&self) -> Box<&dyn SecretProvider> {
match &self.provider {
SupportedProvider::Local(p) => {
debug!("Using local secret provider");
Box::new(p)
}
}
}
pub fn extract_provider(&self) -> Box<dyn SecretProvider> {
match &self.provider {
SupportedProvider::Local(p) => {
debug!("Using local secret provider");
Box::new(*p)
}
}
}
pub fn local_provider_password_file() -> Option<PathBuf> {
let mut path = dirs::home_dir().map(|p| p.join(".gman_password"));
if let Some(p) = &path {
if !p.exists() {
path = None;
}
}
pub fn local_provider_password_file() -> Option<PathBuf> {
let mut path = dirs::home_dir().map(|p| p.join(".gman_password"));
if let Some(p) = &path {
if !p.exists() {
path = None;
}
}
path
}
path
}
}