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-
pull/59274/head
Pedro Magalhães 5 years ago committed by ansibot
parent 4acbb83c84
commit c010a6d288

@ -297,7 +297,7 @@ class MavenDownloader:
self.base = base self.base = base
self.local = local self.local = local
self.headers = headers 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.latest_version_found = None
self.metadata_file_name = "maven-metadata-local.xml" if local else "maven-metadata.xml" 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 # 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_username'] = self.module.params.get('username', '')
self.module.params['url_password'] = self.module.params.get('password', '') 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) response, info = fetch_url(self.module, url_to_use, timeout=req_timeout, headers=self.headers)
if info['status'] == 200: if info['status'] == 200:

Loading…
Cancel
Save