From c010a6d288f5283c85b3810775a5ecdac8fcee1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Magalh=C3=A3es?= <4622652+pjrm@users.noreply.github.com> Date: Thu, 18 Jul 2019 23:55:36 +0100 Subject: [PATCH] Fix maven_artifact.py when your maven is behind a cloudflare (#53495) Cloudflare has a feature that checks Browser Integrity Check, when the user agent is not present, it can fail on BIC. Since we are defining the default value of variable "self.module.params['http_agent']" to None, this will cause that User-Agent header will not be added, because of the conditional if present on module_utils/urls.py [1] [1] https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/urls.py#L1135-L1136 This fix will ensure that the "self.module.params['http_agent']" will be defined URLs: https://support.cloudflare.com/hc/en-us/articles/200171806-Error-1010-The-owner-of-this-website-has-banned-your-access-based-on-your-browser-s-signature https://support.cloudflare.com/hc/en-us/articles/200170086-What-does-the-Browser-Integrity-Check-do- --- lib/ansible/modules/packaging/language/maven_artifact.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/packaging/language/maven_artifact.py b/lib/ansible/modules/packaging/language/maven_artifact.py index aa576f1b702..83255ab07e6 100644 --- a/lib/ansible/modules/packaging/language/maven_artifact.py +++ b/lib/ansible/modules/packaging/language/maven_artifact.py @@ -297,7 +297,7 @@ class MavenDownloader: self.base = base self.local = local self.headers = headers - self.user_agent = "Maven Artifact Downloader/1.0" + self.user_agent = "Ansible {0} maven_artifact".format(self.module.ansible_version) self.latest_version_found = None self.metadata_file_name = "maven-metadata-local.xml" if local else "maven-metadata.xml" @@ -380,7 +380,7 @@ class MavenDownloader: # Hack to add parameters in the way that fetch_url expects self.module.params['url_username'] = self.module.params.get('username', '') self.module.params['url_password'] = self.module.params.get('password', '') - self.module.params['http_agent'] = self.module.params.get('user_agent', None) + self.module.params['http_agent'] = self.user_agent response, info = fetch_url(self.module, url_to_use, timeout=req_timeout, headers=self.headers) if info['status'] == 200: