Skip to content

Commit

Permalink
Safer version check
Browse files Browse the repository at this point in the history
This prevents facter from getting stuck in an interactive session
  • Loading branch information
mvandegarde committed Sep 17, 2021
1 parent f104abf commit 5778673
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/facter/splunkforwarder_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
cmd = if File.exist?('C:/Program Files/SplunkUniversalForwarder/bin/splunk.exe')
'"C:/Program Files/SplunkUniversalForwarder/bin/splunk.exe" --version'
elsif File.exist?('/opt/splunkforwarder/bin/splunk')
'/opt/splunkforwarder/bin/splunk --version'
'/opt/splunkforwarder/bin/splunk --version --accept-license --answer-yes --no-prompt'
end
if cmd
output = Facter::Util::Resolution.exec(cmd)
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/facter/splunkforwarder_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
it 'returns version for Linux' do
allow(File).to receive(:exist?).with('C:/Program Files/SplunkUniversalForwarder/bin/splunk.exe').and_return(false)
allow(File).to receive(:exist?).with('/opt/splunkforwarder/bin/splunk').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('/opt/splunkforwarder/bin/splunk --version').and_return('Splunk Universal Forwarder 7.0.2 (build 03bbabbd5c0f)')
allow(Facter::Util::Resolution).to receive(:exec).with('/opt/splunkforwarder/bin/splunk --version --accept-license --answer-yes --no-prompt').and_return('Splunk Universal Forwarder 7.0.2 (build 03bbabbd5c0f)')
expect(Facter.fact(:splunkforwarder_version).value).to eq('7.0.2')
end

Expand Down

0 comments on commit 5778673

Please sign in to comment.