Fix deprecated warnings

(cherry picked from commit 98fb47b061)
pull/38889/head
Rémy Léone 7 years ago committed by Toshio Kuratomi
parent f5befa5ab4
commit 24c1e2ed0a

@ -107,11 +107,12 @@ slug:
sample: foo sample: foo
''' '''
import base64
import json import json
import os import base64
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url from ansible.module_utils.urls import fetch_url
from ansible.module_utils._text import to_bytes
__metaclass__ = type __metaclass__ = type
@ -166,7 +167,7 @@ def grafana_create_dashboard(module, data):
if 'grafana_api_key' in data and data['grafana_api_key']: if 'grafana_api_key' in data and data['grafana_api_key']:
headers['Authorization'] = "Bearer %s" % data['grafana_api_key'] headers['Authorization'] = "Bearer %s" % data['grafana_api_key']
else: else:
auth = base64.encodestring('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '') auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', ''))
headers['Authorization'] = 'Basic %s' % auth headers['Authorization'] = 'Basic %s' % auth
grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers) grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers)
@ -224,7 +225,7 @@ def grafana_delete_dashboard(module, data):
if 'grafana_api_key' in data and data['grafana_api_key']: if 'grafana_api_key' in data and data['grafana_api_key']:
headers['Authorization'] = "Bearer %s" % data['grafana_api_key'] headers['Authorization'] = "Bearer %s" % data['grafana_api_key']
else: else:
auth = base64.encodestring('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '') auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', ''))
headers['Authorization'] = 'Basic %s' % auth headers['Authorization'] = 'Basic %s' % auth
grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers) grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers)
@ -257,7 +258,7 @@ def grafana_export_dashboard(module, data):
if 'grafana_api_key' in data and data['grafana_api_key']: if 'grafana_api_key' in data and data['grafana_api_key']:
headers['Authorization'] = "Bearer %s" % data['grafana_api_key'] headers['Authorization'] = "Bearer %s" % data['grafana_api_key']
else: else:
auth = base64.encodestring('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '') auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', ''))
headers['Authorization'] = 'Basic %s' % auth headers['Authorization'] = 'Basic %s' % auth
grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers) grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers)

@ -243,11 +243,12 @@ after:
"withCredentials": false } "withCredentials": false }
''' '''
import base64
import json import json
import os import base64
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url from ansible.module_utils.urls import fetch_url
from ansible.module_utils._text import to_bytes
__metaclass__ = type __metaclass__ = type
@ -349,7 +350,7 @@ def grafana_create_datasource(module, data):
if 'grafana_api_key' in data and data['grafana_api_key'] is not None: if 'grafana_api_key' in data and data['grafana_api_key'] is not None:
headers['Authorization'] = "Bearer %s" % data['grafana_api_key'] headers['Authorization'] = "Bearer %s" % data['grafana_api_key']
else: else:
auth = base64.encodestring('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '') auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', ''))
headers['Authorization'] = 'Basic %s' % auth headers['Authorization'] = 'Basic %s' % auth
grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers) grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers)
@ -409,7 +410,7 @@ def grafana_delete_datasource(module, data):
if 'grafana_api_key' in data and data['grafana_api_key']: if 'grafana_api_key' in data and data['grafana_api_key']:
headers['Authorization'] = "Bearer %s" % data['grafana_api_key'] headers['Authorization'] = "Bearer %s" % data['grafana_api_key']
else: else:
auth = base64.encodestring('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', '') auth = base64.b64encode(to_bytes('%s:%s' % (data['grafana_user'], data['grafana_password'])).replace('\n', ''))
headers['Authorization'] = 'Basic %s' % auth headers['Authorization'] = 'Basic %s' % auth
grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers) grafana_switch_organisation(module, data['grafana_url'], data['org_id'], headers)

@ -164,19 +164,20 @@ EXAMPLES = '''
service: '{{ pd_window.result.maintenance_window.id }}' service: '{{ pd_window.result.maintenance_window.id }}'
''' '''
import base64
import datetime import datetime
import json import json
import base64
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url from ansible.module_utils.urls import fetch_url
from ansible.module_utils._text import to_bytes
def auth_header(user, passwd, token): def auth_header(user, passwd, token):
if token: if token:
return "Token token=%s" % token return "Token token=%s" % token
auth = base64.encodestring('%s:%s' % (user, passwd)).replace('\n', '') auth = base64.b64encode(to_bytes('%s:%s' % (user, passwd)).replace('\n', ''))
return "Basic %s" % auth return "Basic %s" % auth

@ -88,14 +88,14 @@ EXAMPLES = '''
action: disable action: disable
''' '''
import base64
import json import json
import socket import socket
import traceback import traceback
import base64
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import urlencode from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils._text import to_native from ansible.module_utils._text import to_native, to_bytes
from ansible.module_utils.urls import fetch_url from ansible.module_utils.urls import fetch_url
@ -115,7 +115,7 @@ class netscaler(object):
if not len(data_json): if not len(data_json):
data_json = None data_json = None
auth = base64.encodestring('%s:%s' % (self._nsc_user, self._nsc_pass)).replace('\n', '').strip() auth = base64.b64encode(to_bytes('%s:%s' % (self._nsc_user, self._nsc_pass)).replace('\n', '').strip())
headers = { headers = {
'Authorization': 'Basic %s' % auth, 'Authorization': 'Basic %s' % auth,
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',

@ -80,15 +80,16 @@ EXAMPLES = '''
delegate_to: localhost delegate_to: localhost
''' '''
import base64
import json import json
import base64
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url from ansible.module_utils.urls import fetch_url
from ansible.module_utils._text import to_bytes
def request(module, url, user, oauthkey, data='', method='GET'): def request(module, url, user, oauthkey, data='', method='GET'):
auth = base64.encodestring('%s:%s' % (user, oauthkey)).replace('\n', '') auth = base64.b64encode(to_bytes('%s:%s' % (user, oauthkey)).replace('\n', ''))
headers = { headers = {
'Authorization': 'Basic %s' % auth, 'Authorization': 'Basic %s' % auth,
} }

Loading…
Cancel
Save