Skip to content

Commit

Permalink
Changed the destination parameter to destination_directory
Browse files Browse the repository at this point in the history
  • Loading branch information
stack72 committed Nov 20, 2013
1 parent 4a5d367 commit c23c807
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ Usage
--

download_file { "Download dotnet 4.0" :
url => 'http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe',
destination => 'c:\temp'
url => 'http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe',
destination_directory => 'c:\temp'
}


This can now be used in other modules that need to install applications. All you would need to do is to have a require (as used with puppet-dotnet, by Liam Bennett) e.g.

download_file { "Download dotnet 4.0" :
url => 'http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe',
destination => 'c:\temp'
url => 'http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe',
destination_directory => 'c:\temp'
}

exec { 'install-dotnet-4':
Expand Down
6 changes: 3 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
define download_file ($url, $destination, $proxyAddress='') {
define download_file ($url, $destination_directory, $proxyAddress='') {
$filename = regsubst($url, '^http.*\/([^\/]+)$', '\1')
$powershell_filename = regsubst($url, '^(.*\/)(.+?)(?:\.[^\.]*$|$)$', '\2')

validate_re($url, '.+')
validate_re($destination, '.+')
validate_re($destination_directory, '.+')
validate_re($filename, '.+')

file { "download-${filename}.ps1" :
Expand All @@ -15,7 +15,7 @@
exec { "download-${filename}" :
command => "c:\\temp\\download-${powershell_filename}.ps1",
provider => powershell,
onlyif => "if(Test-Path -Path '${destination}\\${filename}') { exit 1 } else { exit 0 }",
onlyif => "if(Test-Path -Path '${destination_directory}\\${filename}') { exit 1 } else { exit 0 }",
logoutput => true,
require => File["download-${filename}.ps1"],
}
Expand Down
20 changes: 10 additions & 10 deletions spec/defines/download_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe 'download_file', :type => :define do
describe 'when downloading a file without a proxy' do
let(:title) {'Download DotNet 4.0'}
let(:params) { { :url => 'http://myserver.com/test.exe', :destination => 'c:\temp' } }
let(:params) { { :url => 'http://myserver.com/test.exe', :destination_directory => 'c:\temp' } }

it { should contain_exec('download-test.exe').with({
'command' => "c:\\temp\\download-test.ps1",
Expand All @@ -13,7 +13,7 @@

describe 'when downloading a file with a empty string proxy' do
let(:title) {'Download DotNet 4.0'}
let(:params) { { :url => 'http://myserver.com/test.exe', :destination => 'c:\temp', :proxyAddress => '' } }
let(:params) { { :url => 'http://myserver.com/test.exe', :destination_directory => 'c:\temp', :proxyAddress => '' } }

it { should contain_exec('download-test.exe').with({
'command' => "c:\\temp\\download-test.ps1",
Expand All @@ -23,7 +23,7 @@

describe 'when downloading a file without a proxy we want to check that the erb gets evaluated correctly' do
let(:title) {'Download DotNet 4.0'}
let(:params) { { :url => 'http://myserver.com/test.exe', :destination => 'c:\temp' } }
let(:params) { { :url => 'http://myserver.com/test.exe', :destination_directory => 'c:\temp' } }

it { should contain_file('download-test.exe.ps1').with_content(
"$webclient = New-Object System.Net.WebClient
Expand Down Expand Up @@ -53,7 +53,7 @@

describe 'when downloading a file using a proxy server' do
let(:title) {'Download DotNet 4.0'}
let(:params) { { :url => 'http://myserver.com/test.exe', :destination => 'c:\temp', :proxyAddress => 'test-proxy-01:8888' } }
let(:params) { { :url => 'http://myserver.com/test.exe', :destination_directory => 'c:\temp', :proxyAddress => 'test-proxy-01:8888' } }

it { should contain_exec('download-test.exe').with({
'command' => "c:\\temp\\download-test.ps1",
Expand All @@ -63,7 +63,7 @@

describe 'when downloading a file using a proxy server we want to check that the erb gets evaluated correctly' do
let(:title) {'Download DotNet 4.0'}
let(:params) { { :url => 'http://myserver.com/test.exe', :destination => 'c:\temp', :proxyAddress => 'test-proxy-01:8888' } }
let(:params) { { :url => 'http://myserver.com/test.exe', :destination_directory => 'c:\temp', :proxyAddress => 'test-proxy-01:8888' } }

it { should contain_file('download-test.exe.ps1').with_content(
"$webclient = New-Object System.Net.WebClient
Expand Down Expand Up @@ -95,19 +95,19 @@
let(:title) {'Download DotNet 4.0'}
let(:params) { {:url => 'http://myserver.com/test.exe' } }

it { expect { should contain_exec('download-test.exe')}.to raise_error(Puppet::Error, /Must pass destination to Download_file/)}
it { expect { should contain_exec('download-test.exe')}.to raise_error(Puppet::Error, /Must pass destination_directory to Download_file/)}
end

describe 'when not passing a URL to the file to download to the define' do
let(:title) {'Download DotNet 4.0'}
let(:params) { {:destination => 'c:\temp' } }
let(:params) { {:destination_directory => 'c:\temp' } }

it { expect { should contain_exec('download-test.exe')}.to raise_error(Puppet::Error, /Must pass url to Download_file/)}
end

describe 'when downloading a non-exe file' do
let(:title) {'Download MSI'}
let(:params) { { :url => 'http://myserver.com/test.msi', :destination => 'c:\temp' } }
let(:params) { { :url => 'http://myserver.com/test.msi', :destination_directory => 'c:\temp' } }

it { should contain_exec('download-test.msi').with({
'command' => "c:\\temp\\download-test.ps1",
Expand All @@ -117,7 +117,7 @@

describe 'when downloading the nodejs installer' do
let(:title) {'Download nodejs installer'}
let(:params) { { :url => 'http://artifactory.otsql.opentable.com:8081/artifactory/simple/puppet/windows/nodejs/0.10.15/nodejs-0.10.15-x64.msi', :destination => 'c:\temp' } }
let(:params) { { :url => 'http://artifactory.otsql.opentable.com:8081/artifactory/simple/puppet/windows/nodejs/0.10.15/nodejs-0.10.15-x64.msi', :destination_directory => 'c:\temp' } }

it { should contain_exec('download-nodejs-0.10.15-x64.msi').with({
'command' => "c:\\temp\\download-nodejs-0.10.15-x64.ps1",
Expand All @@ -127,7 +127,7 @@

describe 'when the destination is a folder' do
let(:title) {'Download nodejs installer'}
let(:params) { { :url => 'http://my.server/test.exe', :destination => 'c:\temp' } }
let(:params) { { :url => 'http://my.server/test.exe', :destination_directory => 'c:\temp' } }

it { should contain_exec('download-test.exe').with({
'command' => "c:\\temp\\download-test.ps1",
Expand Down
2 changes: 1 addition & 1 deletion templates/download.ps1.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if ($proxyAddress -ne '') {
}

try {
$webclient.DownloadFile('<%= @url %>', '<%= @destination %>\<%= @filename %>')
$webclient.DownloadFile('<%= @url %>', '<%= @destination_directory %>\<%= @filename %>')
}
catch [Exception] {
write-host $_.Exception.GetType().FullName
Expand Down

0 comments on commit c23c807

Please sign in to comment.