Implemented support for local synchronization to a remote Git repo
This commit is contained in:
+31
-19
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user