Skip to content

Commit 006105d

Browse files
authored
Add available property to cert_handler (#96)
1 parent 1bf6117 commit 006105d

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

lib/charms/observability_libs/v1/cert_handler.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868
LIBID = "b5cd5cd580f3428fa5f59a8876dcbe6a"
6969
LIBAPI = 1
70-
LIBPATCH = 8
70+
LIBPATCH = 9
7171

7272
VAULT_SECRET_LABEL = "cert-handler-private-vault"
7373

@@ -391,30 +391,37 @@ def _migrate_vault(self):
391391

392392
@property
393393
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+
"""
395398
# We need to check for units as a temporary workaround because of https://bugs.launchpad.net/juju/+bug/2024583
396399
# This could in theory not work correctly on scale down to 0 but it is necessary for the moment.
397400

398-
if not self.charm.model.get_relation(self.certificates_relation_name):
401+
if not self.relation:
399402
return False
400403

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
404405
return False
405406

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
409408
return False
410409

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
414411
return False
415412

416413
return True
417414

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+
418425
def _on_certificates_relation_joined(self, _) -> None:
419426
# this will only generate a csr if we don't have one already
420427
self._generate_csr()

0 commit comments

Comments
 (0)