diff --git a/examples/bad_source.pp b/examples/bad_source.pp index 6bfd4ec..57407e8 100644 --- a/examples/bad_source.pp +++ b/examples/bad_source.pp @@ -1,5 +1,4 @@ archive { '/tmp/jta-1.1.jar': ensure => present, source => $bad_variable, } - diff --git a/manifests/artifactory.pp b/manifests/artifactory.pp index 6c60172..e951e4a 100644 --- a/manifests/artifactory.pp +++ b/manifests/artifactory.pp @@ -1,105 +1,104 @@ # Define: archive::artifactory # ============================ # # archive wrapper for downloading files from artifactory # # Parameters # ---------- # # * path: fully qualified filepath for the download the file or use archive_path and only supply filename. (namevar). # * ensure: ensure the file is present/absent. # * url: artifactory download URL. # * owner: file owner (see archive params for defaults). # * group: file group (see archive params for defaults). # * mode: file mode (see archive params for defaults). # * archive_path: the parent directory of local filepath. # * extract: whether to extract the files (true/false). # * creates: the file created when the archive is extracted (true/false). # * cleanup: remove archive file after file extraction (true/false). # # Examples # -------- # # archive::artifactory { '/tmp/logo.png': # url => 'https://repo.jfrog.org/artifactory/distributions/images/Artifactory_120x75.png', # owner => 'root', # group => 'root', # mode => '0644', # } # # $dirname = 'gradle-1.0-milestone-4-20110723151213+0300' # $filename = "${dirname}-bin.zip" # # archive::artifactory { $filename: # archive_path => '/tmp', # url => "http://repo.jfrog.org/artifactory/distributions/org/gradle/${filename}", # extract => true, # extract_path => '/opt', # creates => "/opt/${dirname}", # cleanup => true, # } # define archive::artifactory ( Stdlib::HTTPUrl $url, String $path = $name, Enum['present', 'absent'] $ensure = present, Optional[String] $owner = undef, Optional[String] $group = undef, Optional[String] $mode = undef, Optional[Boolean] $extract = undef, Optional[String] $extract_path = undef, Optional[String] $creates = undef, Optional[Boolean] $cleanup = undef, Optional[Stdlib::Absolutepath] $archive_path = undef, ) { - include archive::params if $archive_path { $file_path = "${archive_path}/${name}" } else { $file_path = $path } assert_type(Stdlib::Absolutepath, $file_path) |$expected, $actual| { fail("archive::artifactory[${name}]: \$name or \$archive_path must be '${expected}', not '${actual}'") } $maven2_data = archive::parse_artifactory_url($url) - if $maven2_data and $maven2_data['folder_iteg_rev'] == 'SNAPSHOT'{ + if $maven2_data and $maven2_data['folder_iteg_rev'] == 'SNAPSHOT' { # URL represents a SNAPSHOT version. eg 'http://artifactory.example.com/artifactory/repo/com/example/artifact/0.0.1-SNAPSHOT/artifact-0.0.1-SNAPSHOT.zip' # Only Artifactory Pro lets you download this directly but the corresponding fileinfo endpoint (where the sha1 checksum is published) doesn't exist. # This means we can't use the artifactory_sha1 function $latest_url_data = archive::artifactory_latest_url($url, $maven2_data) $file_url = $latest_url_data['url'] $sha1 = $latest_url_data['sha1'] } else { $file_url = $url $sha1 = archive::artifactory_checksum($url,'sha1') } archive { $file_path: ensure => $ensure, path => $file_path, extract => $extract, extract_path => $extract_path, source => $file_url, checksum => $sha1, checksum_type => 'sha1', creates => $creates, cleanup => $cleanup, } $file_owner = pick($owner, $archive::params::owner) $file_group = pick($group, $archive::params::group) $file_mode = pick($mode, $archive::params::mode) file { $file_path: owner => $file_owner, group => $file_group, mode => $file_mode, require => Archive[$file_path], } } diff --git a/manifests/go.pp b/manifests/go.pp index f9a9285..d814bfb 100644 --- a/manifests/go.pp +++ b/manifests/go.pp @@ -1,61 +1,60 @@ # download from go define archive::go ( String $server, Integer $port, String $url_path, String $md5_url_path, String $username, String $password, Enum['present', 'absent'] $ensure = present, String $path = $name, Optional[String] $owner = undef, Optional[String] $group = undef, Optional[String] $mode = undef, Optional[Boolean] $extract = undef, Optional[String] $extract_path = undef, Optional[String] $creates = undef, Optional[Boolean] $cleanup = undef, Optional[Stdlib::Compat::Absolute_path] $archive_path = undef, ) { - include archive::params if $archive_path { $file_path = "${archive_path}/${name}" } else { $file_path = $path } if $file_path !~ Stdlib::Compat::Absolute_path { fail("archive::go[${name}]: \$name or \$archive_path must be an absolute path!") # lint:ignore:trailing_comma } $go_url = "http://${server}:${port}" $file_url = "${go_url}/${url_path}" $md5_url = "${go_url}/${md5_url_path}" archive { $file_path: ensure => $ensure, path => $file_path, extract => $extract, extract_path => $extract_path, source => $file_url, checksum => archive::go_md5($username, $password, $name, $md5_url), checksum_type => 'md5', creates => $creates, cleanup => $cleanup, username => $username, password => $password, } $file_owner = pick($owner, $archive::params::owner) $file_group = pick($group, $archive::params::group) $file_mode = pick($mode, $archive::params::mode) file { $file_path: owner => $file_owner, group => $file_group, mode => $file_mode, require => Archive[$file_path], } } diff --git a/manifests/init.pp b/manifests/init.pp index 5437296..6e67b63 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,70 +1,69 @@ # @summary Manages archive module's dependencies. # # @example On Windows, ensure 7zip is installed using the default `chocolatey` provider. # include archive # # @example On Windows, install a 7zip MSI with the native `windows` package provider. # class { 'archive': # seven_zip_name => '7-Zip 9.20 (x64 edition)', # seven_zip_source => 'C:/Windows/Temp/7z920-x64.msi', # seven_zip_provider => 'windows', # } # # @example Install the AWS CLI tool. (Not supported on Windows). # class { 'archive': # aws_cli_install => true, # } # # @param seven_zip_name # 7zip package name. This parameter only applies to Windows. # @param seven_zip_provider # 7zip package provider. This parameter only applies to Windows where it defaults to `chocolatey`. Can be set to an empty string, (or `undef` via hiera), if you don't want this module to manage 7zip. # @param seven_zip_source # Alternative package source for 7zip. This parameter only applies to Windows. # @param aws_cli_install # Installs the AWS CLI command needed for downloading from S3 buckets. This parameter is currently not implemented on Windows. # class archive ( Optional[String[1]] $seven_zip_name = $archive::params::seven_zip_name, Optional[Enum['chocolatey','windows','']] $seven_zip_provider = $archive::params::seven_zip_provider, Optional[String[1]] $seven_zip_source = undef, Boolean $aws_cli_install = false, ) inherits archive::params { - if $facts['os']['family'] == 'Windows' and !($seven_zip_provider in ['', undef]) { package { '7zip': ensure => present, name => $seven_zip_name, source => $seven_zip_source, provider => $seven_zip_provider, } } if $aws_cli_install { # TODO: Windows support. if $facts['os']['family'] != 'Windows' { # Using bundled install option: # http://docs.aws.amazon.com/cli/latest/userguide/installing.html#install-bundle-other-os file { '/opt/awscli-bundle': ensure => 'directory', } archive { 'awscli-bundle.zip': ensure => present, - path => '/opt/awscli-bundle/awscli-bundle.zip', + path => '/opt/awscli-bundle/awscli-bundle.zip', source => 'https://s3.amazonaws.com/aws-cli/awscli-bundle.zip', extract => true, extract_path => '/opt', creates => '/opt/awscli-bundle/install', cleanup => true, } exec { 'install_aws_cli': command => '/opt/awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws', refreshonly => true, subscribe => Archive['awscli-bundle.zip'], } } } } diff --git a/manifests/nexus.pp b/manifests/nexus.pp index 17e27df..f070ddd 100644 --- a/manifests/nexus.pp +++ b/manifests/nexus.pp @@ -1,114 +1,122 @@ # define: archive::nexus # ====================== # # archive wrapper for downloading files from Nexus using REST API. Nexus API: # https://repository.sonatype.org/nexus-restlet1x-plugin/default/docs/path__artifact_maven_content.html # # Parameters # ---------- # # Examples # -------- # # archive::nexus { '/tmp/jtstand-ui-0.98.jar': # url => 'https://oss.sonatype.org', # gav => 'org.codehaus.jtstand:jtstand-ui:0.98', # repository => 'codehaus-releases', # packaging => 'jar', # extract => false, # } # define archive::nexus ( String $url, String $gav, String $repository, Enum['present', 'absent'] $ensure = present, Enum['none', 'md5', 'sha1', 'sha2','sha256', 'sha384', 'sha512'] $checksum_type = 'md5', Boolean $checksum_verify = true, String $packaging = 'jar', Boolean $use_nexus3_urls = false, Optional[String] $classifier = undef, Optional[String] $extension = undef, Optional[String] $username = undef, Optional[String] $password = undef, Optional[String] $user = undef, Optional[String] $owner = undef, Optional[String] $group = undef, Optional[String] $mode = undef, Optional[Boolean] $extract = undef, Optional[String] $extract_path = undef, Optional[String] $extract_flags = undef, Optional[String] $extract_command = undef, Optional[String] $creates = undef, Optional[Boolean] $cleanup = undef, Optional[String] $proxy_server = undef, Optional[String] $proxy_type = undef, Optional[Boolean] $allow_insecure = undef, ) { - include archive::params $artifact_info = split($gav, ':') $group_id = $artifact_info[0] $artifact_id = $artifact_info[1] $version = $artifact_info[2] $query_params = { - 'g' => $group_id, 'a' => $artifact_id, 'v' => $version, 'r' => $repository, 'p' => $packaging, 'c' => $classifier, 'e' => $extension, - }.filter |$keys, $values| { $values != undef } if $use_nexus3_urls { if $classifier { $c = "-${classifier}" } else { $c = '' } - $artifact_url = sprintf('%s/repository/%s/%s/%s/%s/%s-%s%s.%s', $url, - $repository, regsubst($group_id, '\.', '/', 'G'), $artifact_id, - $version, $artifact_id, $version, $c, $packaging) + + $artifact_url = sprintf( + '%s/repository/%s/%s/%s/%s/%s-%s%s.%s', + $url, + $repository, + regsubst($group_id, '\.', '/', 'G'), + $artifact_id, + $version, + $artifact_id, + $version, + $c, + $packaging + ) + $checksum_url = sprintf('%s.%s', $artifact_url, $checksum_type) } else { $artifact_url = archive::assemble_nexus_url($url, $query_params) $checksum_url = regsubst($artifact_url, "p=${packaging}", "p=${packaging}.${checksum_type}") } archive { $name: ensure => $ensure, source => $artifact_url, username => $username, password => $password, checksum_url => $checksum_url, checksum_type => $checksum_type, checksum_verify => $checksum_verify, extract => $extract, extract_path => $extract_path, extract_flags => $extract_flags, extract_command => $extract_command, user => $user, group => $group, creates => $creates, cleanup => $cleanup, proxy_server => $proxy_server, proxy_type => $proxy_type, allow_insecure => $allow_insecure, } $file_owner = pick($owner, $archive::params::owner) $file_group = pick($group, $archive::params::group) $file_mode = pick($mode, $archive::params::mode) file { $name: owner => $file_owner, group => $file_group, mode => $file_mode, require => Archive[$name], } }