Skip to content

Commit

Permalink
update cloud_config_requirer lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Abuelodelanada committed Nov 14, 2024
1 parent 1bb705e commit 79375ed
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions lib/charms/grafana_cloud_integrator/v0/cloud_config_requirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

LIBID = "e6f580481c1b4388aa4d2cdf412a47fa"
LIBAPI = 0
LIBPATCH = 6
LIBPATCH = 7

DEFAULT_RELATION_NAME = "grafana-cloud-config"

Expand Down Expand Up @@ -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())

Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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 {}
return {}

0 comments on commit 79375ed

Please sign in to comment.