diff --git a/Cargo.lock b/Cargo.lock index 362b5da..8a55739 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "acme-client" -version = "1.1.0" +version = "1.1.1" dependencies = [ "acme-lib", "aliyun-openapi-core-rust-sdk", diff --git a/Cargo.toml b/Cargo.toml index 8665e1b..592116c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "acme-client" -version = "1.1.0" +version = "1.1.1" authors = ["Hatter Jiang "] edition = "2018" description = "Acme auto challenge client, acme-client can issue certificates from Let's encrypt" diff --git a/src/config.rs b/src/config.rs index acc304b..9f42f37 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,6 +24,17 @@ impl Default for AcmeChallenge { } } +impl AcmeChallenge { + pub fn from_str(t: Option<&str>) -> Self { + let t = t.map(|t| t.to_ascii_lowercase()).unwrap_or_else(|| "http".to_string()); + if t == "dns" { + AcmeChallenge::Dns + } else { + AcmeChallenge::Http + } + } +} + #[derive(Debug, Clone, Copy)] pub enum AcmeMode { Prod, @@ -135,12 +146,7 @@ impl CertConfig { impl CertConfigItem { pub fn get_acme_challenge(&self) -> AcmeChallenge { - let t = self.r#type.as_ref().map(|t| t.to_ascii_lowercase()).unwrap_or_else(|| "http".to_string()); - if t == "dns" { - AcmeChallenge::Dns - } else { - AcmeChallenge::Http - } + AcmeChallenge::from_str(self.r#type.as_ref().map(|s| s.as_str())) } pub fn fill_dns_names(&mut self) -> XResult> { diff --git a/src/main.rs b/src/main.rs index fe6687c..a93900c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,6 +92,8 @@ async fn main() -> tide::Result<()> { .arg(Arg::with_name("skip-verify-ip").short("k").long("skip-verify-ip").help("Skip verify public ip")) .arg(Arg::with_name("skip-verify-certificate").short("K").long("skip-verify-certificate").help("Skip verify certificate")) .arg(Arg::with_name("allow-interact").long("allow-interact").help("Allow interact")) + .arg(Arg::with_name("challenge-type").short("T").long("challenge-type").takes_value(true).default_value("http").help("Challenge type, http or dns")) + .arg(Arg::with_name("dns-supplier").short("s").long("dns-supplier").takes_value(true).default_value("account://***:****@**?id=*").help("DNS supplier")) .get_matches(); if matches.is_present("verbose") { @@ -249,8 +251,8 @@ async fn main() -> tide::Result<()> { }; let acme_request = AcmeRequest { - challenge: AcmeChallenge::Http, - credential_supplier: None, + challenge: AcmeChallenge::from_str(matches.value_of("challenge-type")), + credential_supplier: matches.value_of("dns-supplier"), allow_interact: false, contract_email: &email, primary_name,