mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
mqtt: remove code for unsupported Python versions (#10980)
* mqtt: remove code for unsupported Python versions * add changelog frag
This commit is contained in:
2
changelogs/fragments/10980-mqtt-ssl.yml
Normal file
2
changelogs/fragments/10980-mqtt-ssl.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
minor_changes:
|
||||||
|
- mqtt - remove provisions for unsupported Python versions (https://github.com/ansible-collections/community.general/pull/10980).
|
||||||
@@ -120,9 +120,6 @@ EXAMPLES = r"""
|
|||||||
import os
|
import os
|
||||||
import ssl
|
import ssl
|
||||||
import traceback
|
import traceback
|
||||||
import platform
|
|
||||||
|
|
||||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
|
||||||
|
|
||||||
HAS_PAHOMQTT = True
|
HAS_PAHOMQTT = True
|
||||||
PAHOMQTT_IMP_ERR = None
|
PAHOMQTT_IMP_ERR = None
|
||||||
@@ -141,17 +138,16 @@ from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
|||||||
#
|
#
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
tls_map = {}
|
# From https://docs.python.org/3/library/ssl.html#constants, this:
|
||||||
|
#
|
||||||
try:
|
# > Deprecated since version 3.6: OpenSSL has deprecated all version specific protocols. Use the default protocol PROTOCOL_TLS_SERVER or
|
||||||
tls_map['tlsv1.2'] = ssl.PROTOCOL_TLSv1_2
|
# > PROTOCOL_TLS_CLIENT with SSLContext.minimum_version and SSLContext.maximum_version instead.
|
||||||
except AttributeError:
|
#
|
||||||
pass
|
# @TODO: update the use of `ssl` constants
|
||||||
|
tls_map = {
|
||||||
try:
|
'tlsv1.2': ssl.PROTOCOL_TLSv1_2,
|
||||||
tls_map['tlsv1.1'] = ssl.PROTOCOL_TLSv1_1
|
'tlsv1.1': ssl.PROTOCOL_TLSv1_1,
|
||||||
except AttributeError:
|
}
|
||||||
pass
|
|
||||||
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
@@ -202,16 +198,7 @@ def main():
|
|||||||
tls = None
|
tls = None
|
||||||
if ca_certs is not None:
|
if ca_certs is not None:
|
||||||
if tls_version:
|
if tls_version:
|
||||||
tls_version = tls_map.get(tls_version, ssl.PROTOCOL_SSLv23)
|
tls_version = tls_map.get(tls_version, ssl.PROTOCOL_TLS)
|
||||||
else:
|
|
||||||
if LooseVersion(platform.python_version()) <= LooseVersion("3.5.2"):
|
|
||||||
# Specifying `None` on later versions of python seems sufficient to
|
|
||||||
# instruct python to autonegotiate the SSL/TLS connection. On versions
|
|
||||||
# 3.5.2 and lower though we need to specify the version.
|
|
||||||
#
|
|
||||||
# Note that this is an alias for PROTOCOL_TLS, but PROTOCOL_TLS was
|
|
||||||
# not available until 3.5.3.
|
|
||||||
tls_version = ssl.PROTOCOL_SSLv23
|
|
||||||
|
|
||||||
tls = {
|
tls = {
|
||||||
'ca_certs': ca_certs,
|
'ca_certs': ca_certs,
|
||||||
|
|||||||
Reference in New Issue
Block a user