Skip to content

Commit

Permalink
directly vendor schema files (#110)
Browse files Browse the repository at this point in the history
* fixed dependencies

* moved cluster over to new dir

* ds exchange interface implementation

* typing

* add datasource exchange to coordinator

* utests

* fmt

* made the endpoints optional

* pr comments

* directly vendor schema files

* fmt

* removed update script

* fixed dependency paths

* added init files for pyright stubber

* simplified dir structure
  • Loading branch information
PietroPasotti authored Dec 10, 2024
1 parent 8ae974b commit 1b42954
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ dependencies = [
"pydantic",
"tenacity",
"jsonschema",
"cryptography",
"PyYAML",
"typing-extensions",
"lightkube>=v0.15.4",
"charm-relation-interfaces @ git+https://github.com/canonical/charm-relation-interfaces",
]
classifiers = [
"Programming Language :: Python :: 3.8",
Expand Down
26 changes: 21 additions & 5 deletions src/cosl/interfaces/datasource_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
for the interface specification.
"""


# FIXME: the interfaces import (because it's a git dep perhaps?)
# can't be type-checked, which breaks everything
# pyright: reportMissingImports=false
Expand All @@ -30,11 +29,8 @@
)

import ops
from interfaces.grafana_datasource_exchange.v0.schema import (
GrafanaDatasource,
GrafanaSourceAppData,
)
from ops import CharmBase
from pydantic import BaseModel, Field, Json
from typing_extensions import TypedDict

import cosl.interfaces.utils
Expand All @@ -45,6 +41,26 @@
DS_EXCHANGE_INTERFACE_NAME = "grafana_datasource_exchange"


# FIXME copy-pasta'd from charm-relation-interfaces. Keep in sync!
# see https://github.com/canonical/charm-relation-interfaces/issues/213
class GrafanaDatasource(BaseModel):
"""GrafanaDatasource model."""

type: str = Field(
description="Type of the datasource, typically one of "
"https://grafana.com/docs/grafana/latest/datasources/#built-in-core-data-sources.",
examples=["tempo", "loki", "prometheus", "elasticsearch"],
)
uid: str = Field(description="Grafana datasource UID, as assigned by Grafana.")
grafana_uid: str = Field(description="Grafana UID.")


class GrafanaSourceAppData(BaseModel):
"""Application databag model for both sides of this interface."""

datasources: Json[List[GrafanaDatasource]]


class DSExchangeAppData(cosl.interfaces.utils.DatabagModelV2, GrafanaSourceAppData):
"""App databag schema for both sides of this interface."""

Expand Down
2 changes: 1 addition & 1 deletion tests/test_datasource_exchange.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json

import pytest
from interfaces.grafana_datasource_exchange.v0.schema import GrafanaDatasource
from ops import CharmBase, Framework
from scenario import Context, Relation, State
from scenario.errors import UncaughtCharmError
Expand All @@ -10,6 +9,7 @@
DatasourceExchange,
DSExchangeAppData,
EndpointValidationError,
GrafanaDatasource,
)


Expand Down

0 comments on commit 1b42954

Please sign in to comment.