Skip to content

Commit

Permalink
Fix certhandler relation broken (#84)
Browse files Browse the repository at this point in the history
* skip pushing csr if relation is dead

* fixed issue with relation-broken in certhandler:

* lint
  • Loading branch information
PietroPasotti authored Apr 24, 2024
1 parent 4169cf1 commit 2a009a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit 2a009a9

Please sign in to comment.