fix args and config
This commit is contained in:
parent
a1fcc5125c
commit
64f013a8fb
@ -21,7 +21,7 @@ where
|
||||
{
|
||||
pub(crate) fn new(cfg: &AppConfig, provider: T) -> Self {
|
||||
let base_dir = PathBuf::from(&cfg.base_directory);
|
||||
let keys_dir = base_dir.clone().join(cfg.keys_subdir.clone());
|
||||
let keys_dir = base_dir.clone();
|
||||
let name = cfg.name.clone();
|
||||
|
||||
Certs {
|
||||
|
@ -49,18 +49,10 @@ pub(crate) struct Args {
|
||||
#[arg(short = 'c', long)]
|
||||
pub(crate) encoding: Option<String>,
|
||||
|
||||
/// keys subdir
|
||||
#[arg(long, default_value = ".")]
|
||||
pub(crate) keys_dir: String,
|
||||
|
||||
/// valid days
|
||||
#[arg(long, default_value = "3650")]
|
||||
pub(crate) days: u32,
|
||||
|
||||
/// openssl binary or (internal)
|
||||
#[arg(long, short, default_value = "internal")]
|
||||
pub(crate) openssl: OpenSSLProviderArg,
|
||||
|
||||
/// dns name
|
||||
#[arg(short = 'n', long)]
|
||||
pub(crate) dns: Vec<String>,
|
||||
@ -77,6 +69,10 @@ pub(crate) struct Args {
|
||||
#[arg(long)]
|
||||
pub(crate) province: Option<String>,
|
||||
|
||||
/// Location
|
||||
#[arg(long)]
|
||||
pub(crate) loc: Option<String>,
|
||||
|
||||
/// Organization
|
||||
#[arg(long)]
|
||||
pub(crate) org: Option<String>,
|
||||
@ -93,11 +89,9 @@ pub(crate) struct Args {
|
||||
pub(crate) struct AppConfig {
|
||||
pub(crate) encoding: String,
|
||||
pub(crate) req_days: u32,
|
||||
pub(crate) keys_subdir: String,
|
||||
pub(crate) ca_filename: String,
|
||||
pub(crate) default_email_domain: String,
|
||||
#[allow(unused)]
|
||||
pub(crate) openssl: OpenSSLProviderArg,
|
||||
pub(crate) base_directory: String,
|
||||
pub(crate) email: String,
|
||||
pub(crate) name: String,
|
||||
@ -105,6 +99,7 @@ pub(crate) struct AppConfig {
|
||||
pub(crate) ip: Vec<String>,
|
||||
pub(crate) country: Option<String>,
|
||||
pub(crate) province: Option<String>,
|
||||
pub(crate) loc: Option<String>,
|
||||
pub(crate) org: Option<String>,
|
||||
pub(crate) ou: Option<String>,
|
||||
pub(crate) key_size: u32,
|
||||
@ -115,10 +110,8 @@ impl Default for AppConfig {
|
||||
Self {
|
||||
encoding: "cp866".into(),
|
||||
req_days: 30650,
|
||||
keys_subdir: "keys".into(),
|
||||
ca_filename: "ca.crt".into(),
|
||||
default_email_domain: "example.com".into(),
|
||||
openssl: OpenSSLProviderArg::Internal,
|
||||
base_directory: ".".into(),
|
||||
email: "name@example.com".into(),
|
||||
name: "user".into(),
|
||||
@ -126,6 +119,7 @@ impl Default for AppConfig {
|
||||
ip: Vec::new(),
|
||||
country: None,
|
||||
province: None,
|
||||
loc: None,
|
||||
org: None,
|
||||
ou: None,
|
||||
key_size: 2048,
|
||||
@ -153,14 +147,13 @@ impl From<&Args> for AppConfig {
|
||||
defaults.encoding.clone()
|
||||
};
|
||||
let name = args.name.clone();
|
||||
let openssl = args.openssl.clone();
|
||||
let req_days = args.days;
|
||||
let keys_subdir = args.keys_dir.clone();
|
||||
let (dns, ip, country, province, org, ou) = (
|
||||
let (dns, ip, country, province, loc, org, ou) = (
|
||||
args.dns.clone(),
|
||||
args.ip.clone(),
|
||||
args.country.clone(),
|
||||
args.province.clone(),
|
||||
args.loc.clone(),
|
||||
args.org.clone(),
|
||||
args.ou.clone(),
|
||||
);
|
||||
@ -170,13 +163,12 @@ impl From<&Args> for AppConfig {
|
||||
email,
|
||||
encoding,
|
||||
name,
|
||||
openssl,
|
||||
req_days,
|
||||
keys_subdir,
|
||||
dns,
|
||||
ip,
|
||||
country,
|
||||
province,
|
||||
loc,
|
||||
org,
|
||||
ou,
|
||||
key_size: args.key_size,
|
||||
|
@ -90,6 +90,7 @@ pub(crate) struct OpenSSLInternalProvider {
|
||||
ip: Vec<String>,
|
||||
country: Option<String>,
|
||||
province: Option<String>,
|
||||
location: Option<String>,
|
||||
org: Option<String>,
|
||||
ou: Option<String>,
|
||||
}
|
||||
@ -109,7 +110,7 @@ impl OpenSSLInternalProvider {
|
||||
|
||||
pub(crate) fn from_cfg(cfg: &AppConfig) -> Self {
|
||||
let base_dir = PathBuf::from(&cfg.base_directory);
|
||||
let keys_dir = base_dir.clone().join(cfg.keys_subdir.clone());
|
||||
let keys_dir = base_dir.clone();
|
||||
let name = cfg.name.clone();
|
||||
|
||||
let ca_file = keys_dir.join(cfg.ca_filename.clone());
|
||||
@ -135,6 +136,7 @@ impl OpenSSLInternalProvider {
|
||||
ip: cfg.ip.clone(),
|
||||
country: cfg.country.clone(),
|
||||
province: cfg.province.clone(),
|
||||
location: cfg.loc.clone(),
|
||||
org: cfg.org.clone(),
|
||||
ou: cfg.ou.clone(),
|
||||
}
|
||||
@ -192,6 +194,9 @@ impl OpenSSLInternalProvider {
|
||||
if let Some(province) = self.province.clone() {
|
||||
name_builder.append_entry_by_text("ST", &province)?;
|
||||
}
|
||||
if let Some(location) = self.location.clone() {
|
||||
name_builder.append_entry_by_text("L", &location)?;
|
||||
}
|
||||
if let Some(org) = self.org.clone() {
|
||||
name_builder.append_entry_by_text("O", &org)?;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user