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

grafana_datasource: use the Ansible helpers to get basic auth header #54183

Merged
merged 2 commits into from
Mar 25, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- grafana_datasource - Fixed an issue when running Python3 and using basic auth
(https://github.com/ansible/ansible/issues/49147)
8 changes: 3 additions & 5 deletions lib/ansible/modules/monitoring/grafana_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
import base64

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url
from ansible.module_utils.urls import fetch_url, basic_auth_header
from ansible.module_utils._text import to_bytes

__metaclass__ = type
Expand Down Expand Up @@ -373,8 +373,7 @@ def grafana_create_datasource(module, data):
if 'grafana_api_key' in data and data['grafana_api_key'] is not None:
headers['Authorization'] = "Bearer %s" % data['grafana_api_key']
else:
auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', ''))
headers['Authorization'] = 'Basic %s' % auth
headers['Authorization'] = basic_auth_header(data['grafana_user'], data['grafana_password'])
grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers)

# test if datasource already exists
Expand Down Expand Up @@ -433,8 +432,7 @@ def grafana_delete_datasource(module, data):
if 'grafana_api_key' in data and data['grafana_api_key']:
headers['Authorization'] = "Bearer %s" % data['grafana_api_key']
else:
auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', ''))
headers['Authorization'] = 'Basic %s' % auth
headers['Authorization'] = basic_auth_header(data['grafana_user'], data['grafana_password'])
grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers)

# test if datasource already exists
Expand Down