Skip to content
Open
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
18 changes: 17 additions & 1 deletion lib/puppet_x/bodeco/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,22 @@
@proxy_port = uri.port
end

ENV['SSL_CERT_FILE'] = File.expand_path(File.join(__FILE__, '..', 'cacert.pem')) if Facter.value(:osfamily) == 'windows' && !ENV.key?('SSL_CERT_FILE')
@osfamily = Facter.value(:osfamily)
if @osfamily == 'windows'

Check failure on line 84 in lib/puppet_x/bodeco/util.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Style/GuardClause: Use a guard clause (`return unless @osfamily == 'windows'`) instead of wrapping the code inside a conditional expression. (https://rubystyle.guide#no-nested-conditionals)
# Get the 'ssl_trust_store' setting from the puppet agent
Puppet.settings.preferred_run_mode = :agent
puppet_ssl_trust_store = Puppet.settings.to_h[:ssl_trust_store].value || nil

# Prefer 'ssl_trust_store' from the puppet agent, then SSL_CERT_FILE from the
# environment, and the bundled pem file as a last resort
@ssl_trust_store = if puppet_ssl_trust_store && File.exist?(puppet_ssl_trust_store)
puppet_ssl_trust_store
elsif ENV.key?('SSL_CERT_FILE')
ENV['SSL_CERT_FILE']
else
File.expand_path(File.join(__FILE__, '..', 'cacert.pem'))
end
end
end

def generate_request(uri)
Expand All @@ -98,6 +113,7 @@
else
{ use_ssl: false }
end
http_opts[:ca_file] = @ssl_trust_store if @osfamily == 'windows'
Net::HTTP.start(uri.host, uri.port, @proxy_addr, @proxy_port, http_opts) do |http|
http.request(generate_request(uri)) do |response|
case response
Expand Down
Loading