uri: move follow_redirects to module_utils (#84442)

* url lookup and uri module shares follow_redirects parameter,
  moving it module_utils code.

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/84324/head
Abhijeet Kasurde 1 year ago committed by GitHub
parent 106909db8b
commit 01ca9b1d0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
---
minor_changes:
- Move ``follow_redirects`` parameter to module_utils so external modules can reuse it.

@ -1153,6 +1153,16 @@ def url_argument_spec():
)
def url_redirect_argument_spec():
"""
Creates an addition arugment spec to `url_argument_spec`
for `follow_redirects` argument
"""
return dict(
follow_redirects=dict(type='str', default='safe', choices=['all', 'no', 'none', 'safe', 'urllib2', 'yes']),
)
def fetch_url(module, url, data=None, headers=None, method=None,
use_proxy=None, force=False, last_mod_time=None, timeout=10,
use_gssapi=False, unix_socket=None, ca_path=None, cookies=None, unredirected_headers=None,

@ -106,18 +106,6 @@ options:
- The webservice bans or rate-limits clients that cause any HTTP 401 errors.
type: bool
default: no
follow_redirects:
description:
- Whether or not the URI module should follow redirects.
type: str
default: safe
choices:
all: Will follow all redirects.
none: Will not follow any redirects.
safe: Only redirects doing GET or HEAD requests will be followed.
urllib2: Defer to urllib2 behavior (As of writing this follows HTTP redirects).
'no': (DEPRECATED, removed in 2.22) alias of V(none).
'yes': (DEPRECATED, removed in 2.22) alias of V(all).
creates:
description:
- A filename, when it already exists, this step will not be run.
@ -235,6 +223,7 @@ options:
extends_documentation_fragment:
- action_common_attributes
- files
- url.url_redirect
attributes:
check_mode:
support: none
@ -455,7 +444,14 @@ from ansible.module_utils.six.moves.urllib.parse import urlencode, urlsplit
from ansible.module_utils.common.text.converters import to_native, to_text
from ansible.module_utils.compat.datetime import utcnow, utcfromtimestamp
from ansible.module_utils.six.moves.collections_abc import Mapping, Sequence
from ansible.module_utils.urls import fetch_url, get_response_filename, parse_content_type, prepare_multipart, url_argument_spec
from ansible.module_utils.urls import (
fetch_url,
get_response_filename,
parse_content_type,
prepare_multipart,
url_argument_spec,
url_redirect_argument_spec,
)
JSON_CANDIDATES = {'json', 'javascript'}
@ -609,6 +605,7 @@ def uri(module, url, dest, body, body_format, method, headers, socket_timeout, c
def main():
argument_spec = url_argument_spec()
argument_spec['url']['required'] = True
argument_spec.update(url_redirect_argument_spec())
argument_spec.update(
dest=dict(type='path'),
url_username=dict(type='str', aliases=['user']),

@ -72,3 +72,19 @@ options:
default: no
version_added: '2.11'
"""
URL_REDIRECT = r'''
options:
follow_redirects:
description:
- Whether or not the URI module should follow redirects.
type: str
default: safe
choices:
all: Will follow all redirects.
none: Will not follow any redirects.
safe: Only redirects doing GET or HEAD requests will be followed.
urllib2: Defer to urllib2 behavior (As of writing this follows HTTP redirects).
'no': (DEPRECATED, removed in 2.22) alias of V(none).
'yes': (DEPRECATED, removed in 2.22) alias of V(all).
'''

@ -87,7 +87,6 @@ options:
- section: url_lookup
key: force_basic_auth
follow_redirects:
description: String of urllib2, all/yes, safe, none to determine how redirects are followed
type: string
version_added: "2.10"
default: 'urllib2'
@ -98,13 +97,6 @@ options:
ini:
- section: url_lookup
key: follow_redirects
choices:
all: Will follow all redirects.
none: Will not follow any redirects.
safe: Only redirects doing GET or HEAD requests will be followed.
urllib2: Defer to urllib2 behavior (As of writing this follows HTTP redirects).
'no': (DEPRECATED, removed in 2.22) alias of V(none).
'yes': (DEPRECATED, removed in 2.22) alias of V(all).
use_gssapi:
description:
- Use GSSAPI handler of requests
@ -185,6 +177,8 @@ options:
ini:
- section: url_lookup
key: ciphers
extends_documentation_fragment:
- url.url_redirect
"""
EXAMPLES = """

Loading…
Cancel
Save