Skip to content

Commit 17cb262

Browse files
author
Dylan Ratcliffe
committed
Fixed #93 Make puppet version check respect env vars
1 parent b024941 commit 17cb262

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/octocatalog-diff/catalog/computed.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def build(logger = Logger.new(StringIO.new))
6868
# @return [String] Puppet version
6969
def puppet_version
7070
raise ArgumentError, '"puppet_binary" was not passed to OctocatalogDiff::Catalog::Computed' unless @puppet_binary
71-
@puppet_version ||= OctocatalogDiff::Util::PuppetVersion.puppet_version(@puppet_binary)
71+
@puppet_version ||= OctocatalogDiff::Util::PuppetVersion.puppet_version(@puppet_binary, @opts)
7272
end
7373

7474
# Compilation directory

lib/octocatalog-diff/util/puppetversion.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ module Util
1212
class PuppetVersion
1313
# Determine the version of Puppet.
1414
# @param puppet [String] Path to Puppet binary
15+
# @param options [Hash] Options hash as defined in OctocatalogDiff::Catalog::Computed
1516
# @return [String] Puppet version number
16-
def self.puppet_version(puppet)
17+
def self.puppet_version(puppet, options = {})
1718
raise ArgumentError, 'Puppet binary was not supplied' if puppet.nil?
1819
raise Errno::ENOENT, "Puppet binary #{puppet} doesn't exist" unless File.file?(puppet)
1920
cmdline = [Shellwords.escape(puppet), '--version'].join(' ')
@@ -24,6 +25,8 @@ def self.puppet_version(puppet)
2425
'PATH' => ENV['PATH'],
2526
'PWD' => File.dirname(puppet)
2627
}
28+
pass_env_vars = options.fetch(:pass_env_vars, [])
29+
pass_env_vars.each { |var| env[var] ||= ENV[var] }
2730
out, err, _status = Open3.capture3(env, cmdline, unsetenv_others: true, chdir: env['PWD'])
2831
return Regexp.last_match(1) if out =~ /^([\d\.]+)\s*$/
2932
raise "Unable to determine Puppet version: #{out} #{err}"

0 commit comments

Comments
 (0)