diff --git a/lib/charms/grafana_k8s/v0/grafana_source.py b/lib/charms/grafana_k8s/v0/grafana_source.py index 66277621..6f2f4ef4 100644 --- a/lib/charms/grafana_k8s/v0/grafana_source.py +++ b/lib/charms/grafana_k8s/v0/grafana_source.py @@ -32,6 +32,8 @@ `refresh_event`: A `PebbleReady` event from `charm`, used to refresh the IP address sent to Grafana on a charm lifecycle event or pod restart + `extra_fields`: None + `secure_extra_fields`: None The value of `source_url` should be a fully-resolvable URL for a valid Grafana source, e.g., `http://example.com/api` or similar. @@ -160,7 +162,7 @@ def __init__(self, *args): # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 20 +LIBPATCH = 21 logger = logging.getLogger(__name__) @@ -324,6 +326,7 @@ def __init__( refresh_event: Optional[Union[BoundEvent, List[BoundEvent]]] = None, relation_name: str = DEFAULT_RELATION_NAME, extra_fields: Optional[dict] = None, + secure_extra_fields: Optional[dict] = None, ) -> None: """Construct a Grafana charm client. @@ -364,6 +367,8 @@ def __init__( machine/VM restart. extra_fields: a :dict: which is used for additional information required for some datasources in the `jsonData` field + secure_extra_fields: a :dict: which is used for additional information required + for some datasources in the `secureJsonData` """ _validate_relation_by_interface_and_direction( charm, relation_name, RELATION_INTERFACE_NAME, RelationRole.provides @@ -382,6 +387,7 @@ def __init__( extra_fields["implementation"] = "prometheus" self._extra_fields = extra_fields + self._secure_extra_fields = secure_extra_fields if not refresh_event: if len(self._charm.meta.containers) == 1: @@ -450,6 +456,7 @@ def _scrape_data(self) -> Dict: "application": str(self._charm.model.app.name), "type": self._source_type, "extra_fields": self._extra_fields, + "secure_extra_fields": self._secure_extra_fields, } return data @@ -574,6 +581,9 @@ def _get_source_config(self, rel: Relation): if source_data.get("extra_fields", None): host_data["extra_fields"] = source_data.get("extra_fields") + if source_data.get("secure_extra_fields", None): + host_data["secure_extra_fields"] = source_data.get("secure_extra_fields") + if host_data["source_name"] in sources_to_delete: sources_to_delete.remove(host_data["source_name"]) diff --git a/src/charm.py b/src/charm.py index 7d65faa9..3d5cd865 100755 --- a/src/charm.py +++ b/src/charm.py @@ -1131,6 +1131,8 @@ def _generate_datasource_config(self) -> str: } if source_info.get("extra_fields", None): source["jsonData"] = source_info.get("extra_fields") + if source_info.get("secure_extra_fields", None): + source["secureJsonData"] = source_info.get("secure_extra_fields") # set timeout for querying this data source timeout = int(source.get("jsonData", {}).get("timeout", 0)) diff --git a/tox.ini b/tox.ini index 11749116..d6ad5b75 100644 --- a/tox.ini +++ b/tox.ini @@ -105,7 +105,7 @@ deps = aiohttp asyncstdlib # Libjuju needs to track the juju version - juju ~= 3.3.0 + juju<=3.3.0,>=3.0 pytest pytest-operator pytest-playwright