Skip to content

Commit

Permalink
refactor: definition of org_id variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemental authored and rndmh3ro committed Jan 18, 2024
1 parent 1acfb76 commit 3f4aa3d
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions plugins/modules/grafana_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3f4aa3d

Please sign in to comment.