Auto renew given certificate
(
&self,
domains: &[String],
live_cert_pem_path: impl AsRef<Path>,
live_key_pem_path: impl AsRef<Path>,
backup_dir: impl AsRef<Path>,
)
| 281 | |
| 282 | /// Auto renew given certificate |
| 283 | pub async fn create_cert_if_needed( |
| 284 | &self, |
| 285 | domains: &[String], |
| 286 | live_cert_pem_path: impl AsRef<Path>, |
| 287 | live_key_pem_path: impl AsRef<Path>, |
| 288 | backup_dir: impl AsRef<Path>, |
| 289 | ) -> Result<bool> { |
| 290 | if live_cert_pem_path.as_ref().exists() && live_key_pem_path.as_ref().exists() { |
| 291 | return Ok(false); |
| 292 | } |
| 293 | let key_pem = if live_key_pem_path.as_ref().exists() { |
| 294 | debug!("using existing cert key pair"); |
| 295 | fs::read_to_string(live_key_pem_path.as_ref())? |
| 296 | } else { |
| 297 | debug!("generating new cert key pair"); |
| 298 | let key = KeyPair::generate().context("failed to generate key")?; |
| 299 | key.serialize_pem() |
| 300 | }; |
| 301 | let cert_pem = self.request_new_certificate(&key_pem, domains).await?; |
| 302 | self.store_cert( |
| 303 | live_cert_pem_path.as_ref(), |
| 304 | live_key_pem_path.as_ref(), |
| 305 | &cert_pem, |
| 306 | &key_pem, |
| 307 | backup_dir.as_ref(), |
| 308 | )?; |
| 309 | Ok(true) |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | impl AcmeClient { |
no test coverage detected