From 79375ed0e3d69696bb6501032fe6135c0b73b5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20C=2E=20Mass=C3=B3n?= Date: Wed, 13 Nov 2024 22:37:09 -0300 Subject: [PATCH] update cloud_config_requirer lib --- .../v0/cloud_config_requirer.py | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/lib/charms/grafana_cloud_integrator/v0/cloud_config_requirer.py b/lib/charms/grafana_cloud_integrator/v0/cloud_config_requirer.py index 8fd85509..59f72e7b 100644 --- a/lib/charms/grafana_cloud_integrator/v0/cloud_config_requirer.py +++ b/lib/charms/grafana_cloud_integrator/v0/cloud_config_requirer.py @@ -6,7 +6,7 @@ LIBID = "e6f580481c1b4388aa4d2cdf412a47fa" LIBAPI = 0 -LIBPATCH = 6 +LIBPATCH = 7 DEFAULT_RELATION_NAME = "grafana-cloud-config" @@ -57,7 +57,7 @@ def _on_relation_changed(self, event): def _on_relation_broken(self, event): self.on.cloud_config_revoked.emit() # pyright: ignore - + def _is_not_empty(self, s): return bool(s and not s.isspace()) @@ -83,16 +83,8 @@ def _events(self): @property def credentials(self): """Return the credentials, if any; otherwise, return None.""" - if not all( - self._is_not_empty(x) - for x in [ - self._data.get("username", ""), - self._data.get("password", ""), - ]): - return Credentials( - self._data.get("username", ""), - self._data.get("password", "") - ) + if (username := self._data.get("username", "").strip()) and (password := self._data.get("password", "").strip()): + return Credentials(username, password) return None @property @@ -124,7 +116,7 @@ def prometheus_endpoint(self) -> dict: """Return the prometheus endpoint dict.""" if not self.prometheus_ready: return {} - + endpoint = {} endpoint["url"] = self.prometheus_url if self.credentials: @@ -148,4 +140,4 @@ def _data(self): for relation in self._charm.model.relations[self._relation_name]: logger.info("%s %s %s", relation, self._relation_name, relation.data[relation.app]) return relation.data[relation.app] - return {} \ No newline at end of file + return {}