(&self, domain: &str)
| 150 | /// Request new certificate for a domain |
| 151 | #[tracing::instrument(skip(self))] |
| 152 | async fn request_new_cert(&self, domain: &str) -> Result<()> { |
| 153 | let config = self |
| 154 | .kv_store |
| 155 | .get_zt_domain_config(domain) |
| 156 | .context("ZT-Domain config not found")?; |
| 157 | |
| 158 | // Try to acquire lock first |
| 159 | if !self |
| 160 | .kv_store |
| 161 | .try_acquire_cert_lock(domain, RENEW_LOCK_TIMEOUT_SECS) |
| 162 | { |
| 163 | // Another node is requesting, wait for it |
| 164 | info!("another node is requesting, waiting..."); |
| 165 | tokio::time::sleep(Duration::from_secs(30)).await; |
| 166 | if let Some(cert_data) = self.kv_store.get_cert_data(domain) { |
| 167 | self.cert_resolver.update_cert(domain, &cert_data)?; |
| 168 | return Ok(()); |
| 169 | } |
| 170 | bail!("failed to get certificate from KvStore after waiting"); |
| 171 | } |
| 172 | |
| 173 | let result = self.do_request_new(domain, &config).await; |
| 174 | |
| 175 | if let Err(err) = self.kv_store.release_cert_lock(domain) { |
| 176 | error!("failed to release lock: {err:?}"); |
| 177 | } |
| 178 | |
| 179 | result |
| 180 | } |
| 181 | |
| 182 | async fn do_request_new(&self, domain: &str, config: &ZtDomainConfig) -> Result<()> { |
| 183 | let acme_client = self.get_or_create_acme_client(domain, config).await?; |
no test coverage detected