diff options
Diffstat (limited to 'src/acme.rs')
-rw-r--r-- | src/acme.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/acme.rs b/src/acme.rs new file mode 100644 index 0000000..c6dbc5b --- /dev/null +++ b/src/acme.rs @@ -0,0 +1,41 @@ +use std::collections::HashSet; + +use log::*; +use anyhow::Result; +use tokio::{sync::watch, time::sleep}; + +use acme_micro::{Error, Certificate, Directory, DirectoryUrl}; +use acme_micro::create_p384_key; + +use crate::consul::Consul; +use crate::proxy_config::ProxyConfig; + +pub async fn acme_task(mut consul: Consul, mut rx_proxy_config: watch::Receiver<ProxyConfig>) { + while rx_proxy_config.changed().await.is_ok() { + let mut domains: HashSet<String> = HashSet::new(); + + for ent in rx_proxy_config.borrow().entries.iter() { + domains.insert(ent.host.clone()); + } + info!("Ensuring we have certs for domains: {:#?}", domains); + + let results = futures::future::join_all( + domains.iter() + .map(|dom| renew_cert(dom, &consul)) + ).await; + + for (res, dom) in results.iter().zip(domains.iter()) { + if let Err(e) = res { + error!("{}: {}", dom, e); + } + } + } +} + +async fn renew_cert(dom: &str, consul: &Consul) -> Result<()> { + let dir = Directory::from_url(DirectoryUrl::LetsEncrypt)?; + let contact = vec!["mailto:alex@adnab.me".to_string()]; + let acc = dir.register_account(contact.clone())?; + // TODO + unimplemented!() +} |