Skip to content

Commit

Permalink
tox & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kayra1 committed Aug 1, 2024
1 parent 197b351 commit c69d024
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
8 changes: 1 addition & 7 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit c69d024

Please sign in to comment.