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

(#29) Ensure vault is updated when version changes #52

Merged
merged 8 commits into from
Jul 12, 2024
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
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
C24-AK marked this conversation as resolved.
Show resolved Hide resolved
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'
C24-AK marked this conversation as resolved.
Show resolved Hide resolved
configure_beaker(modules: :metadata)

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