Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make our type camptocamp/archive compatible #176

Merged
merged 3 commits into from
Jul 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion lib/puppet/type/archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ def change_to_s(currentvalue, newvalue)
end
end
end
newparam(:target) do
desc 'target folder path to extract archive. (this parameter is for camptocamp/archive compatibility)'
validate do |value|
unless Puppet::Util.absolute_path? value
raise ArgumentError, "archive extract_path must be absolute: #{value}"
end
end
munge do |val|
resource[:extract_path] = val
end
end

newparam(:extract_command) do
desc "custom extraction command ('tar xvf example.tar.gz'), also support sprintf format ('tar xvf %s') which will be processed with the filename: sprintf('tar xvf %s', filename)"
Expand Down Expand Up @@ -109,24 +120,74 @@ def should_to_s(value)
end
end

newparam(:url) do
desc 'archive file source, supports http|https|ftp|file uri.
(for camptocamp/archive compatibility)'
validate do |value|
unless value =~ URI.regexp(%w(http https file ftp))
raise ArgumentError, "invalid source url: #{value}"
end
end
munge do |val|
resource[:source] = val
end
end

newparam(:cookie) do
desc 'archive file download cookie.'
end

newparam(:checksum) do
desc 'archive file checksum (match checksum_type).'
newvalues(%r{\b[0-9a-f]{5,128}\b}, :true, :false, :undef, nil, '')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is awful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it works with the latest _release_ or rtyler/jenkins

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(a.k.a.: we're running it in prod now ;)

munge do |val|
if val.nil? || val.empty? || val == :undef
:false
elsif val == :true || val == :false
resource[:checksum_verify] = val
else
val
end
end
end
newparam(:digest_string) do
desc 'archive file checksum (match checksum_type)
(this parameter is for camptocamp/archive compatibility).'
newvalues(%r{\b[0-9a-f]{5,128}\b})
munge do |val|
if !val.nil? && !val.empty?
resource[:checksum] = val
else
val
end
end
end

newparam(:checksum_url) do
desc 'archive file checksum source (instead of specify checksum)'
desc 'archive file checksum source (instead of specifying checksum)'
end
newparam(:digest_url) do
desc 'archive file checksum source (instead of specifying checksum)
(this parameter is for camptocamp/archive compatibility)'
munge do |val|
resource[:checksum_url] = val
end
end

newparam(:checksum_type) do
desc 'archive file checksum type (none|md5|sha1|sha2|sh256|sha384|sha512).'
newvalues(:none, :md5, :sha1, :sha2, :sha256, :sha384, :sha512)
defaultto(:none)
end
newparam(:digest_type) do
desc 'archive file checksum type (none|md5|sha1|sha2|sh256|sha384|sha512)
(this parameter is camptocamp/archive compatibility).'
newvalues(:none, :md5, :sha1, :sha2, :sha256, :sha384, :sha512)
defaultto(:none)
munge do |val|
resource[:checksum_type] = val
end
end

newparam(:checksum_verify) do
desc 'whether checksum wil be verified (true|false).'
Expand Down Expand Up @@ -175,6 +236,12 @@ def should_to_s(value)
validate do
filepath = Pathname.new(self[:path])
self[:filename] = filepath.basename.to_s
if !self[:source].nil? && !self[:url].nil? && self[:source] != self[:url]
raise ArgumentError, "invalid parameter: url (#{self[:url]}) and source (#{self[:source]}) are mutually exclusive."
end
if !self[:checksum_url].nil? && !self[:digest_url].nil? && self[:checksum_url] != self[:digest_url]
raise ArgumentError, "invalid parameter: checksum_url (#{self[:checksum_url]}) and digest_url (#{self[:digest_url]}) are mutually exclusive."
end
if self[:proxy_server]
self[:proxy_type] ||= URI(self[:proxy_server]).scheme.to_sym
else
Expand Down
64 changes: 64 additions & 0 deletions manifests/download.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# == Definition: archive::download
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igalic Maybe document this type as for compatibility with camptocamp? You would otherwise always use the native archive type directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it wasn't documented in camptocamp/archive either _
i don't want to document it, because it's just a shim. private api that moves as camptocamp/archive moves.

Copy link
Member

@alexjfisher alexjfisher Jul 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I wasn't clear (story of my life!) I don't mean document all the parameters etc. I mean just add a line to say that it is a shim/private etc. Something to discourage new users from thinking this is the way they should be using the module.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to how the new parameters in the type are marked (this parameter is for camptocamp/archive compatibility)

#
# Archive downloader with integrity verification.
#
# Parameters:
#
# - *$url:
# - *$digest_url:
# - *$digest_string: Default value undef
# - *$digest_type: Default value "md5".
# - *$timeout: Default value 120. (ignored)
# - *$src_target: Default value "/usr/src".
# - *$allow_insecure: Default value false.
# - *$follow_redirects: Default value false.
# - *$verbose: Default value true.
# - *$proxy_server: Default value undef.
# - *$user: The user used to download the archive
#
# 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",
# }
#
# archive::download {"apache-tomcat-6.0.26.tar.gz":
# ensure => present,
# digest_string => "f9eafa9bfd620324d1270ae8f09a8c89",
# url => "http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.26/bin/apache-tomcat-6.0.26.tar.gz",
# }
#
define archive::download (
$url,
$ensure = present,
$checksum = true,
$digest_url = undef,
$digest_string = undef,
$digest_type = 'md5', # bad default!
$timeout = 120, # ignored
$src_target = '/usr/src',
$allow_insecure = false, # ignored
$follow_redirects = false, # ignored (default)
$verbose = true, # ignored
$path = $::path, # ignored
$proxy_server = undef,
$user = undef,
) {

$target = is_absolute_path($title) ? {
false => "${src_target}/${title}",
default => $title,
}

archive { $target:
ensure => $ensure,
source => $url,
checksum_verify => $checksum,
checksum => $digest_string,
checksum_type => $digest_type,
checksum_url => $digest_url,
proxy_server => $proxy_server,
user => $user,
}
}