diff --git a/src/charm.py b/src/charm.py index 615545f..ade1bd9 100755 --- a/src/charm.py +++ b/src/charm.py @@ -5,15 +5,13 @@ """Charm the application.""" import logging -from dataclasses import dataclass -from typing import Tuple, List from contextlib import suppress -from itertools import chain +from dataclasses import dataclass +from typing import List, Tuple import ops import requests from charms.tls_certificates_interface.v3.tls_certificates import ( - CertificateCreationRequestEvent, TLSCertificatesProvidesV3, generate_ca, generate_certificate, @@ -105,21 +103,23 @@ def _on_collect_status(self, event: ops.CollectStatusEvent): def _on_gocert_notify(self, event: ops.PebbleCustomNoticeEvent): gocert_csrs = self._certificate_requests_table + assert gocert_csrs # TODO: error checking databag_csrs = self.tls.get_requirer_csrs() for csr in databag_csrs: - if csr not in [row.get("CSR") for row in gocert_csrs]: + if csr.csr not in [row.get("CSR", "") for row in gocert_csrs]: # TODO: error checking and signing up to gocert requests.post( url=f"https://{self._application_bind_address}:{self.port}/api/v1/certificate_requests", - data=csr, + data=csr.csr, headers={"Content-Type": "text/plain", "Authorization": "Bearer {token}"}, verify=f"{CHARM_PATH}/{CONFIG_MOUNT}/0/ca.pem", ) gocert_csrs = self._certificate_requests_table + assert gocert_csrs # TODO: error checking for row in gocert_csrs: gocert_csr = row.get("CSR") - gocert_cert = row.get("Certificate") + # gocert_cert = row.get("Certificate") for databag_csr in databag_csrs: if not databag_csr != gocert_csr: continue @@ -199,7 +199,7 @@ def _certificate_requests_table(self) -> List[dict[str, str]] | None: ## Status Checks ## def _storages_attached(self) -> bool: """Return if the storages are attached.""" - return self.model.storages.get("config") and self.model.storages.get("database") + return self.model.storages.get("config") and self.model.storages.get("database") # type: ignore def _gocert_available(self) -> bool: """Return if the gocert server is reachable.""" diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index d2f7d43..c7ec8a5 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -9,7 +9,7 @@ import pytest import requests from charm import GocertCharm -from scenario import Container, Context, Event, Network, Relation, State, Storage +from scenario import Container, Context, Event, Network, State, Storage # https://res.cloudinary.com/canonical/image/fetch/f_auto,q_auto/https://discourse-charmhub-io.s3.eu-west-2.amazonaws.com/original/2X/4/4ac42dc8a238a003c7d56fe282246ca102dd594f.png @@ -126,9 +126,3 @@ def test_configure_handler( assert out.unit_status == ops.BlockedStatus("Please initialize GoCert") if storage_ready and container_ready and network_ready and gocert_status == "initialized": assert out.unit_status == ops.ActiveStatus() - - def test_on_gocert_notify_handler(): - pass - - def test_on_certificate_request_handler(): - pass