diff options
author | Abhijeet Kasurde <akasurde@redhat.com> | 2024-12-10 17:08:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-10 17:08:24 +0100 |
commit | 01ca9b1d0ec882f5eea7fc42ef7f7dab9ea76d19 (patch) | |
tree | 01050708b9a11ce10989aab855e479f01536369e /lib | |
parent | adding option for form-multipart data to switch multipart encoding (#80566) (diff) | |
download | ansible-01ca9b1d0ec882f5eea7fc42ef7f7dab9ea76d19.tar.xz ansible-01ca9b1d0ec882f5eea7fc42ef7f7dab9ea76d19.zip |
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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ansible/module_utils/urls.py | 10 | ||||
-rw-r--r-- | lib/ansible/modules/uri.py | 23 | ||||
-rw-r--r-- | lib/ansible/plugins/doc_fragments/url.py | 16 | ||||
-rw-r--r-- | lib/ansible/plugins/lookup/url.py | 10 |
4 files changed, 38 insertions, 21 deletions
diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py index 282210b27a..09ea835d72 100644 --- a/lib/ansible/module_utils/urls.py +++ b/lib/ansible/module_utils/urls.py @@ -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, diff --git a/lib/ansible/modules/uri.py b/lib/ansible/modules/uri.py index b193d0ac06..3229c746c7 100644 --- a/lib/ansible/modules/uri.py +++ b/lib/ansible/modules/uri.py @@ -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']), diff --git a/lib/ansible/plugins/doc_fragments/url.py b/lib/ansible/plugins/doc_fragments/url.py index bddc33db98..942558f166 100644 --- a/lib/ansible/plugins/doc_fragments/url.py +++ b/lib/ansible/plugins/doc_fragments/url.py @@ -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). +''' diff --git a/lib/ansible/plugins/lookup/url.py b/lib/ansible/plugins/lookup/url.py index 4775ecfb0c..7c15cba3e0 100644 --- a/lib/ansible/plugins/lookup/url.py +++ b/lib/ansible/plugins/lookup/url.py @@ -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 = """ |