From 2ce7d3891e45183eaa6a8d474888c3877306b73d Mon Sep 17 00:00:00 2001 From: Mihmet Akpinar Date: Wed, 5 Jun 2024 08:53:30 +0200 Subject: [PATCH 1/8] Fixed issue #29 that version is not updated when parameter is changing --- lib/facter/vault_version.rb | 16 ++++++++++++++++ manifests/install.pp | 8 +++++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 lib/facter/vault_version.rb diff --git a/lib/facter/vault_version.rb b/lib/facter/vault_version.rb new file mode 100644 index 0000000..f65de5b --- /dev/null +++ b/lib/facter/vault_version.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# Fact: vault_version +# +# Purpose: Retrieve vault version if installed +# +Facter.add(:vault_version) do + setcode do + if Facter::Util::Resolution.which('vault') + vault_server_version_output = Facter::Util::Resolution.exec('vault version') + match = vault_server_version_output.match(%r{Vault v(\d+\.\d+\.\d+)}) + match ? match.captures.first : nil + end + end + end + \ No newline at end of file diff --git a/manifests/install.pp b/manifests/install.pp index c1a99e1..1b76965 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -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'], } From b7fe6fb96332e40b2ec3e410efcaf4b8dfa65658 Mon Sep 17 00:00:00 2001 From: Mihmet Akpinar Date: Wed, 5 Jun 2024 08:57:54 +0200 Subject: [PATCH 2/8] fix linting --- manifests/install.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/install.pp b/manifests/install.pp index 1b76965..9d49d35 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -19,7 +19,7 @@ extract_path => $vault::bin_dir, source => $vault::real_download_url, cleanup => true, - creates => $facts['vault_version'] ? { # lint:ignore:selector_inside_resource + creates => $facts['vault_version'] ? { # lint:ignore:selector_inside_resource undef => $vault_bin, default => versioncmp($vault::version, $facts['vault_version']) > 0 ? { true => undef, From 81f8c2588fafc28f5696035ddb44b10620807ffd Mon Sep 17 00:00:00 2001 From: Mihmet Akpinar Date: Wed, 5 Jun 2024 09:02:04 +0200 Subject: [PATCH 3/8] fix rubocop linting --- lib/facter/vault_version.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/facter/vault_version.rb b/lib/facter/vault_version.rb index f65de5b..b2af286 100644 --- a/lib/facter/vault_version.rb +++ b/lib/facter/vault_version.rb @@ -6,11 +6,10 @@ # Facter.add(:vault_version) do setcode do - if Facter::Util::Resolution.which('vault') - vault_server_version_output = Facter::Util::Resolution.exec('vault version') - match = vault_server_version_output.match(%r{Vault v(\d+\.\d+\.\d+)}) - match ? match.captures.first : nil - end + if Facter::Util::Resolution.which('vault') + 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 - end - \ No newline at end of file +end From 7cf05de74a246804bd4e1090798a2e6d0e7881c4 Mon Sep 17 00:00:00 2001 From: Mihmet Akpinar Date: Wed, 5 Jun 2024 09:04:22 +0200 Subject: [PATCH 4/8] fix rubocop linting --- lib/facter/vault_version.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/facter/vault_version.rb b/lib/facter/vault_version.rb index b2af286..d1ac06d 100644 --- a/lib/facter/vault_version.rb +++ b/lib/facter/vault_version.rb @@ -5,11 +5,11 @@ # Purpose: Retrieve vault version if installed # Facter.add(:vault_version) do - setcode do - if Facter::Util::Resolution.which('vault') - 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 + setcode do + if Facter::Util::Resolution.which('vault') + 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 end From 408dec4a8a57d53314d3627fe802aeb77b907d4b Mon Sep 17 00:00:00 2001 From: Mihmet Akpinar Date: Fri, 21 Jun 2024 12:54:04 +0200 Subject: [PATCH 5/8] use confine instead of if statement --- lib/facter/vault_version.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/facter/vault_version.rb b/lib/facter/vault_version.rb index d1ac06d..8826e38 100644 --- a/lib/facter/vault_version.rb +++ b/lib/facter/vault_version.rb @@ -5,11 +5,10 @@ # Purpose: Retrieve vault version if installed # Facter.add(:vault_version) do + confine {Facter::Util::Resolution.which('vault')} setcode do - if Facter::Util::Resolution.which('vault') - 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 + 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 From f5de2bae0f3d6e9d66c42175ff32d7f7d48f37ec Mon Sep 17 00:00:00 2001 From: Mihmet Akpinar Date: Fri, 21 Jun 2024 12:55:23 +0200 Subject: [PATCH 6/8] rubocop linting --- lib/facter/vault_version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/facter/vault_version.rb b/lib/facter/vault_version.rb index 8826e38..24008e6 100644 --- a/lib/facter/vault_version.rb +++ b/lib/facter/vault_version.rb @@ -5,7 +5,7 @@ # Purpose: Retrieve vault version if installed # Facter.add(:vault_version) do - confine {Facter::Util::Resolution.which('vault')} + 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+)}) From a8506073e097cd9ff9a4b152d3675a3ea82e4070 Mon Sep 17 00:00:00 2001 From: Mihmet Akpinar Date: Tue, 25 Jun 2024 13:03:02 +0200 Subject: [PATCH 7/8] add spec tests with mock vault_version fact --- spec/acceptance/class_spec.rb | 40 ++++++++++++++++++++++++++++++++++ spec/spec_helper_acceptance.rb | 1 + 2 files changed, 41 insertions(+) diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 2147a5d..773420d 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -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 'should 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 diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 2681792..4e1d21c 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -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 } From 7d9a561cf8dc75ca8f2c701a43dc42ab75680b78 Mon Sep 17 00:00:00 2001 From: Mihmet Akpinar Date: Tue, 25 Jun 2024 13:14:15 +0200 Subject: [PATCH 8/8] rubocop linting --- spec/acceptance/class_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 773420d..ded93f1 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -114,9 +114,9 @@ class { 'file_capability': PUPPET end - it 'should not be idempotent and cause changes' do + it 'will not be idempotent and cause changes' do apply_manifest(manifest, expect_changes: true) - end + end describe command('/usr/local/bin/vault version') do its(:exit_status) { is_expected.to eq 0 }