Allow basic auth in netloc_no_port filtered URLs
Update the netloc_no_port filter to parse a URL using the 'hostname' attribute instead of splitting the netloc before the first colon, where a username might be provided. Change-Id: I9a0d01eac1e44de121fc7c6753cfa1bc2ed4318d
This commit is contained in:
parent
cf99208142
commit
83c5785ba8
|
@ -183,8 +183,14 @@ def get_netloc_no_port(url):
|
|||
:type url: ``str``
|
||||
:returns: ``str``
|
||||
"""
|
||||
return get_netloc(url=url).split(':')[0]
|
||||
|
||||
try:
|
||||
hostname = urlparse(url).hostname
|
||||
except Exception as exp:
|
||||
raise errors.AnsibleFilterError(
|
||||
'Failed to return the hostname of: "%s"' % str(exp)
|
||||
)
|
||||
else:
|
||||
return hostname
|
||||
|
||||
def get_netorigin(url):
|
||||
"""Return the netloc from a URL.
|
||||
|
|
|
@ -30,12 +30,14 @@
|
|||
set_fact:
|
||||
url_netloc: "{{ 'http://review.openstack.org:29418/something' | netloc }}"
|
||||
url_netloc_no_port: "{{ 'http://review.openstack.org:29418/something' | netloc_no_port }}"
|
||||
url_netloc_no_port_with_auth: "{{ 'http://user:secrete@review.openstack.org:29418/something' | netloc_no_port }}"
|
||||
url_netorigin: "{{ 'http://review.openstack.org:29418/something' | netorigin }}"
|
||||
- name: Validate net filters
|
||||
assert:
|
||||
that:
|
||||
- "url_netloc == 'review.openstack.org:29418'"
|
||||
- "url_netloc_no_port == 'review.openstack.org'"
|
||||
- "url_netloc_no_port_with_auth == 'review.openstack.org'"
|
||||
- "url_netorigin == 'http://review.openstack.org:29418'"
|
||||
|
||||
- name: Validate string_2_int filter
|
||||
|
|
Loading…
Reference in New Issue