feat: email

This commit is contained in:
2021-05-05 15:01:15 +08:00
parent 234640f263
commit 00d5dc9d09
2 changed files with 41 additions and 11 deletions

View File

@@ -150,11 +150,14 @@ impl CertConfigItem {
}
cert_dns_names.push(x509_certificate.common_name.to_lowercase());
self.dns_names.as_ref().map(|dns_names| dns_names.iter().map(|n| n.to_lowercase()).map(|n| {
if !self_dns_names.contains(&n) {
self_dns_names.push(n);
if let Some(dns_names) = &self.dns_names {
for n in dns_names {
let n = n.to_lowercase();
if !self_dns_names.contains(&n) {
self_dns_names.push(n);
}
}
}));
}
for n in &x509_certificate.alt_names {
let n = n.to_lowercase();
if !cert_dns_names.contains(&n) {

View File

@@ -26,6 +26,7 @@ use async_std::channel::Sender;
use config::AcmeMode;
use crate::config::{CertConfig, CERT_NAME, KEY_NAME};
use crate::x509::{X509PublicKeyAlgo, X509EcPublicKeyAlgo};
use std::path::PathBuf;
const NAME: &str = env!("CARGO_PKG_NAME");
const VERSION: &str = env!("CARGO_PKG_VERSION");
@@ -86,10 +87,37 @@ async fn main() -> tide::Result<()> {
debugging!("Clap matches: {:?}", matches);
let email = matches.value_of("email").unwrap_or_else(|| {
failure!("Email is not assigned.");
exit(1);
});
let account_dir = matches.value_of("dir").unwrap_or("acme_dir");
let mut account_email = PathBuf::from(account_dir);
account_email.push("account_email.conf");
let email = if account_email.exists() {
match fs::read_to_string(&account_email) {
Err(e) => {
failure!("Read from file: {:?}, failed: {}", account_email, e);
exit(1);
}
Ok(email) => {
if let Some(email_from_args) = matches.value_of("email") {
if &email != email_from_args {
warning!("Get email from account config: {}", email);
}
}
email.trim().to_string()
}
}
} else {
let email = matches.value_of("email").unwrap_or_else(|| {
failure!("Email is not assigned.");
exit(1);
});
information!("Write email to account config: {:?}", account_email);
fs::write(account_email, email);
email.to_string()
};
match matches.value_of("type") {
Some("http") => {}
@@ -138,7 +166,6 @@ async fn main() -> tide::Result<()> {
exit(1);
}
};
let account_dir = matches.value_of("dir").unwrap_or("acme_dir");
let check = matches.is_present("check");
@@ -161,7 +188,7 @@ async fn main() -> tide::Result<()> {
let alt_names: Vec<&str> = domains.into_iter().skip(1).collect();
information!("Domains, main: {}, alt: {:?}", primary_name, alt_names);
let acme_request = AcmeRequest {
contract_email: email,
contract_email: &email,
primary_name,
alt_names: &alt_names,
algo,
@@ -197,7 +224,7 @@ async fn main() -> tide::Result<()> {
information!("Domains, main: {}, alt: {:?}", common_name, dns_names);
let alt_names: Vec<&str> = dns_names.iter().map(|n| n.as_str()).collect();
let acme_request = AcmeRequest {
contract_email: email,
contract_email: &email,
primary_name: common_name,
alt_names: &alt_names,
algo,