mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-26 21:33:12 +00:00
discard Python 2 ssl handling (#11078)
* discard Python 2 ssl handling * add changelog frag * Apply suggestion Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
@@ -110,22 +110,10 @@ def main():
|
||||
|
||||
start = now()
|
||||
|
||||
ssl_context = None
|
||||
if not validate_certs:
|
||||
try:
|
||||
ssl_context = ssl._create_unverified_context()
|
||||
except AttributeError:
|
||||
# Legacy Python that doesn't verify HTTPS certificates by default
|
||||
pass
|
||||
else:
|
||||
# Handle target environment that doesn't support HTTPS verification
|
||||
ssl._create_default_https_context = ssl._create_unverified_context
|
||||
ssl_context = None if validate_certs or not use_ssl else ssl._create_unverified_context()
|
||||
|
||||
url = "{proto}://{host}:{port}/cobbler_api".format(**module.params)
|
||||
if ssl_context:
|
||||
conn = xmlrpc_client.ServerProxy(url, context=ssl_context)
|
||||
else:
|
||||
conn = xmlrpc_client.Server(url)
|
||||
conn = xmlrpc_client.ServerProxy(url, context=ssl_context)
|
||||
|
||||
try:
|
||||
token = conn.login(username, password)
|
||||
|
||||
@@ -232,22 +232,10 @@ def main():
|
||||
|
||||
start = now()
|
||||
|
||||
ssl_context = None
|
||||
if not validate_certs:
|
||||
try:
|
||||
ssl_context = ssl._create_unverified_context()
|
||||
except AttributeError:
|
||||
# Legacy Python that doesn't verify HTTPS certificates by default
|
||||
pass
|
||||
else:
|
||||
# Handle target environment that doesn't support HTTPS verification
|
||||
ssl._create_default_https_context = ssl._create_unverified_context
|
||||
ssl_context = None if validate_certs or not use_ssl else ssl._create_unverified_context()
|
||||
|
||||
url = "{proto}://{host}:{port}/cobbler_api".format(**module.params)
|
||||
if ssl_context:
|
||||
conn = xmlrpc_client.ServerProxy(url, context=ssl_context)
|
||||
else:
|
||||
conn = xmlrpc_client.Server(url)
|
||||
conn = xmlrpc_client.ServerProxy(url, context=ssl_context)
|
||||
|
||||
try:
|
||||
token = conn.login(username, password)
|
||||
|
||||
@@ -160,13 +160,8 @@ def get_jenkins_connection(module):
|
||||
token = module.params.get("token")
|
||||
|
||||
validate_certs = module.params.get("validate_certs")
|
||||
if not validate_certs and hasattr(ssl, "SSLContext"):
|
||||
if not validate_certs:
|
||||
ssl._create_default_https_context = ssl._create_unverified_context
|
||||
if validate_certs and not hasattr(ssl, "SSLContext"):
|
||||
module.fail_json(
|
||||
msg="Module does not support changing verification mode with python < 2.7.9."
|
||||
" Either update Python or use validate_certs=false."
|
||||
)
|
||||
|
||||
if username and (password or token):
|
||||
return jenkins.Jenkins(url, username, password or token)
|
||||
|
||||
Reference in New Issue
Block a user