From dae88633dffab730960e0ec36e0e05e01da2b102 Mon Sep 17 00:00:00 2001 From: Felix Fontein <felix@fontein.de> Date: Sun, 16 May 2021 13:51:52 +0200 Subject: [PATCH 1/2] Only emit tls_hostname deprecation warning if TLS is actually used. --- changelogs/fragments/143-tls_hostname-deprecation.yml | 2 ++ plugins/module_utils/common.py | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/143-tls_hostname-deprecation.yml diff --git a/changelogs/fragments/143-tls_hostname-deprecation.yml b/changelogs/fragments/143-tls_hostname-deprecation.yml new file mode 100644 index 000000000..c5270b1ba --- /dev/null +++ b/changelogs/fragments/143-tls_hostname-deprecation.yml @@ -0,0 +1,2 @@ +bugfixes: +- "docker_* modules and plugins, except ``docker_swarm`` connection plugin and ``docker_compose`` and ``docker_stack*` modules - only emit ``tls_hostname`` deprecation message if TLS is actually used (https://github.com/ansible-collections/community.docker/pull/143)." diff --git a/plugins/module_utils/common.py b/plugins/module_utils/common.py index fd7cdeaf5..468211fbc 100644 --- a/plugins/module_utils/common.py +++ b/plugins/module_utils/common.py @@ -172,11 +172,11 @@ def log(self, msg, pretty_print=False): # log_file.write(msg + u'\n') -def update_tls_hostname(result, old_behavior=False, deprecate_function=None): +def update_tls_hostname(result, old_behavior=False, deprecate_function=None, uses_tls=True): if result['tls_hostname'] is None: if old_behavior: result['tls_hostname'] = DEFAULT_TLS_HOSTNAME - if deprecate_function is not None: + if uses_tls and deprecate_function is not None: deprecate_function( 'The default value "localhost" for tls_hostname is deprecated and will be removed in community.docker 2.0.0.' ' From then on, docker_host will be used to compute tls_hostname. If you want to keep using "localhost",' @@ -200,8 +200,11 @@ def _get_tls_config(fail_function, **kwargs): fail_function("TLS config error: %s" % exc) +def is_using_tls(auth): + return auth['tls_verify'] or auth['tls'] + def get_connect_params(auth, fail_function): - if auth['tls'] or auth['tls_verify']: + if is_using_tls(auth): auth['docker_host'] = auth['docker_host'].replace('tcp://', 'https://') result = dict( @@ -391,7 +394,7 @@ def auth_params(self): def depr(*args, **kwargs): self.deprecate(*args, **kwargs) - update_tls_hostname(result, old_behavior=True, deprecate_function=depr) + update_tls_hostname(result, old_behavior=True, deprecate_function=depr, uses_tls=is_using_tls(result)) return result From fe8f6f8f16ee980242d33116eff4950c441877e7 Mon Sep 17 00:00:00 2001 From: Felix Fontein <felix@fontein.de> Date: Sun, 16 May 2021 20:11:03 +0200 Subject: [PATCH 2/2] Linting. --- plugins/module_utils/common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/module_utils/common.py b/plugins/module_utils/common.py index 468211fbc..fbe2ba28c 100644 --- a/plugins/module_utils/common.py +++ b/plugins/module_utils/common.py @@ -203,6 +203,7 @@ def _get_tls_config(fail_function, **kwargs): def is_using_tls(auth): return auth['tls_verify'] or auth['tls'] + def get_connect_params(auth, fail_function): if is_using_tls(auth): auth['docker_host'] = auth['docker_host'].replace('tcp://', 'https://')