mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-27 23:21:22 -07:00
Fixing a bug in the new fetch_url username/password logic
This commit is contained in:
parent
b9d8b3b911
commit
117952cf6c
1 changed files with 16 additions and 14 deletions
|
@ -250,9 +250,8 @@ def fetch_url(module, url, data=None, headers=None, method=None,
|
||||||
handlers.append(ssl_handler)
|
handlers.append(ssl_handler)
|
||||||
|
|
||||||
if parsed[0] != 'ftp':
|
if parsed[0] != 'ftp':
|
||||||
url_username = module.params.get('url_username', '')
|
username = module.params.get('url_username', '')
|
||||||
if url_username:
|
if username:
|
||||||
username = url_username
|
|
||||||
password = module.params.get('url_password', '')
|
password = module.params.get('url_password', '')
|
||||||
netloc = parsed[1]
|
netloc = parsed[1]
|
||||||
elif '@' in parsed[1]:
|
elif '@' in parsed[1]:
|
||||||
|
@ -266,19 +265,22 @@ def fetch_url(module, url, data=None, headers=None, method=None,
|
||||||
parsed = list(parsed)
|
parsed = list(parsed)
|
||||||
parsed[1] = netloc
|
parsed[1] = netloc
|
||||||
|
|
||||||
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
|
# reconstruct url without credentials
|
||||||
# this creates a password manager
|
url = urlparse.urlunparse(parsed)
|
||||||
passman.add_password(None, netloc, username, password)
|
|
||||||
# because we have put None at the start it will always
|
|
||||||
# use this username/password combination for urls
|
|
||||||
# for which `theurl` is a super-url
|
|
||||||
|
|
||||||
authhandler = urllib2.HTTPBasicAuthHandler(passman)
|
if username:
|
||||||
# create the AuthHandler
|
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
|
||||||
handlers.append(authhandler)
|
|
||||||
|
|
||||||
#reconstruct url without credentials
|
# this creates a password manager
|
||||||
url = urlparse.urlunparse(parsed)
|
passman.add_password(None, netloc, username, password)
|
||||||
|
|
||||||
|
# because we have put None at the start it will always
|
||||||
|
# use this username/password combination for urls
|
||||||
|
# for which `theurl` is a super-url
|
||||||
|
authhandler = urllib2.HTTPBasicAuthHandler(passman)
|
||||||
|
|
||||||
|
# create the AuthHandler
|
||||||
|
handlers.append(authhandler)
|
||||||
|
|
||||||
if not use_proxy:
|
if not use_proxy:
|
||||||
proxyhandler = urllib2.ProxyHandler({})
|
proxyhandler = urllib2.ProxyHandler({})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue