feat: command line supports dns challenge

This commit is contained in:
2022-02-04 14:38:08 +08:00
parent ac540437dd
commit 6639276e11
4 changed files with 18 additions and 10 deletions

2
Cargo.lock generated
View File

@@ -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",

View File

@@ -1,6 +1,6 @@
[package]
name = "acme-client"
version = "1.1.0"
version = "1.1.1"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
description = "Acme auto challenge client, acme-client can issue certificates from Let's encrypt"

View File

@@ -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<Option<X509Certificate>> {

View File

@@ -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,