Skip to content

Commit

Permalink
Add option to download with user.
Browse files Browse the repository at this point in the history
  • Loading branch information
juanibiapina committed May 2, 2013
1 parent a8c76a7 commit 895fdb8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
21 changes: 11 additions & 10 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
################################################################################
class wget($version='installed') {

if $::operatingsystem != 'Darwin' {
package { "wget": ensure => $version }
}
Expand All @@ -18,7 +18,7 @@
# using $http_proxy if necessary.
#
################################################################################
define wget::fetch($source,$destination,$timeout="0",$verbose=false,$redownload=false,$nocheckcertificate=false) {
define wget::fetch($source,$destination,$timeout="0",$verbose=false,$redownload=false,$nocheckcertificate=false,$user='root') {
include wget
# using "unless" with test instead of "creates" to re-attempt download
# on empty files.
Expand All @@ -40,17 +40,18 @@
true => "test",
false => "test -s $destination"
}

$nocheckcert_option = $nocheckcertificate ? {
true => ' --no-check-certificate',
false => ''
}

exec { "wget-$name":
command => "wget $verbose_option$nocheckcert_option --output-document=$destination $source",
timeout => $timeout,
unless => $unless_test,
environment => $environment,
user => $user,
path => "/usr/bin:/usr/sbin:/bin:/usr/local/bin:/opt/local/bin",
require => Class[wget],
}
Expand Down Expand Up @@ -82,25 +83,25 @@
true => "test",
false => "test -s $destination"
}

$nocheckcert_option = $nocheckcertificate ? {
true => ' --no-check-certificate',
false => ''
}

case $::operatingsystem {
'Darwin': {
# This is to work around an issue with macports wget and out of date CA cert bundle. This requires
# This is to work around an issue with macports wget and out of date CA cert bundle. This requires
# installing the curl-ca-bundle package like so:
#
# sudo port install curl-ca-bundle
# sudo port install curl-ca-bundle
$wgetrc_content = "password=$password\nCA_CERTIFICATE=/opt/local/share/curl/curl-ca-bundle.crt\n"
}
}
default: {
$wgetrc_content = "password=$password"
}
}

file { "/tmp/wgetrc-$name":
owner => root,
mode => 600,
Expand Down
6 changes: 5 additions & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
end

describe 'wget::fetch' do
it { should contain_exec('wget-test').with_command('wget --no-verbose --output-document=/tmp/dest http://localhost/source') }
it { should contain_exec('wget-test').with({
'command' => 'wget --no-verbose --output-document=/tmp/dest http://localhost/source',
'user' => 'testuser'
})
}
end

describe 'wget::authfetch' do
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/manifests/site.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
wget::fetch { 'test':
source => 'http://localhost/source',
destination => '/tmp/dest',
user => 'testuser',
}

wget::authfetch { 'authtest':
Expand Down

0 comments on commit 895fdb8

Please sign in to comment.