feat: rm acme config
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use rust_util::util_file;
|
||||
use rust_util::XResult;
|
||||
use std::fs;
|
||||
use acme_lib::DirectoryUrl;
|
||||
@@ -27,10 +26,6 @@ impl Default for AcmeAlgo {
|
||||
}
|
||||
|
||||
impl AcmeAlgo {
|
||||
// pub fn parse_or_default(s: &str) -> AcmeAlgo {
|
||||
// Self::parse(s).unwrap_or_else(|_| Default::default())
|
||||
// }
|
||||
|
||||
pub fn parse(s: &str) -> XResult<AcmeAlgo> {
|
||||
match s {
|
||||
"ec256" => Ok(AcmeAlgo::Ec256),
|
||||
@@ -57,10 +52,6 @@ impl Default for AcmeMode {
|
||||
}
|
||||
|
||||
impl AcmeMode {
|
||||
// pub fn parse_or_default(s: &str) -> AcmeMode {
|
||||
// Self::parse(s).unwrap_or_else(|_| Default::default())
|
||||
// }
|
||||
|
||||
pub fn parse(s: &str) -> XResult<AcmeMode> {
|
||||
match s {
|
||||
"prod" => Ok(AcmeMode::Prod),
|
||||
@@ -77,30 +68,6 @@ impl AcmeMode {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AcmeConfig {
|
||||
pub email: String,
|
||||
pub dir: String,
|
||||
pub auth_timeout: Option<u64>,
|
||||
pub csr_timeout: Option<u64>,
|
||||
pub concurrent: Option<u32>,
|
||||
}
|
||||
|
||||
impl AcmeConfig {
|
||||
// pub fn get_auth_timeout(&self) -> u64 {
|
||||
// self.auth_timeout.unwrap_or(5_000)
|
||||
// }
|
||||
//
|
||||
// pub fn get_csr_timeout(&self) -> u64 {
|
||||
// self.csr_timeout.unwrap_or(5_000)
|
||||
// }
|
||||
//
|
||||
// pub fn get_concurrent(&self) -> u32 {
|
||||
// self.concurrent.unwrap_or(0)
|
||||
// }
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CertConfigItem {
|
||||
@@ -191,23 +158,3 @@ impl CertConfigItem {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_acme_config(file: Option<&str>, load_default: bool) -> XResult<Option<AcmeConfig>> {
|
||||
if let Some(file) = file {
|
||||
let s = opt_result!(util_file::read_file_content(file), "Read file: {}, failed: {}", file);
|
||||
return Ok(Some(opt_result!(deser_hjson::from_str(&s), "Parse acme config file: {}, failed: {}", file)));
|
||||
}
|
||||
|
||||
if load_default {
|
||||
let default_config = util_file::read_config(None, &[
|
||||
"~/acme_config.json".to_string(),
|
||||
"/etc/acme_config.json".to_string(),
|
||||
]);
|
||||
if let Some(default_config) = default_config {
|
||||
let s = opt_result!(fs::read_to_string(default_config.clone()), "Read file: {:?}, failed: {}", default_config);
|
||||
return Ok(Some(opt_result!(deser_hjson::from_str(&s), "Parse acme config file: {:?}, failed: {}", default_config)));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
23
src/main.rs
23
src/main.rs
@@ -23,7 +23,7 @@ use async_std::channel;
|
||||
use async_std::channel::Sender;
|
||||
use config::AcmeAlgo;
|
||||
use config::AcmeMode;
|
||||
use crate::config::{CertConfig, CERT_NAME, KEY_NAME, load_acme_config};
|
||||
use crate::config::{CertConfig, CERT_NAME, KEY_NAME};
|
||||
|
||||
const NAME: &str = env!("CARGO_PKG_NAME");
|
||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
@@ -65,8 +65,7 @@ async fn main() -> tide::Result<()> {
|
||||
.arg(Arg::with_name("timeout").long("timeout").takes_value(true).default_value("5000").help("Timeout (ms)"))
|
||||
.arg(Arg::with_name("mode").short("m").long("mode").takes_value(true).default_value("prod").help("Mode"))
|
||||
.arg(Arg::with_name("dir").long("dir").takes_value(true).default_value("acme_dir").help("Account key dir"))
|
||||
.arg(Arg::with_name("config").short("c").long("config").takes_value(true).help("Acme config"))
|
||||
.arg(Arg::with_name("cert-config").long("cert-config").takes_value(true).help("Cert config"))
|
||||
.arg(Arg::with_name("config").short("c").long("config").takes_value(true).help("Cert config"))
|
||||
.get_matches();
|
||||
|
||||
if matches.is_present("version") {
|
||||
@@ -125,26 +124,18 @@ async fn main() -> tide::Result<()> {
|
||||
};
|
||||
let account_dir = matches.value_of("dir").unwrap_or("acme_dir");
|
||||
|
||||
let domains_val = matches.values_of("domain").unwrap_or_else(|| {
|
||||
failure!("Domains is not assigned.");
|
||||
exit(1);
|
||||
});
|
||||
|
||||
let (s, r) = channel::bounded(1);
|
||||
startup_http_server(s, port);
|
||||
r.recv().await.ok();
|
||||
task::sleep(Duration::from_millis(500)).await;
|
||||
|
||||
// TODO ......
|
||||
let config = matches.value_of("config");
|
||||
let _acme_config = load_acme_config(config, true).unwrap_or_else(|e| {
|
||||
failure!("Load acme config failed: {}", e);
|
||||
exit(1);
|
||||
});
|
||||
|
||||
let cert_config = matches.value_of("cert-config");
|
||||
let cert_config = matches.value_of("config");
|
||||
match cert_config {
|
||||
None => { // cert config is not assigned
|
||||
let domains_val = matches.values_of("domain").unwrap_or_else(|| {
|
||||
failure!("Domains is not assigned.");
|
||||
exit(1);
|
||||
});
|
||||
let domains: Vec<&str> = domains_val.collect::<Vec<_>>();
|
||||
let primary_name = domains[0];
|
||||
let alt_names: Vec<&str> = domains.into_iter().skip(1).collect();
|
||||
|
||||
Reference in New Issue
Block a user