Skip to content

Commit 9db4aad

Browse files
patchback[bot]russozfelixfontein
authored
[PR #11078/dcb580c4 backport][stable-12] discard Python 2 ssl handling (#11086)
discard Python 2 ssl handling (#11078) * discard Python 2 ssl handling * add changelog frag * Apply suggestion --------- (cherry picked from commit dcb580c) Co-authored-by: Alexei Znamensky <[email protected]> Co-authored-by: Felix Fontein <[email protected]>
1 parent b593c67 commit 9db4aad

File tree

5 files changed

+10
-41
lines changed

5 files changed

+10
-41
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
minor_changes:
2+
- cobbler_sync - remove conditional code handling SSL for unsupported versions of Python (https://github.com/ansible-collections/community.general/pull/11078).
3+
- cobbler_system - remove conditional code handling SSL for unsupported versions of Python (https://github.com/ansible-collections/community.general/pull/11078).
4+
- jenkins_job_info - remove conditional code handling SSL for unsupported versions of Python (https://github.com/ansible-collections/community.general/pull/11078).

plugins/modules/cobbler_sync.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,10 @@ def main():
110110

111111
start = now()
112112

113-
ssl_context = None
114-
if not validate_certs:
115-
try:
116-
ssl_context = ssl._create_unverified_context()
117-
except AttributeError:
118-
# Legacy Python that doesn't verify HTTPS certificates by default
119-
pass
120-
else:
121-
# Handle target environment that doesn't support HTTPS verification
122-
ssl._create_default_https_context = ssl._create_unverified_context
113+
ssl_context = None if validate_certs or not use_ssl else ssl._create_unverified_context()
123114

124115
url = "{proto}://{host}:{port}/cobbler_api".format(**module.params)
125-
if ssl_context:
126-
conn = xmlrpc_client.ServerProxy(url, context=ssl_context)
127-
else:
128-
conn = xmlrpc_client.Server(url)
116+
conn = xmlrpc_client.ServerProxy(url, context=ssl_context)
129117

130118
try:
131119
token = conn.login(username, password)

plugins/modules/cobbler_system.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,22 +232,10 @@ def main():
232232

233233
start = now()
234234

235-
ssl_context = None
236-
if not validate_certs:
237-
try:
238-
ssl_context = ssl._create_unverified_context()
239-
except AttributeError:
240-
# Legacy Python that doesn't verify HTTPS certificates by default
241-
pass
242-
else:
243-
# Handle target environment that doesn't support HTTPS verification
244-
ssl._create_default_https_context = ssl._create_unverified_context
235+
ssl_context = None if validate_certs or not use_ssl else ssl._create_unverified_context()
245236

246237
url = "{proto}://{host}:{port}/cobbler_api".format(**module.params)
247-
if ssl_context:
248-
conn = xmlrpc_client.ServerProxy(url, context=ssl_context)
249-
else:
250-
conn = xmlrpc_client.Server(url)
238+
conn = xmlrpc_client.ServerProxy(url, context=ssl_context)
251239

252240
try:
253241
token = conn.login(username, password)

plugins/modules/jenkins_job_info.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,8 @@ def get_jenkins_connection(module):
160160
token = module.params.get("token")
161161

162162
validate_certs = module.params.get("validate_certs")
163-
if not validate_certs and hasattr(ssl, "SSLContext"):
163+
if not validate_certs:
164164
ssl._create_default_https_context = ssl._create_unverified_context
165-
if validate_certs and not hasattr(ssl, "SSLContext"):
166-
module.fail_json(
167-
msg="Module does not support changing verification mode with python < 2.7.9."
168-
" Either update Python or use validate_certs=false."
169-
)
170165

171166
if username and (password or token):
172167
return jenkins.Jenkins(url, username, password or token)

tests/integration/targets/mail/files/smtpserver.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@
4141
if len(sys.argv) > 3:
4242
keyfile = sys.argv[3]
4343

44-
try:
45-
ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
46-
except AttributeError:
47-
ssl_ctx = None
48-
if HAS_TLS:
49-
print('Python ssl library does not support SSLContext, hence starttls and TLS are not supported.')
50-
import smtpd
44+
ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
5145

5246
if HAS_TLS and ssl_ctx is not None:
5347
print('Using %s and %s' % (certfile, keyfile))

0 commit comments

Comments
 (0)