diff --git a/manifests/nexus.pp b/manifests/nexus.pp index f070ddd..2a9395b 100644 --- a/manifests/nexus.pp +++ b/manifests/nexus.pp @@ -1,122 +1,124 @@ # 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, + Optional[Stdlib::Absolutepath] $temp_dir = 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 ) $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, + temp_dir => $temp_dir, } $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], } } diff --git a/spec/defines/nexus_spec.rb b/spec/defines/nexus_spec.rb index 0000cb2..70c0672 100644 --- a/spec/defines/nexus_spec.rb +++ b/spec/defines/nexus_spec.rb @@ -1,185 +1,187 @@ require 'spec_helper' describe 'archive::nexus' do let(:facts) { { os: { family: 'RedHat' }, puppetversion: '4.4.0' } } context 'nexus archive with defaults' do let(:title) { '/tmp/hawtio.war' } let(:params) do { url: 'https://oss.sonatype.org', gav: 'io.hawt:hawtio-web:1.4.36', repository: 'releases', packaging: 'war' } end it do is_expected.to contain_archive('/tmp/hawtio.war').with( source: 'https://oss.sonatype.org/service/local/artifact/maven/content?g=io.hawt&a=hawtio-web&v=1.4.36&r=releases&p=war', checksum_url: 'https://oss.sonatype.org/service/local/artifact/maven/content?g=io.hawt&a=hawtio-web&v=1.4.36&r=releases&p=war.md5' ) end it do is_expected.to contain_file('/tmp/hawtio.war').that_requires('Archive[/tmp/hawtio.war]').with( owner: '0', group: '0' ) end end context 'nexus archive with overwritten parameters' do let(:title) { '/tmp/artifact.war' } let(:params) do { url: 'https://oss.sonatype.org', gav: 'io.hawt:hawtio-web:1.4.36', repository: 'releases', owner: 'tom', group: 'worker', user: 'tom', extract: true, extract_path: '/opt', creates: '/opt/artifact/WEB-INF', - cleanup: true + cleanup: true, + temp_dir: '/tmp' } end it do is_expected.to contain_archive('/tmp/artifact.war').with( 'user' => 'tom', 'group' => 'worker', 'extract' => true, 'extract_path' => '/opt', 'creates' => '/opt/artifact/WEB-INF', - 'cleanup' => true + 'cleanup' => true, + 'temp_dir' => '/tmp' ) end it do is_expected.to contain_file('/tmp/artifact.war').that_requires('Archive[/tmp/artifact.war]').with( 'owner' => 'tom', 'group' => 'worker' ) end end context 'nexus archive with checksum_verify => false' do let :title do '/tmp/artifact.war' end let :params do { url: 'https://oss.sonatype.org', gav: 'io.hawt:hawtio-web:1.4.36', repository: 'releases', owner: 'tom', group: 'worker', user: 'tom', extract: true, extract_path: '/opt', creates: '/opt/artifact/WEB-INF', cleanup: true, checksum_verify: false } end it do is_expected.to contain_archive('/tmp/artifact.war').with( 'user' => 'tom', 'group' => 'worker', 'extract' => true, 'extract_path' => '/opt', 'creates' => '/opt/artifact/WEB-INF', 'cleanup' => true, 'checksum_verify' => false ) end it do is_expected.to contain_file('/tmp/artifact.war').that_requires('Archive[/tmp/artifact.war]').with( 'owner' => 'tom', 'group' => 'worker' ) end end context 'nexus archive with allow_insecure => true' do let(:title) { '/tmp/artifact.war' } let(:params) do { url: 'https://oss.sonatype.org', gav: 'io.hawt:hawtio-web:1.4.36', repository: 'releases', packaging: 'war', allow_insecure: true } end it { is_expected.to contain_archive('/tmp/artifact.war').with_allow_insecure(true) } end context 'nexus archive with allow_insecure => false' do let(:title) { '/tmp/artifact.war' } let(:params) do { url: 'https://oss.sonatype.org', gav: 'io.hawt:hawtio-web:1.4.36', repository: 'releases', packaging: 'war', allow_insecure: false } end it { is_expected.to contain_archive('/tmp/artifact.war').with_allow_insecure(false) } end context 'nexus archive with allow_insecure => \'foobar\'' do let(:title) { '/tmp/artifact.war' } let(:params) do { url: 'https://oss.sonatype.org', gav: 'io.hawt:hawtio-web:1.4.36', repository: 'releases', packaging: 'war', allow_insecure: 'foobar' } end it { is_expected.to compile.and_raise_error(%r{parameter 'allow_insecure' expects a value of type Undef or Boolean, got String}) } end context 'nexus archive with use_nexus3_urls => false' do let(:title) { '/tmp/artifact.war' } let(:params) do { url: 'https://oss.sonatype.org', gav: 'io.hawt:hawtio-web:1.4.36', repository: 'releases', packaging: 'war', use_nexus3_urls: false } end it { is_expected.to contain_archive('/tmp/artifact.war').with_source('https://oss.sonatype.org/service/local/artifact/maven/content?g=io.hawt&a=hawtio-web&v=1.4.36&r=releases&p=war') } end context 'nexus archive with use_nexus3_urls => true' do let(:title) { '/tmp/artifact.war' } let(:params) do { url: 'https://oss.sonatype.org', gav: 'io.hawt:hawtio-web:1.4.36', repository: 'releases', packaging: 'war', use_nexus3_urls: true } end it { is_expected.to contain_archive('/tmp/artifact.war').with_source('https://oss.sonatype.org/repository/releases/io/hawt/hawtio-web/1.4.36/hawtio-web-1.4.36.war') } end end