Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #19 from wavesoftware/master
Browse files Browse the repository at this point in the history
Add configuration parameter for allowing `curl` to follow redirects with `Location` HTTP header (default: true)
  • Loading branch information
joschi committed Feb 26, 2014
2 parents e2f5389 + 01baa95 commit 3777199
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/metadata.json
/.project
37 changes: 22 additions & 15 deletions manifests/download.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
# - *$timeout: Default value 120.
# - *$src_target: Default value '/usr/src'.
# - *$allow_insecure: Default value false.
# - *$allow_redirects: Default value true
# - *$proxy: HTTP proxy in the form of "hostname:port"
# - *$exec_path: Path being searched for all Exec resources, default: ['/usr/local/bin', '/usr/bin', '/bin']
#
# Example usage:

#
# archive::download {'apache-tomcat-6.0.26.tar.gz':
# ensure => present,
# url => 'http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.26/bin/apache-tomcat-6.0.26.tar.gz',
Expand All @@ -29,18 +30,19 @@
# }
define archive::download (
$url,
$ensure = present,
$checksum = true,
$digest_url = '',
$digest_string = '',
$digest_type = 'md5',
$timeout = 120,
$src_target = '/usr/src',
$allow_insecure = false,
$username = undef,
$password = undef,
$proxy = undef,
$exec_path = ['/usr/local/bin', '/usr/bin', '/bin']) {
$ensure = present,
$checksum = true,
$digest_url = '',
$digest_string = '',
$digest_type = 'md5',
$timeout = 120,
$src_target = '/usr/src',
$allow_insecure = false,
$allow_redirects = true,
$username = undef,
$password = undef,
$proxy = undef,
$exec_path = ['/usr/local/bin', '/usr/bin', '/bin']) {

if ($username == undef and $password == undef) {
$basic_auth = ''
Expand All @@ -59,6 +61,11 @@
default => '',
}

$redirects_arg = $allow_redirects ? {
true => '-L',
default => '',
}

case $checksum {
true : {
case $digest_type {
Expand All @@ -84,7 +91,7 @@
}

exec {"download digest of archive ${name}":
command => "curl ${basic_auth} ${insecure_arg} ${proxy_arg} -L -s -o ${src_target}/${name}.${digest_type} ${digest_src}",
command => "curl ${basic_auth} ${insecure_arg} ${redirects_arg} ${proxy_arg} -s -o ${src_target}/${name}.${digest_type} ${digest_src}",
path => $exec_path,
creates => "${src_target}/${name}.${digest_type}",
timeout => $timeout,
Expand Down Expand Up @@ -141,7 +148,7 @@
}

exec {"download archive ${name} and check sum":
command => "curl ${basic_auth} -L -s ${insecure_arg} ${proxy_arg} -o ${src_target}/${name} ${url}",
command => "curl ${basic_auth} -s ${insecure_arg} ${redirects_arg} ${proxy_arg} -o ${src_target}/${name} ${url}",
path => $exec_path,
creates => "${src_target}/${name}",
logoutput => true,
Expand Down
31 changes: 17 additions & 14 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# - *$extension: Default value ".tar.gz"
# - *$timeout: Default value 120
# - *$allow_insecure: Default value false
# - *$allow_redirects: Default value true
# - *$strip_components: Strip the top most n directories from each file name; default value 0
# - *$username: set basic auth username
# - *$password: set basic auth password
Expand Down Expand Up @@ -50,6 +51,7 @@
$extension = 'tar.gz',
$src_target = '/usr/src',
$allow_insecure = false,
$allow_redirects = true,
$strip_components = 0,
$username = undef,
$password = undef,
Expand All @@ -58,20 +60,21 @@
$exec_path = ['/usr/local/bin', '/usr/bin', '/bin']) {

archive::download {"${name}.${extension}":
ensure => $ensure,
url => $url,
checksum => $checksum,
digest_url => $digest_url,
digest_string => $digest_string,
digest_type => $digest_type,
timeout => $timeout,
src_target => $src_target,
allow_insecure => $allow_insecure,
username => $username,
password => $password,
proxy => $proxy,
require => $dependency_class,
exec_path => $exec_path,
ensure => $ensure,
url => $url,
checksum => $checksum,
digest_url => $digest_url,
digest_string => $digest_string,
digest_type => $digest_type,
timeout => $timeout,
src_target => $src_target,
allow_insecure => $allow_insecure,
allow_redirects => $allow_redirects,
username => $username,
password => $password,
proxy => $proxy,
require => $dependency_class,
exec_path => $exec_path,
}

archive::extract { $name:
Expand Down

0 comments on commit 3777199

Please sign in to comment.