Skip to content

Commit

Permalink
chore: Fetches lates version of the lego client lib (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
saltiyazan committed Jun 12, 2024
1 parent e08a6f4 commit 65eb9c5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
17 changes: 15 additions & 2 deletions lib/charms/lego_base_k8s/v0/lego_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _plugin_config(self):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 8
LIBPATCH = 9


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -144,7 +144,7 @@ def _on_collect_status(self, event: CollectStatusEvent) -> None:
BlockedStatus(err)
)
return
event.add_status(ActiveStatus())
event.add_status(ActiveStatus(self._get_certificate_fulfillment_status()))

def _sync_certificates(self, event: EventBase) -> None:
"""Go through all the certificates relations and handle outstanding requests."""
Expand Down Expand Up @@ -278,6 +278,19 @@ def _generate_signed_certificate(self, csr: str, relation_id: int):
relation_id=relation_id,
)

def _get_certificate_fulfillment_status(self) -> str:
"""Return the status message reflecting how many certificate requests are still pending."""
outstanding_requests_num = len(
self.tls_certificates.get_outstanding_certificate_requests()
)
total_requests_num = len(
self.tls_certificates.get_requirer_csrs()
)
fulfilled_certs = total_requests_num - outstanding_requests_num
return (
f"{fulfilled_certs}/{total_requests_num} certificate requests are fulfilled"
)

@property
def _cmd(self) -> List[str]:
"""Command to run to get the certificate.
Expand Down
10 changes: 8 additions & 2 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def test_given_email_is_valid_when_config_changed_then_status_is_active(self):
}
)
self.harness.evaluate_status()
self.assertEqual(self.harness.model.unit.status, ActiveStatus())
self.assertEqual(
self.harness.model.unit.status,
ActiveStatus("0/0 certificate requests are fulfilled"),
)

def test_given_email_is_invalid_when_config_changed_then_status_is_blocked(self):
self.harness.update_config(
Expand Down Expand Up @@ -85,7 +88,10 @@ def test_optional_config_provided_then_status_is_active(self):
}
)
self.harness.evaluate_status()
self.assertEqual(self.harness.model.unit.status, ActiveStatus())
self.assertEqual(
self.harness.model.unit.status,
ActiveStatus("0/0 certificate requests are fulfilled"),
)

def test_optional_config_provided_then_plugin_config_is_correct(self):
self.harness.update_config(
Expand Down

0 comments on commit 65eb9c5

Please sign in to comment.