(
&self,
domain: &str,
config: &ZtDomainConfig,
)
| 285 | } |
| 286 | |
| 287 | async fn get_or_create_acme_client( |
| 288 | &self, |
| 289 | domain: &str, |
| 290 | config: &ZtDomainConfig, |
| 291 | ) -> Result<AcmeClient> { |
| 292 | // Get DNS credential (from config or default) |
| 293 | let dns_cred = if let Some(ref cred_id) = config.dns_cred_id { |
| 294 | self.kv_store |
| 295 | .get_dns_credential(cred_id) |
| 296 | .context("specified DNS credential not found")? |
| 297 | } else { |
| 298 | self.kv_store |
| 299 | .get_default_dns_credential() |
| 300 | .context("no default DNS credential configured")? |
| 301 | }; |
| 302 | |
| 303 | // Create DNS client based on provider |
| 304 | let dns01_client = match &dns_cred.provider { |
| 305 | DnsProvider::Cloudflare { api_token, api_url } => { |
| 306 | Dns01Client::new_cloudflare(domain.to_string(), api_token.clone(), api_url.clone()) |
| 307 | .await? |
| 308 | } |
| 309 | }; |
| 310 | |
| 311 | // Use ACME URL from certbot config, fall back to default if not set |
| 312 | let config = self.config(); |
| 313 | let acme_url = if config.acme_url.is_empty() { |
| 314 | DEFAULT_ACME_URL |
| 315 | } else { |
| 316 | &config.acme_url |
| 317 | }; |
| 318 | |
| 319 | // Try to load global ACME credentials from KvStore |
| 320 | if let Some(creds) = self.kv_store.get_acme_credentials() { |
| 321 | if acme_url_matches(&creds.acme_credentials, acme_url) { |
| 322 | info!("loaded global ACME account credentials from KvStore"); |
| 323 | return AcmeClient::load( |
| 324 | dns01_client, |
| 325 | &creds.acme_credentials, |
| 326 | dns_cred.max_dns_wait, |
| 327 | dns_cred.dns_txt_ttl, |
| 328 | ) |
| 329 | .await |
| 330 | .context("failed to load ACME client from KvStore credentials"); |
| 331 | } |
| 332 | warn!("ACME URL mismatch in KvStore credentials, will create new account"); |
| 333 | } |
| 334 | |
| 335 | // Create new global ACME account |
| 336 | info!("creating new global ACME account at {acme_url}"); |
| 337 | let client = AcmeClient::new_account( |
| 338 | acme_url, |
| 339 | dns01_client, |
| 340 | dns_cred.max_dns_wait, |
| 341 | dns_cred.dns_txt_ttl, |
| 342 | ) |
| 343 | .await |
| 344 | .context("failed to create new ACME account")?; |
no test coverage detected