Add key_data_base to the CLI

This commit is contained in:
Rodolphe Bréard 2023-03-26 22:46:49 +02:00
parent 9438ab4af4
commit ebdb91fda4

View file

@ -12,6 +12,8 @@ use std::path::{Path, PathBuf};
pub struct Config {
#[arg(short, long, default_value_t = Algorithm::default())]
algorithm: Algorithm,
#[arg(short = 'b', long, value_name = "FILE")]
key_data_base: Option<PathBuf>,
#[arg(short, long, default_value_t = Canonicalization::default())]
canonicalization: Canonicalization,
#[arg(short, long)]
@ -39,6 +41,7 @@ pub struct Config {
impl Config {
pub fn init() -> Result<Self, String> {
let mut cnf = Self::parse();
cnf.key_data_base = process_key_data_base(cnf.key_data_base);
cnf.domain = process_domains(&cnf.domain, &cnf.domain_file)?;
cnf.header = process_headers(&cnf.header, crate::DEFAULT_HEADERS);
cnf.header_optional = process_headers(&cnf.header_optional, crate::DEFAULT_HEADERS_OPT);
@ -49,6 +52,10 @@ impl Config {
self.algorithm
}
pub fn key_data_base(&self) -> PathBuf {
self.key_data_base.clone().unwrap()
}
pub fn canonicalization(&self) -> Canonicalization {
self.canonicalization
}
@ -97,6 +104,15 @@ impl Config {
}
}
fn process_key_data_base(opt: Option<PathBuf>) -> Option<PathBuf> {
match opt {
Some(p) => Some(p),
None => Some(PathBuf::from(
"/var/lib/opensmtpd-filter-dkimout/key-db.sqlite3",
)),
}
}
fn process_domains(lst: &[String], domain_file: &Option<PathBuf>) -> Result<Vec<String>, String> {
let mut domain_set: HashSet<String> = lst.iter().map(|e| e.to_string()).collect();
if let Some(path) = domain_file {