Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra useful methods and one bugfix. #51

Merged
merged 3 commits into from
Jul 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/charms/observability_libs/v0/cert_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

LIBID = "b5cd5cd580f3428fa5f59a8876dcbe6a"
LIBAPI = 0
LIBPATCH = 1
LIBPATCH = 2


class CertChanged(EventBase):
Expand Down Expand Up @@ -139,7 +139,7 @@ def __init__(
self._on_all_certificates_invalidated,
)
self.framework.observe(
self.charm.on.certificates_relation_broken, # pyright: ignore
self.charm.on[self.certificates_relation_name].relation_broken, # pyright: ignore
self._on_certificates_relation_broken,
)

Expand All @@ -148,6 +148,16 @@ def __init__(
self.charm.on[self.peer_relation_name].relation_created, self._on_peer_relation_created
)

@property
def enabled(self) -> bool:
"""Boolean indicating whether the charm has a tls_certificates relation."""
# 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.
return (
len(self.charm.model.relations[self.certificates_relation_name]) > 0
and len(self.charm.model.get_relation(self.certificates_relation_name).units) > 0 # type: ignore
)

@property
def _peer_relation(self) -> Optional[Relation]:
"""Return the peer relation."""
Expand Down Expand Up @@ -302,6 +312,11 @@ def cert(self):
"""Return the server cert."""
return self._server_cert

@property
def ca(self):
"""Return the CA cert."""
return self._ca_cert

@property
def _server_cert(self) -> Optional[str]:
if self._peer_relation:
Expand Down