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

Fix certhandler relation broken #84

Merged
merged 4 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion lib/charms/observability_libs/v0/cert_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

LIBID = "b5cd5cd580f3428fa5f59a8876dcbe6a"
LIBAPI = 0
LIBPATCH = 11
LIBPATCH = 12


def is_ip_address(value: str) -> bool:
Expand Down Expand Up @@ -240,6 +240,13 @@ def _generate_csr(

This method intentionally does not emit any events, leave it for caller's responsibility.
"""
# if we are in a relation-broken hook, we might not have a relation to publish the csr to.
if not self.charm.model.get_relation(self.certificates_relation_name):
logger.warning(
f"No {self.certificates_relation_name!r} relation found. " f"Cannot generate csr."
)
return

# At this point, assuming "peer joined" and "certificates joined" have already fired
# (caller must guard) so we must have a private_key entry in relation data at our disposal.
# Otherwise, traceback -> debug.
Expand Down
9 changes: 8 additions & 1 deletion lib/charms/observability_libs/v1/cert_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

LIBID = "b5cd5cd580f3428fa5f59a8876dcbe6a"
LIBAPI = 1
LIBPATCH = 4
LIBPATCH = 5


def is_ip_address(value: str) -> bool:
Expand Down Expand Up @@ -221,6 +221,13 @@ def _generate_csr(

This method intentionally does not emit any events, leave it for caller's responsibility.
"""
# if we are in a relation-broken hook, we might not have a relation to publish the csr to.
if not self.charm.model.get_relation(self.certificates_relation_name):
logger.warning(
f"No {self.certificates_relation_name!r} relation found. " f"Cannot generate csr."
)
return

# In case we already have a csr, do not overwrite it by default.
if overwrite or renew or not self._csr:
private_key = self.private_key
Expand Down
Loading