From 79044cf3bf8494b3f7d3d47d510ea65b539281e6 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:01:08 +0200 Subject: [PATCH 1/3] refactor: compare datasources function --- plugins/modules/grafana_datasource.py | 42 +++++++++++++++------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index b011e5db..0e497696 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -537,25 +537,29 @@ def compare_datasources(new, current, compareSecureData=True): - if new["uid"] is None: - del current["uid"] - del new["uid"] - del current["typeLogoUrl"] - del current["id"] - if "version" in current: - del current["version"] - if "readOnly" in current: - del current["readOnly"] - if current["basicAuth"] is False: - if "basicAuthUser" in current: - del current["basicAuthUser"] - if "password" in current: - del current["password"] - if "basicAuthPassword" in current: - del current["basicAuthPassword"] - if current["type"] == "grafana-postgresql-datasource" and new["type"] == "postgres": - del current["type"] - del new["type"] + if new.get("uid") is None: + new.pop("uid", None) + current.pop("uid", None) + + for field in [ + "basicAuthPassword", + "id", + "password", + "readOnly", + "typeLogoUrl", + "version", + ]: + current.pop(field, None) + + if not current.get("basicAuth", True): + current.pop("basicAuthUser", None) + + if ( + current.get("type") == "grafana-postgresql-datasource" + and new.get("type") == "postgres" + ): + new.pop("type", None) + current.pop("type", None) # check if secureJsonData should be compared if not compareSecureData: From 34df25409d9641ebc3a9db444fb290c2c4435ff0 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:01:59 +0200 Subject: [PATCH 2/3] fix: delete field apiVersion in current ds for diff --- plugins/modules/grafana_datasource.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index 0e497696..8011ebf6 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -542,6 +542,7 @@ def compare_datasources(new, current, compareSecureData=True): current.pop("uid", None) for field in [ + "apiVersion", "basicAuthPassword", "id", "password", From c24a8a709bf1ac63da5161938facb2453b69348a Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:06:40 +0200 Subject: [PATCH 3/3] docs: changelog fragment --- changelogs/fragments/396-datasource-diff-apiversion.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/396-datasource-diff-apiversion.yml diff --git a/changelogs/fragments/396-datasource-diff-apiversion.yml b/changelogs/fragments/396-datasource-diff-apiversion.yml new file mode 100644 index 00000000..03be7315 --- /dev/null +++ b/changelogs/fragments/396-datasource-diff-apiversion.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Remove field `apiVersion` from return of current `grafana_datasource` for working diff