Skip to content

Commit

Permalink
fix: use cert_handler v1
Browse files Browse the repository at this point in the history
  • Loading branch information
nsklikas committed Apr 19, 2024
1 parent 5b84ff7 commit b941d3c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from charms.glauth_utils.v0.glauth_auxiliary import AuxiliaryProvider, AuxiliaryRequestedEvent
from charms.grafana_k8s.v0.grafana_dashboard import GrafanaDashboardProvider
from charms.loki_k8s.v0.loki_push_api import LogProxyConsumer, PromtailDigestError
from charms.observability_libs.v0.cert_handler import CertChanged
from charms.observability_libs.v1.cert_handler import CertChanged
from charms.observability_libs.v0.kubernetes_service_patch import KubernetesServicePatch
from charms.prometheus_k8s.v0.prometheus_scrape import MetricsEndpointProvider
from configs import ConfigFile, DatabaseConfig, StartTLSConfig, pebble_layer
Expand Down
15 changes: 7 additions & 8 deletions src/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from charms.glauth_k8s.v0.ldap import LdapProviderBaseData, LdapProviderData
from charms.glauth_utils.v0.glauth_auxiliary import AuxiliaryData
from charms.observability_libs.v0.cert_handler import CertHandler
from charms.observability_libs.v1.cert_handler import CertHandler
from configs import DatabaseConfig
from constants import (
CERTIFICATE_FILE,
Expand Down Expand Up @@ -134,7 +134,7 @@ def auxiliary_data(self) -> AuxiliaryData:
@dataclass
class CertificateData:
ca_cert: Optional[str] = None
ca_chain: Optional[list[str]] = None
ca_chain: Optional[str] = None
cert: Optional[str] = None


Expand All @@ -147,28 +147,27 @@ def __init__(self, charm: CharmBase) -> None:
self.cert_handler = CertHandler(
charm,
key="glauth-server-cert",
peer_relation_name="glauth-peers",
cert_subject=hostname,
extra_sans_dns=[
sans=[
hostname,
f"{charm.app.name}.{charm.model.name}.svc.cluster.local",
],
)

@property
def _ca_cert(self) -> Optional[str]:
return self.cert_handler.ca
return self.cert_handler.ca_cert

@property
def _server_key(self) -> Optional[str]:
return self.cert_handler.key
return self.cert_handler.private_key

@property
def _server_cert(self) -> Optional[str]:
return self.cert_handler.cert
return self.cert_handler.server_cert

@property
def _ca_chain(self) -> list[str]:
def _ca_chain(self) -> Optional[str]:
return self.cert_handler.chain

@property
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

import os
from typing import Callable
from unittest.mock import MagicMock

Expand Down Expand Up @@ -204,3 +205,8 @@ def certificates_transfer_relation(harness: Harness) -> int:
)
harness.add_relation_unit(relation_id, f"{CERTIFICATES_TRANSFER_CLIENT_APP}/0")
return relation_id


@pytest.fixture(autouse=True)
def mocked_juju_version(mocker: MockerFixture) -> MagicMock:
return mocker.patch.dict(os.environ, {"JUJU_VERSION": "3.2.1"})

0 comments on commit b941d3c

Please sign in to comment.