blob: c6dbc5be97617475c7d49b178f216b0f56607101 (
plain) (
tree)
|
|
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!()
}
|