From 3388212eac8fa6aff2f5d766e62e33962816501b Mon Sep 17 00:00:00 2001 From: David Garcia Date: Fri, 5 Nov 2021 12:33:03 +0100 Subject: [PATCH] Fix grafana datasource authentication in Charmed OSM Change-Id: I7620f0a3b52f378f97fea92e8542418a5da36e5f Signed-off-by: David Garcia --- installers/charm/grafana/src/charm.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/installers/charm/grafana/src/charm.py b/installers/charm/grafana/src/charm.py index 778b5eb5..28d28ae3 100755 --- a/installers/charm/grafana/src/charm.py +++ b/installers/charm/grafana/src/charm.py @@ -148,16 +148,22 @@ class GrafanaCharm(CharmedOsmBase): prometheus_user = self.prometheus_client.user prometheus_password = self.prometheus_client.password enable_basic_auth = all([prometheus_user, prometheus_password]) + kwargs = { + "prometheus_host": self.prometheus_client.hostname, + "prometheus_port": self.prometheus_client.port, + "enable_basic_auth": enable_basic_auth, + "user": "", + "password": "", + } + if enable_basic_auth: + kwargs["user"] = f"basic_auth_user: {prometheus_user}" + kwargs[ + "password" + ] = f"secure_json_data:\n basicAuthPassword: {prometheus_password}" files_builder.add_file( "datasource_prometheus.yaml", Template(Path("templates/default_datasources.yaml").read_text()).substitute( - prometheus_host=self.prometheus_client.hostname, - prometheus_port=self.prometheus_client.port, - enable_basic_auth=enable_basic_auth, - user=f"user: {prometheus_user}" if enable_basic_auth else "", - password=f"password: {prometheus_password}" - if enable_basic_auth - else "", + **kwargs ), ) return files_builder.build() -- 2.25.1