Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(grafana_datasource): orgId by name if defined to compare diff #345

Merged
merged 7 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/345-datasource-compare-diff-orgid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- Fixed orgId handling in diff comparison for `grafana_datasource` if using org_name
11 changes: 6 additions & 5 deletions plugins/modules/grafana_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@
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"],
Expand Down Expand Up @@ -688,6 +688,7 @@
def __init__(self, module):
self._module = module
self.grafana_url = base.clean_url(module.params.get("url"))
self.org_id = None

Check warning on line 691 in plugins/modules/grafana_datasource.py

View check run for this annotation

Codecov / codecov/patch

plugins/modules/grafana_datasource.py#L691

Added line #L691 was not covered by tests
# {{{ Authentication header
self.headers = {"Content-Type": "application/json"}
if module.params.get("grafana_api_key", None):
Expand All @@ -698,12 +699,12 @@
self.headers["Authorization"] = basic_auth_header(
module.params["url_username"], module.params["url_password"]
)
org_id = (
self.org_id = (

Check warning on line 702 in plugins/modules/grafana_datasource.py

View check run for this annotation

Codecov / codecov/patch

plugins/modules/grafana_datasource.py#L702

Added line #L702 was not covered by tests
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)

Check warning on line 707 in plugins/modules/grafana_datasource.py

View check run for this annotation

Codecov / codecov/patch

plugins/modules/grafana_datasource.py#L707

Added line #L707 was not covered by tests
# }}}

def _send_request(self, url, data=None, headers=None, method="GET"):
Expand Down Expand Up @@ -923,7 +924,7 @@
ds = grafana_iface.datasource_by_name(name)

if state == "present":
payload = get_datasource_payload(module.params)
payload = get_datasource_payload(module.params, grafana_iface.org_id)

Check warning on line 927 in plugins/modules/grafana_datasource.py

View check run for this annotation

Codecov / codecov/patch

plugins/modules/grafana_datasource.py#L927

Added line #L927 was not covered by tests
if ds is None:
grafana_iface.create_datasource(payload)
ds = grafana_iface.datasource_by_name(name)
Expand Down
Loading