Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/nested catalogues #147

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions charm/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ provides:
interface: catalogue

requires:
catalogue-item:
interface: catalogue
description: |
Add this catalogue to the index of another catalogue instance.
ingress:
interface: ingress
limit: 1
Expand Down
31 changes: 27 additions & 4 deletions charm/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
from typing import cast
from urllib.parse import urlparse

from charms.catalogue_k8s.v1.catalogue import CatalogueItemsChangedEvent, CatalogueProvider
from charms.catalogue_k8s.v1.catalogue import (
CatalogueConsumer,
CatalogueItem,
CatalogueItemsChangedEvent,
CatalogueProvider,
)
from charms.observability_libs.v1.cert_handler import CertHandler
from charms.tempo_coordinator_k8s.v0.charm_tracing import trace_charm
from charms.tempo_coordinator_k8s.v0.tracing import TracingEndpointRequirer, charm_tracing_config
Expand Down Expand Up @@ -64,24 +69,42 @@ def __init__(self, *args):
key="catalogue-server-cert",
sans=[socket.getfqdn()],
)

desc = f"A service catalogue containing {len(self._info.items)} items."

self._ingress = IngressPerAppRequirer(
charm=self,
port=self._internal_port,
strip_prefix=True,
redirect_https=True,
scheme=lambda: urlparse(self._internal_url).scheme,
)

self._catalogue_consumer = CatalogueConsumer(
charm=self,
relation_name="catalogue-item",
item=CatalogueItem(
name=f"{self.model.config['title']}",
icon="book-open-blank-variant-outline",
url=self._ingress.url or "about:blank",
description=desc,
),
)

self.framework.observe(
self.on.catalogue_pebble_ready, self._on_catalogue_pebble_ready # pyright: ignore
self.on.catalogue_pebble_ready,
self._on_catalogue_pebble_ready, # pyright: ignore
)
self.framework.observe(
self._info.on.items_changed, self._on_items_changed # pyright: ignore
self._info.on.items_changed,
self._on_items_changed, # pyright: ignore
)
self.framework.observe(self.on.upgrade_charm, self._on_upgrade)
self.framework.observe(self.on.config_changed, self._on_config_changed)
self.framework.observe(self._ingress.on.ready, self._on_ingress_ready) # pyright: ignore
self.framework.observe(
self._ingress.on.revoked, self._on_ingress_revoked # pyright: ignore
self._ingress.on.revoked,
self._on_ingress_revoked, # pyright: ignore
)
self.framework.observe(
self.server_cert.on.cert_changed, # pyright: ignore
Expand Down
14 changes: 3 additions & 11 deletions charm/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,18 @@ passenv =
[testenv:fmt]
description = Apply coding style standards to code
deps =
black
ruff
isort
commands =
isort {[vars]all_path}
black {[vars]all_path}
ruff check {[vars]all_path} --fix
ruff check --fix {[vars]all_path}
ruff format {[vars]all_path}

[testenv:lint]
description = Check code against coding style standards
deps =
black
ruff
codespell
commands =
codespell {[vars]lib_path}
codespell . --skip .git --skip .tox --skip build --skip lib --skip venv --skip .mypy_cache --skip nginx_config.py --skip tox.ini
codespell src/nginx_config.py -L anull
ruff check {[vars]all_path}
black --check --diff {[vars]all_path}
ruff format --check {[vars]all_path}

[testenv:static-{charm,lib}]
description = Run static analysis checks
Expand Down
Loading