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

Fixed #93 Make puppet version check respect env vars #94

Merged
merged 1 commit into from
Mar 17, 2017
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
2 changes: 1 addition & 1 deletion lib/octocatalog-diff/catalog/computed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def build(logger = Logger.new(StringIO.new))
# @return [String] Puppet version
def puppet_version
raise ArgumentError, '"puppet_binary" was not passed to OctocatalogDiff::Catalog::Computed' unless @puppet_binary
@puppet_version ||= OctocatalogDiff::Util::PuppetVersion.puppet_version(@puppet_binary)
@puppet_version ||= OctocatalogDiff::Util::PuppetVersion.puppet_version(@puppet_binary, @opts)
end

# Compilation directory
Expand Down
5 changes: 4 additions & 1 deletion lib/octocatalog-diff/util/puppetversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ module Util
class PuppetVersion
# Determine the version of Puppet.
# @param puppet [String] Path to Puppet binary
# @param options [Hash] Options hash as defined in OctocatalogDiff::Catalog::Computed
# @return [String] Puppet version number
def self.puppet_version(puppet)
def self.puppet_version(puppet, options = {})
raise ArgumentError, 'Puppet binary was not supplied' if puppet.nil?
raise Errno::ENOENT, "Puppet binary #{puppet} doesn't exist" unless File.file?(puppet)
cmdline = [Shellwords.escape(puppet), '--version'].join(' ')
Expand All @@ -24,6 +25,8 @@ def self.puppet_version(puppet)
'PATH' => ENV['PATH'],
'PWD' => File.dirname(puppet)
}
pass_env_vars = options.fetch(:pass_env_vars, [])
pass_env_vars.each { |var| env[var] ||= ENV[var] }
out, err, _status = Open3.capture3(env, cmdline, unsetenv_others: true, chdir: env['PWD'])
return Regexp.last_match(1) if out =~ /^([\d\.]+)\s*$/
raise "Unable to determine Puppet version: #{out} #{err}"
Expand Down