From a390e9720365a6a1bbfaf3661ee34d30643221e7 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Wed, 17 Jan 2024 14:19:36 +0100 Subject: [PATCH 1/9] fix: orgId by name if defined to compare diff --- plugins/modules/grafana_datasource.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index be631836..ffc8d952 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -559,9 +559,9 @@ def compare_datasources(new, current, compareSecureData=True): return dict(before=current, after=new) -def get_datasource_payload(data): +def get_datasource_payload(data, org_id): payload = { - "orgId": data["org_id"], + "orgId": org_id, "name": data["name"], "uid": data["uid"], "type": data["ds_type"], @@ -921,9 +921,14 @@ def main(): grafana_iface = GrafanaInterface(module) ds = grafana_iface.datasource_by_name(name) + org_id = ( + grafana_iface.organization_by_name(module.params["org_name"]) + if module.params["org_name"] + else module.params["org_id"] + ) if state == "present": - payload = get_datasource_payload(module.params) + payload = get_datasource_payload(module.params, org_id) if ds is None: grafana_iface.create_datasource(payload) ds = grafana_iface.datasource_by_name(name) From 39f23044ef416c65a12d8ab2106279c328ba064a Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Wed, 17 Jan 2024 14:30:28 +0100 Subject: [PATCH 2/9] chore: changelog fragment --- changelogs/fragments/345-datasource-compare-diff-orgid.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/345-datasource-compare-diff-orgid.yml diff --git a/changelogs/fragments/345-datasource-compare-diff-orgid.yml b/changelogs/fragments/345-datasource-compare-diff-orgid.yml new file mode 100644 index 00000000..14de8aca --- /dev/null +++ b/changelogs/fragments/345-datasource-compare-diff-orgid.yml @@ -0,0 +1,3 @@ +--- +bugfix: + - `grafana_datasource` get orgId by name if defined to compare diff From f89f2ea866759380ee0da885d208a91b9c246d51 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Wed, 17 Jan 2024 14:33:25 +0100 Subject: [PATCH 3/9] chore: fragment category --- changelogs/fragments/345-datasource-compare-diff-orgid.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/345-datasource-compare-diff-orgid.yml b/changelogs/fragments/345-datasource-compare-diff-orgid.yml index 14de8aca..a535c776 100644 --- a/changelogs/fragments/345-datasource-compare-diff-orgid.yml +++ b/changelogs/fragments/345-datasource-compare-diff-orgid.yml @@ -1,3 +1,3 @@ --- -bugfix: +bugfixes: - `grafana_datasource` get orgId by name if defined to compare diff From b9472a7498d2ca50661eba9758953ffb96736b17 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Wed, 17 Jan 2024 15:05:14 +0100 Subject: [PATCH 4/9] chore: simplify --- plugins/modules/grafana_datasource.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index ffc8d952..c911900f 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -559,9 +559,9 @@ def compare_datasources(new, current, compareSecureData=True): return dict(before=current, after=new) -def get_datasource_payload(data, org_id): +def get_datasource_payload(data): payload = { - "orgId": org_id, + "orgId": data["org_id"], "name": data["name"], "uid": data["uid"], "type": data["ds_type"], @@ -921,14 +921,15 @@ def main(): grafana_iface = GrafanaInterface(module) ds = grafana_iface.datasource_by_name(name) - org_id = ( - grafana_iface.organization_by_name(module.params["org_name"]) - if module.params["org_name"] - else module.params["org_id"] - ) if state == "present": - payload = get_datasource_payload(module.params, org_id) + params = module.params + params["org_id"] = ( + grafana_iface.organization_by_name(params["org_name"]) + if params["org_name"] + else params["org_id"] + ) + payload = get_datasource_payload(params) if ds is None: grafana_iface.create_datasource(payload) ds = grafana_iface.datasource_by_name(name) From 63db02f541687b2dfe66defff73b6de77e7cb4c8 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Wed, 17 Jan 2024 15:12:12 +0100 Subject: [PATCH 5/9] chore: fixed changelog fragment --- changelogs/fragments/345-datasource-compare-diff-orgid.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/345-datasource-compare-diff-orgid.yml b/changelogs/fragments/345-datasource-compare-diff-orgid.yml index a535c776..11c21141 100644 --- a/changelogs/fragments/345-datasource-compare-diff-orgid.yml +++ b/changelogs/fragments/345-datasource-compare-diff-orgid.yml @@ -1,3 +1,3 @@ --- bugfixes: - - `grafana_datasource` get orgId by name if defined to compare diff + - Fixed orgId handling in diff comparison for `grafana_datasource` if using org_name From 1acfb76ba3902e777e6abd0bcf17700d4a9fd14b Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Thu, 18 Jan 2024 10:57:41 +0100 Subject: [PATCH 6/9] refactor: get ds payload optional org_id parameter --- plugins/modules/grafana_datasource.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index c911900f..910e16bb 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -559,9 +559,9 @@ def compare_datasources(new, current, compareSecureData=True): return dict(before=current, after=new) -def get_datasource_payload(data): +def get_datasource_payload(data, org_id=None): payload = { - "orgId": data["org_id"], + "orgId": data["org_id"] if org_id is None else org_id, "name": data["name"], "uid": data["uid"], "type": data["ds_type"], @@ -923,13 +923,12 @@ def main(): ds = grafana_iface.datasource_by_name(name) if state == "present": - params = module.params - params["org_id"] = ( - grafana_iface.organization_by_name(params["org_name"]) - if params["org_name"] - else params["org_id"] + org_id = ( + grafana_iface.organization_by_name(module.params["org_name"]) + if module.params["org_name"] + else module.params["org_id"] ) - payload = get_datasource_payload(params) + payload = get_datasource_payload(module.params, org_id) if ds is None: grafana_iface.create_datasource(payload) ds = grafana_iface.datasource_by_name(name) From 3f4aa3d79c3f5343b705784a4e2d2da8ccd708a3 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Thu, 18 Jan 2024 13:36:07 +0100 Subject: [PATCH 7/9] refactor: definition of org_id variable --- plugins/modules/grafana_datasource.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py index 910e16bb..37849998 100644 --- a/plugins/modules/grafana_datasource.py +++ b/plugins/modules/grafana_datasource.py @@ -688,6 +688,7 @@ class GrafanaInterface(object): def __init__(self, module): self._module = module self.grafana_url = base.clean_url(module.params.get("url")) + self.org_id = None # {{{ Authentication header self.headers = {"Content-Type": "application/json"} if module.params.get("grafana_api_key", None): @@ -698,12 +699,12 @@ def __init__(self, module): self.headers["Authorization"] = basic_auth_header( module.params["url_username"], module.params["url_password"] ) - org_id = ( + self.org_id = ( self.organization_by_name(module.params["org_name"]) if module.params["org_name"] else module.params["org_id"] ) - self.switch_organization(org_id) + self.switch_organization(self.org_id) # }}} def _send_request(self, url, data=None, headers=None, method="GET"): @@ -923,12 +924,7 @@ def main(): ds = grafana_iface.datasource_by_name(name) if state == "present": - org_id = ( - grafana_iface.organization_by_name(module.params["org_name"]) - if module.params["org_name"] - else module.params["org_id"] - ) - payload = get_datasource_payload(module.params, org_id) + payload = get_datasource_payload(module.params, grafana_iface.org_id) if ds is None: grafana_iface.create_datasource(payload) ds = grafana_iface.datasource_by_name(name) From bd6615ec90b614e2bed913e5634ec3079bb62353 Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Wed, 17 Jan 2024 09:23:07 +0100 Subject: [PATCH 8/9] build(1.7.0): release version --- CHANGELOG.rst | 18 ++++++++++++++++++ changelogs/changelog.yaml | 26 ++++++++++++++++++++++++++ galaxy.yml | 2 +- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5385a3f3..14e523c4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,24 @@ Grafana Collection Release Notes .. contents:: Topics +v1.7.0 +====== + +Minor Changes +------------- + +- Add Quickwit search engine datasource (https://quickwit.io). +- Add parameter `org_name` to `grafana_dashboard` +- Add parameter `org_name` to `grafana_datasource` +- Add parameter `org_name` to `grafana_organization_user` +- Add support for Grafana Tempo datasource type (https://grafana.com/docs/grafana/latest/datasources/tempo/) +- default to true/false in docs and code + +Bugfixes +-------- + +- Add `grafana_organiazion_user` to `action_groups.grafana` + v1.6.1 ====== diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 0f1f2932..91a04d23 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -234,3 +234,29 @@ releases: - 300_datasource_prometheus_time_interval.yml - fix-316.yml release_date: '2023-11-05' + 1.7.0: + changes: + bugfixes: + - Add `grafana_organiazion_user` to `action_groups.grafana` + minor_changes: + - Add Quickwit search engine datasource (https://quickwit.io). + - Add parameter `org_name` to `grafana_dashboard` + - Add parameter `org_name` to `grafana_datasource` + - Add parameter `org_name` to `grafana_organization_user` + - Add support for Grafana Tempo datasource type (https://grafana.com/docs/grafana/latest/datasources/tempo/) + - default to true/false in docs and code + fragments: + - 238_checkmode.yml + - 308_datasource_quickwit.yml + - 318-org_users_by_org_name.yml + - 321-action-groups-org-users.yml + - 324_formatting.yml + - 325_linting.yml + - 325_true_false.yml + - 331-dashboard-by-org-name.yml + - 332-datasource-by-org-name.yml + - 335-add-datasource-type-tempo.yml + - 339-lint-black.yml + - 341-lint-ruff.yml + - 342-ruff-findings.yml + release_date: '2024-01-17' diff --git a/galaxy.yml b/galaxy.yml index dbfb2d93..b8560002 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,7 +1,7 @@ --- namespace: community name: grafana -version: 1.6.1 +version: 1.7.0 readme: README.md authors: - RĂ©mi REY (@rrey) From 195f9d1287c1a6ab0b97f484ddea09b31845fe1c Mon Sep 17 00:00:00 2001 From: Nemental <15136847+Nemental@users.noreply.github.com> Date: Thu, 18 Jan 2024 13:55:35 +0100 Subject: [PATCH 9/9] docs: update changelog --- CHANGELOG.rst | 1 + changelogs/changelog.yaml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 14e523c4..bb44be3c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -22,6 +22,7 @@ Bugfixes -------- - Add `grafana_organiazion_user` to `action_groups.grafana` +- Fixed orgId handling in diff comparison for `grafana_datasource` if using org_name v1.6.1 ====== diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 91a04d23..0a778f3b 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -238,6 +238,8 @@ releases: changes: bugfixes: - Add `grafana_organiazion_user` to `action_groups.grafana` + - Fixed orgId handling in diff comparison for `grafana_datasource` if using + org_name minor_changes: - Add Quickwit search engine datasource (https://quickwit.io). - Add parameter `org_name` to `grafana_dashboard` @@ -259,4 +261,5 @@ releases: - 339-lint-black.yml - 341-lint-ruff.yml - 342-ruff-findings.yml + - 345-datasource-compare-diff-orgid.yml release_date: '2024-01-17'