From 8e7d9be02bc1f4f12dc538684e3353a8f8883b97 Mon Sep 17 00:00:00 2001 From: Andrew Briening Date: Thu, 25 Jun 2015 16:52:23 -0400 Subject: [PATCH] Adds basic authentication & skip certificate validation to win_get_url module --- windows/win_get_url.ps1 | 17 +++++++++++++++++ windows/win_get_url.py | 17 ++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/windows/win_get_url.ps1 b/windows/win_get_url.ps1 index 46979c129f2..525854eae87 100644 --- a/windows/win_get_url.ps1 +++ b/windows/win_get_url.ps1 @@ -40,11 +40,23 @@ Else { 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 If ($force -or -not (Test-Path $dest)) { $client = New-Object System.Net.WebClient + if($username -and $password){ + $client.Credentials = New-Object System.Net.NetworkCredential($username, $password) + } + Try { $client.DownloadFile($url, $dest) $result.changed = $true @@ -56,6 +68,11 @@ If ($force -or -not (Test-Path $dest)) { Else { Try { $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.Method = "GET" [System.Net.HttpWebResponse]$webResponse = $webRequest.GetResponse() diff --git a/windows/win_get_url.py b/windows/win_get_url.py index a34f23890b5..5c3e994d418 100644 --- a/windows/win_get_url.py +++ b/windows/win_get_url.py @@ -28,6 +28,7 @@ version_added: "1.7" short_description: Fetches a file from a given URL description: - Fetches a file from a URL and saves to locally +author: "Paul Durivage (@angstwad)" options: url: description: @@ -49,7 +50,21 @@ options: required: false choices: [ "yes", "no" ] 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 = '''