Skip to content

Commit

Permalink
Merge pull request #52 from C24-AK/feature/fix-issue-29
Browse files Browse the repository at this point in the history
(#29) Fix version is not updated when parameter is changing
  • Loading branch information
bastelfreak authored Jul 12, 2024
2 parents df3a940 + 7d9a561 commit a740954
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
14 changes: 14 additions & 0 deletions lib/facter/vault_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

# Fact: vault_version
#
# Purpose: Retrieve vault version if installed
#
Facter.add(:vault_version) do
confine { Facter::Util::Resolution.which('vault') }
setcode do
vault_server_version_output = Facter::Util::Resolution.exec('vault version')
match = vault_server_version_output.match(%r{Vault v(\d+\.\d+\.\d+)})
match&.captures&.first
end
end
8 changes: 7 additions & 1 deletion manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
extract_path => $vault::bin_dir,
source => $vault::real_download_url,
cleanup => true,
creates => $vault_bin,
creates => $facts['vault_version'] ? { # lint:ignore:selector_inside_resource
undef => $vault_bin,
default => versioncmp($vault::version, $facts['vault_version']) > 0 ? {
true => undef,
default => $vault_bin
}
},
before => File['vault_binary'],
}

Expand Down
40 changes: 40 additions & 0 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,46 @@ class { 'file_capability':
describe port(8200) do
it { is_expected.to be_listening.on('127.0.0.1').with('tcp') }
end

describe command('/usr/local/bin/vault version') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match %r{Vault v1.12.0} }
end
end

context 'default parameters with vesion higher than fact' do
let(:manifest) do
<<-PUPPET
if $facts['os']['name'] == 'Archlinux' {
class { 'file_capability':
package_name => 'libcap',
}
} else {
include file_capability
}
package { 'unzip': ensure => present }
-> class { 'vault':
storage => {
file => {
path => '/tmp',
}
},
bin_dir => '/usr/local/bin',
install_method => 'archive',
version => '1.12.1',
require => Class['file_capability'],
}
PUPPET
end

it 'will not be idempotent and cause changes' do
apply_manifest(manifest, expect_changes: true)
end

describe command('/usr/local/bin/vault version') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match %r{Vault v1.12.1} }
end
end

context 'with package based setup' do
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

require 'voxpupuli/acceptance/spec_helper_acceptance'

ENV['BEAKER_FACTER_VAULT_VERSION'] = '1.12.0'
configure_beaker(modules: :metadata)

Dir['./spec/support/acceptance/**/*.rb'].sort.each { |f| require f }

0 comments on commit a740954

Please sign in to comment.