From cf6a8225d75d1cf16427dd78aac4baa444cf1217 Mon Sep 17 00:00:00 2001 From: Noctua Date: Sat, 15 Jun 2024 14:09:05 +0200 Subject: [PATCH] chore: update charm libraries (#266) --- .../observability_libs/v1/cert_handler.py | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/charms/observability_libs/v1/cert_handler.py b/lib/charms/observability_libs/v1/cert_handler.py index c482662f..f6a3eda4 100644 --- a/lib/charms/observability_libs/v1/cert_handler.py +++ b/lib/charms/observability_libs/v1/cert_handler.py @@ -67,7 +67,7 @@ LIBID = "b5cd5cd580f3428fa5f59a8876dcbe6a" LIBAPI = 1 -LIBPATCH = 8 +LIBPATCH = 9 VAULT_SECRET_LABEL = "cert-handler-private-vault" @@ -391,30 +391,37 @@ def _migrate_vault(self): @property def enabled(self) -> bool: - """Boolean indicating whether the charm has a tls_certificates relation.""" + """Boolean indicating whether the charm has a tls_certificates relation. + + See also the `available` property. + """ # We need to check for units as a temporary workaround because of https://bugs.launchpad.net/juju/+bug/2024583 # This could in theory not work correctly on scale down to 0 but it is necessary for the moment. - if not self.charm.model.get_relation(self.certificates_relation_name): + if not self.relation: return False - if not self.charm.model.get_relation( - self.certificates_relation_name - ).units: # pyright: ignore + if not self.relation.units: # pyright: ignore return False - if not self.charm.model.get_relation( - self.certificates_relation_name - ).app: # pyright: ignore + if not self.relation.app: # pyright: ignore return False - if not self.charm.model.get_relation( - self.certificates_relation_name - ).data: # pyright: ignore + if not self.relation.data: # pyright: ignore return False return True + @property + def available(self) -> bool: + """Return True if all certs are available in relation data; False otherwise.""" + return ( + self.enabled + and self.server_cert is not None + and self.private_key is not None + and self.ca_cert is not None + ) + def _on_certificates_relation_joined(self, _) -> None: # this will only generate a csr if we don't have one already self._generate_csr()