-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
win_get_url: Add use_proxy, headers and timeout #26612
Conversation
* invalid drive letter breaks new Powershell path validation (this is a separate issue that needs to be solved) * test also exposes a minor bug in win_get_url where a nonexistent directory in the root of a drive that exists passes the "does the parent dir exist" check and causes DownloadFile to bomb (this should be fixed by dag's rewrite of win_get_url in #26612)
20a1d4a
to
141cc86
Compare
ae99c29
to
c95650a
Compare
4e6c9b2
to
a1d2f7c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proxy stuff works but there are a few others issues I came across. If you can fix those I'll do a speedy merge before the freeze.
Also looks like you need to rebase this.
} | ||
|
||
if ($timeout) { | ||
$webRequest.Timeout = $timeout * 1000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Timeout
is not a valid property of WebClient
https://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.110).aspx. Might be best to remove this new feature so we can get the rest in for 2.4 but I'll let you have a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is not a WebClient object, it is a HttpWebRequest object, and it does have a Timeout property. I also see a ConnectTimeout property, which we also could add. https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(v=vs.110).aspx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry ignore this line, line 88 is the one that is the invalid property.
} | ||
|
||
if ($timeout) { | ||
$webClient.Timeout = $timeout * 1000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto for timeout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So here we do have a WebClient object. It's strange that it worked fine for me, I'll remove the timeout here.
$params = Parse-Args $args -supports_check_mode $true | ||
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false | ||
|
||
$url = Get-AnsibleParam -obj $params -name "url" -type "str" -failifempty $true | ||
$dest = Get-AnsibleParam -obj $params -name "dest" -type "path" -failifempty $true | ||
$timeout = Get-AnsibleParam -obj $params -name "timeout" -type "int" -default 10 | ||
$headers = Get-AnsibleParam -obj $params -name "headers" -type "dict" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will need to set the default to @{}
so when call GetEnumerator()
in the methods above it won't fail if a user doesn't pass anything in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed that the default would adapt to the type in Ansible, but we don't do that anywhere.
I learned something new today :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dict
isn't a real type right now, even if it was I'm not sure if it should. There may be a reason where we need to know if it is null vs when it is an empty dict.
$fileLastMod = ([System.IO.FileInfo]$dest).LastWriteTimeUtc | ||
$webLastMod = $null | ||
Download-File -result $result -url $url -dest $dest -credentials $credentials ` | ||
-headers $headers -timeout $timeout -use_proxy $use_proxy -proxy_server $proxy_server ` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/proxy_server/proxy/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch !
@@ -19,120 +20,194 @@ | |||
# WANT_JSON | |||
# POWERSHELL_COMMON | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add $ErrorActionPreference = 'Stop'
to this, would have helped you to pick up some of the errors below and keeps it more inline with other PS modules we have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
d104539
to
b33d3ad
Compare
This PR includes: - Add use_proxy parameter - Add timeout parameter - Add headers parameter - Simplify logic - Create separate CheckModified-File - Now use -LiteralPath instead of -Path - Clean up documentation
b33d3ad
to
5f7f1e4
Compare
This PR includes: - Add use_proxy parameter - Add timeout parameter - Add headers parameter - Simplify logic - Create separate CheckModified-File - Now use -LiteralPath instead of -Path - Clean up documentation
5f7f1e4
to
76e7ebd
Compare
Typo fixed. |
Thanks the work, merging in for 2.4 |
* win_get_url: Add use_proxy, headers and timeout This PR includes: - Add use_proxy parameter - Add timeout parameter - Add headers parameter - Simplify logic - Create separate CheckModified-File - Now use -LiteralPath instead of -Path - Clean up documentation * win_get_url: Add use_proxy, headers and timeout This PR includes: - Add use_proxy parameter - Add timeout parameter - Add headers parameter - Simplify logic - Create separate CheckModified-File - Now use -LiteralPath instead of -Path - Clean up documentation
Hi, FAILED! => {"changed": false, "module_stderr": "An error occurred while creating the pipeline.\r\n + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordE \r\n xception\r\n + FullyQualifiedErrorId : RuntimeException\r\n \r\nException calling "Add" with "2" argument(s): "The parameter 'name' cannot be \r\nan empty string.\r\nParameter name: name"\r\nAt line:94 char:9\r\n+ $extWebClient.Headers.Add($header.Name, $header.Value)\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordE \r\n xception\r\n + FullyQualifiedErrorId : ArgumentException\r\n \r\n\r\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1} Can you please advice? Thanks |
@ctal80 Please open a new issue, rather than hijack a closed PR. BTW according to the docs, the input expects a dictionary, but you provide a string. PS If you open an issue, please provide all details because your current comment is not sufficient to understand what you're doing and how the error relates to what you're doing. |
Hi, I'm sorry for hijacked the closed PR. I changed the parameter from string to dictionary e.g {X-JFrog-Art-Api: AKCp5Z2Y3oz3MRbmpthVW4omH3xymFRzGkrFfacGSbAU7abGDF5nGe6WXkJsM6UFeZqYLmeCx} and now it's working properly and i'm able to download the file. Thanks Tal |
@ctal80 There's still use in opening an issue so we can fix the error-message and better test for the input. |
SUMMARY
This PR includes:
use_proxy
parameterheaders
parameterusername
tourl_username
password
tourl_password
CheckModified-File
function-LiteralPath
instead of-Path
This relates to #20160
This fixes #19573
ISSUE TYPE
COMPONENT NAME
win_get_url
ANSIBLE VERSION
v2.4