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