mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
Fix undefined variables, basestring usage, and some associated python3 issues
This commit is contained in:
@@ -385,19 +385,18 @@ EXAMPLES = '''
|
||||
# DNSMadeEasy module specific support methods.
|
||||
#
|
||||
|
||||
import json
|
||||
import hashlib
|
||||
import hmac
|
||||
from time import strftime, gmtime
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||
from ansible.module_utils.six import string_types
|
||||
|
||||
IMPORT_ERROR = None
|
||||
try:
|
||||
import json
|
||||
from time import strftime, gmtime
|
||||
import hashlib
|
||||
import hmac
|
||||
except ImportError:
|
||||
e = get_exception()
|
||||
IMPORT_ERROR = str(e)
|
||||
|
||||
class DME2:
|
||||
class DME2(object):
|
||||
|
||||
def __init__(self, apikey, secret, domain, module):
|
||||
self.module = module
|
||||
@@ -437,7 +436,7 @@ class DME2:
|
||||
|
||||
def query(self, resource, method, data=None):
|
||||
url = self.baseurl + resource
|
||||
if data and not isinstance(data, basestring):
|
||||
if data and not isinstance(data, string_types):
|
||||
data = urlencode(data)
|
||||
|
||||
response, info = fetch_url(self.module, url, data=data, method=method, headers=self._headers())
|
||||
@@ -601,9 +600,6 @@ def main():
|
||||
]
|
||||
)
|
||||
|
||||
if IMPORT_ERROR:
|
||||
module.fail_json(msg="Import Error: " + IMPORT_ERROR)
|
||||
|
||||
protocols = dict(TCP=1, UDP=2, HTTP=3, DNS=4, SMTP=5, HTTPS=6)
|
||||
sensitivities = dict(Low=8, Medium=5, High=3)
|
||||
|
||||
@@ -727,9 +723,6 @@ def main():
|
||||
module.fail_json(
|
||||
msg="'%s' is an unknown value for the state argument" % state)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.urls import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -156,8 +156,7 @@ RETURN = """
|
||||
# Default return values
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import ldap
|
||||
@@ -168,6 +167,10 @@ try:
|
||||
except ImportError:
|
||||
HAS_LDAP = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
class LdapEntry(object):
|
||||
def __init__(self, module):
|
||||
@@ -251,19 +254,19 @@ class LdapEntry(object):
|
||||
if self.start_tls:
|
||||
try:
|
||||
connection.start_tls_s()
|
||||
except ldap.LDAPError:
|
||||
e = get_exception()
|
||||
self.module.fail_json(msg="Cannot start TLS.", details=str(e))
|
||||
except ldap.LDAPError as e:
|
||||
self.module.fail_json(msg="Cannot start TLS.", details=to_native(e),
|
||||
exception=traceback.format_exc())
|
||||
|
||||
try:
|
||||
if self.bind_dn is not None:
|
||||
connection.simple_bind_s(self.bind_dn, self.bind_pw)
|
||||
else:
|
||||
connection.sasl_interactive_bind_s('', ldap.sasl.external())
|
||||
except ldap.LDAPError:
|
||||
e = get_exception()
|
||||
except ldap.LDAPError as e:
|
||||
self.module.fail_json(
|
||||
msg="Cannot bind to the server.", details=str(e))
|
||||
msg="Cannot bind to the server.", details=to_native(e),
|
||||
exception=traceback.format_exc())
|
||||
|
||||
return connection
|
||||
|
||||
@@ -298,7 +301,7 @@ def main():
|
||||
# Check if objectClass is of the correct type
|
||||
if (
|
||||
module.params['objectClass'] is not None and not (
|
||||
isinstance(module.params['objectClass'], basestring) or
|
||||
isinstance(module.params['objectClass'], string_types) or
|
||||
isinstance(module.params['objectClass'], list))):
|
||||
module.fail_json(msg="objectClass must be either a string or a list.")
|
||||
|
||||
@@ -326,9 +329,8 @@ def main():
|
||||
if action is not None and not module.check_mode:
|
||||
try:
|
||||
action()
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="Entry action failed.", details=str(e))
|
||||
except Exception as e:
|
||||
module.fail_json(msg="Entry action failed.", details=to_native(e), exception=traceback.format_exc())
|
||||
|
||||
module.exit_json(changed=(action is not None))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user