Merge pull request #1607 from abriening/win_get_url_updates
Adds basic authentication & skip certificate validation to win_get_ur…
This commit is contained in:
commit
d8f45bab41
2 changed files with 36 additions and 4 deletions
|
@ -40,22 +40,39 @@ Else {
|
||||||
Fail-Json $result "missing required argument: dest"
|
Fail-Json $result "missing required argument: dest"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$skip_certificate_validation = Get-Attr $params "skip_certificate_validation" $false | ConvertTo-Bool
|
||||||
|
$username = Get-Attr $params "username"
|
||||||
|
$password = Get-Attr $params "password"
|
||||||
|
|
||||||
|
if($skip_certificate_validation){
|
||||||
|
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
|
||||||
|
}
|
||||||
|
|
||||||
$force = Get-Attr -obj $params -name "force" "yes" | ConvertTo-Bool
|
$force = Get-Attr -obj $params -name "force" "yes" | ConvertTo-Bool
|
||||||
|
|
||||||
If ($force -or -not (Test-Path $dest)) {
|
If ($force -or -not (Test-Path $dest)) {
|
||||||
$client = New-Object System.Net.WebClient
|
$client = New-Object System.Net.WebClient
|
||||||
|
|
||||||
|
if($username -and $password){
|
||||||
|
$client.Credentials = New-Object System.Net.NetworkCredential($username, $password)
|
||||||
|
}
|
||||||
|
|
||||||
Try {
|
Try {
|
||||||
$client.DownloadFile($url, $dest)
|
$client.DownloadFile($url, $dest)
|
||||||
$result.changed = $true
|
$result.changed = $true
|
||||||
}
|
}
|
||||||
Catch {
|
Catch {
|
||||||
Fail-Json $result "Error downloading $url to $dest"
|
Fail-Json $result "Error downloading $url to $dest $($_.Exception.Message)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Else {
|
Else {
|
||||||
Try {
|
Try {
|
||||||
$webRequest = [System.Net.HttpWebRequest]::Create($url)
|
$webRequest = [System.Net.HttpWebRequest]::Create($url)
|
||||||
|
|
||||||
|
if($username -and $password){
|
||||||
|
$webRequest.Credentials = New-Object System.Net.NetworkCredential($username, $password)
|
||||||
|
}
|
||||||
|
|
||||||
$webRequest.IfModifiedSince = ([System.IO.FileInfo]$dest).LastWriteTime
|
$webRequest.IfModifiedSince = ([System.IO.FileInfo]$dest).LastWriteTime
|
||||||
$webRequest.Method = "GET"
|
$webRequest.Method = "GET"
|
||||||
[System.Net.HttpWebResponse]$webResponse = $webRequest.GetResponse()
|
[System.Net.HttpWebResponse]$webResponse = $webRequest.GetResponse()
|
||||||
|
@ -68,11 +85,11 @@ Else {
|
||||||
}
|
}
|
||||||
Catch [System.Net.WebException] {
|
Catch [System.Net.WebException] {
|
||||||
If ($_.Exception.Response.StatusCode -ne [System.Net.HttpStatusCode]::NotModified) {
|
If ($_.Exception.Response.StatusCode -ne [System.Net.HttpStatusCode]::NotModified) {
|
||||||
Fail-Json $result "Error downloading $url to $dest"
|
Fail-Json $result "Error downloading $url to $dest $($_.Exception.Message)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Catch {
|
Catch {
|
||||||
Fail-Json $result "Error downloading $url to $dest"
|
Fail-Json $result "Error downloading $url to $dest $($_.Exception.Message)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ version_added: "1.7"
|
||||||
short_description: Fetches a file from a given URL
|
short_description: Fetches a file from a given URL
|
||||||
description:
|
description:
|
||||||
- Fetches a file from a URL and saves to locally
|
- Fetches a file from a URL and saves to locally
|
||||||
|
author: "Paul Durivage (@angstwad)"
|
||||||
options:
|
options:
|
||||||
url:
|
url:
|
||||||
description:
|
description:
|
||||||
|
@ -49,7 +50,21 @@ options:
|
||||||
required: false
|
required: false
|
||||||
choices: [ "yes", "no" ]
|
choices: [ "yes", "no" ]
|
||||||
default: yes
|
default: yes
|
||||||
author: "Paul Durivage (@angstwad)"
|
username:
|
||||||
|
description:
|
||||||
|
- Basic authentication username
|
||||||
|
required: false
|
||||||
|
default: null
|
||||||
|
password:
|
||||||
|
description:
|
||||||
|
- Basic authentication password
|
||||||
|
required: false
|
||||||
|
default: null
|
||||||
|
skip_certificate_validation:
|
||||||
|
description:
|
||||||
|
- Skip SSL certificate validation if true
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
|
Loading…
Reference in a new issue