|
67 | 67 |
|
68 | 68 | LIBID = "b5cd5cd580f3428fa5f59a8876dcbe6a" |
69 | 69 | LIBAPI = 1 |
70 | | -LIBPATCH = 8 |
| 70 | +LIBPATCH = 9 |
71 | 71 |
|
72 | 72 | VAULT_SECRET_LABEL = "cert-handler-private-vault" |
73 | 73 |
|
@@ -391,30 +391,37 @@ def _migrate_vault(self): |
391 | 391 |
|
392 | 392 | @property |
393 | 393 | def enabled(self) -> bool: |
394 | | - """Boolean indicating whether the charm has a tls_certificates relation.""" |
| 394 | + """Boolean indicating whether the charm has a tls_certificates relation. |
| 395 | +
|
| 396 | + See also the `available` property. |
| 397 | + """ |
395 | 398 | # We need to check for units as a temporary workaround because of https://bugs.launchpad.net/juju/+bug/2024583 |
396 | 399 | # This could in theory not work correctly on scale down to 0 but it is necessary for the moment. |
397 | 400 |
|
398 | | - if not self.charm.model.get_relation(self.certificates_relation_name): |
| 401 | + if not self.relation: |
399 | 402 | return False |
400 | 403 |
|
401 | | - if not self.charm.model.get_relation( |
402 | | - self.certificates_relation_name |
403 | | - ).units: # pyright: ignore |
| 404 | + if not self.relation.units: # pyright: ignore |
404 | 405 | return False |
405 | 406 |
|
406 | | - if not self.charm.model.get_relation( |
407 | | - self.certificates_relation_name |
408 | | - ).app: # pyright: ignore |
| 407 | + if not self.relation.app: # pyright: ignore |
409 | 408 | return False |
410 | 409 |
|
411 | | - if not self.charm.model.get_relation( |
412 | | - self.certificates_relation_name |
413 | | - ).data: # pyright: ignore |
| 410 | + if not self.relation.data: # pyright: ignore |
414 | 411 | return False |
415 | 412 |
|
416 | 413 | return True |
417 | 414 |
|
| 415 | + @property |
| 416 | + def available(self) -> bool: |
| 417 | + """Return True if all certs are available in relation data; False otherwise.""" |
| 418 | + return ( |
| 419 | + self.enabled |
| 420 | + and self.server_cert is not None |
| 421 | + and self.private_key is not None |
| 422 | + and self.ca_cert is not None |
| 423 | + ) |
| 424 | + |
418 | 425 | def _on_certificates_relation_joined(self, _) -> None: |
419 | 426 | # this will only generate a csr if we don't have one already |
420 | 427 | self._generate_csr() |
|
0 commit comments