WebRequest - remove generically named aliases from util (#66325)

* WebRequest - remove generically named aliases from util

* Fix location of deprecated aliases key
This commit is contained in:
Jordan Borean 2020-01-10 13:01:26 +10:00 committed by GitHub
parent 7a7f70612a
commit c92b538cc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 111 additions and 11 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- Ansible.ModuleUtils.WebRequest - Move username and password aliases out of util to avoid option name collision

View file

@ -467,6 +467,57 @@ Function Invoke-WithWebRequest {
}
}
Function Merge-WebRequestSpec {
<#
.SYNOPSIS
Merges a modules spec definition with extra options supplied by this module_util. Options from the module take
priority over the module util spec.
.PARAMETER ModuleSpec
The root $spec of a module option definition to merge with.
.EXAMPLE
$spec = @{
options = @{
name = @{ type = "str" }
}
supports_check_mode = $true
}
$spec = Merge-WebRequestSpec -ModuleSpec $spec
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[System.Collections.IDictionary]
$ModuleSpec,
[System.Collections.IDictionary]
$SpecToMerge = @{ options = $ansible_web_request_options }
)
foreach ($option_kvp in $SpecToMerge.GetEnumerator()) {
$k = $option_kvp.Key
$v = $option_kvp.Value
if ($ModuleSpec.Contains($k)) {
if ($v -is [System.Collections.IDictionary]) {
$ModuleSpec[$k] = Merge-WebRequestSpec -ModuleSpec $ModuleSpec[$k] -SpecToMerge $v
} elseif ($v -is [Array] -or $v -is [System.Collections.IList]) {
$sourceList = [System.Collections.Generic.List[Object]]$ModuleSpec[$k]
foreach ($entry in $v) {
$sourceList.Add($entry)
}
$ModuleSpec[$k] = $sourceList
}
} else {
$ModuleSpec[$k] = $v
}
}
$ModuleSpec
}
$ansible_web_request_options = @{
url = @{ type="str"; required=$true }
method = @{ type="str" }
@ -481,8 +532,8 @@ $ansible_web_request_options = @{
client_cert = @{ type="str" }
client_cert_password = @{ type="str"; no_log=$true }
force_basic_auth = @{ type="bool"; default=$false }
url_username = @{ type="str"; aliases=@("user", "username") } # user was used in win_uri
url_password = @{ type="str"; aliases=@("password"); no_log=$true }
url_username = @{ type="str" }
url_password = @{ type="str"; no_log=$true }
use_default_credential = @{ type="bool"; default=$false }
# Proxy options
@ -494,7 +545,7 @@ $ansible_web_request_options = @{
}
$export_members = @{
Function = "Get-AnsibleWebRequest", "Invoke-WithWebRequest"
Function = "Get-AnsibleWebRequest", "Invoke-WithWebRequest", "Merge-WebRequestSpec"
Variable = "ansible_web_request_options"
}
Export-ModuleMember @export_members

View file

@ -18,13 +18,28 @@ $spec = @{
checksum = @{ type='str' }
checksum_algorithm = @{ type='str'; default='sha1'; choices = @("md5", "sha1", "sha256", "sha384", "sha512") }
checksum_url = @{ type='str' }
# Defined for the alias backwards compatibility, remove once aliases are removed
url_username = @{
aliases = @("user", "username")
deprecated_aliases = @(
@{ name = "user"; version = "2.14" },
@{ name = "username"; version = "2.14" }
)
}
url_password = @{
aliases = @("password")
deprecated_aliases = @(
@{ name = "password"; version = "2.14" }
)
}
}
mutually_exclusive = @(
,@('checksum', 'checksum_url')
)
supports_check_mode = $true
}
$spec.options += $ansible_web_request_options
$spec = Merge-WebRequestSpec -ModuleSpec $spec
$module = [Ansible.Basic.AnsibleModule]::Create($args, $spec)

View file

@ -73,6 +73,20 @@ options:
- This option cannot be set with I(checksum).
type: str
version_added: "2.8"
url_username:
description:
- The username to use for authentication.
- The aliases I(user) and I(username) are deprecated and will be removed in
Ansible 2.14.
aliases:
- user
- username
url_password:
description:
- The password for I(url_username).
- The alias I(password) is deprecated and will be removed in Ansible 2.14.
aliases:
- password
proxy_url:
version_added: "2.0"
proxy_username:

View file

@ -16,14 +16,29 @@ $spec = @{
body = @{ type = "raw" }
dest = @{ type = "path" }
creates = @{ type = "path" }
method = @{ default = "GET" }
removes = @{ type = "path" }
return_content = @{ type = "bool"; default = $false }
status_code = @{ type = "list"; elements = "int"; default = @(200) }
# Defined for the alias backwards compatibility, remove once aliases are removed
url_username = @{
aliases = @("user", "username")
deprecated_aliases = @(
@{ name = "user"; version = "2.14" },
@{ name = "username"; version = "2.14" }
)
}
url_password = @{
aliases = @("password")
deprecated_aliases = @(
@{ name = "password"; version = "2.14" }
)
}
}
supports_check_mode = $true
}
$spec.options += $ansible_web_request_options
$spec.options.method.default = "GET"
$spec = Merge-WebRequestSpec -ModuleSpec $spec
$module = [Ansible.Basic.AnsibleModule]::Create($args, $spec)

View file

@ -73,12 +73,20 @@ options:
- The username to use for authentication.
- Was originally called I(user) but was changed to I(url_username) in
Ansible 2.9.
- The aliases I(user) and I(username) are deprecated and will be removed in
Ansible 2.14.
aliases:
- user
- username
version_added: "2.4"
url_password:
description:
- The password for I(url_username).
- Was originally called I(password) but was changed to I(url_password) in
Ansible 2.9.
- The alias I(password) is deprecated and will be removed in Ansible 2.14.
aliases:
- password
version_added: "2.4"
follow_redirects:
version_added: "2.4"

View file

@ -101,15 +101,10 @@ options:
description:
- The username to use for authentication.
type: str
aliases:
- user
- username
url_password:
description:
- The password for I(url_username).
type: str
aliases:
- password
use_default_credential:
description:
- Uses the current user's credentials when authenticating with a server