Skip to content

Commit 21bccfb

Browse files
committed
(PUP-11428) Refactor how the default ssl_context is created
Move the code for creating the default ssl_context into the http client, which is similar to how the default *system* ssl_context is created.
1 parent 842cce9 commit 21bccfb

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

lib/puppet.rb

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -242,20 +242,7 @@ def self.base_context(settings)
242242
{
243243
:environments => Puppet::Environments::Cached.new(Puppet::Environments::Combined.new(*loaders)),
244244
:http_pool => proc { Puppet.runtime[:http].pool },
245-
:ssl_context => proc {
246-
begin
247-
cert = Puppet::X509::CertProvider.new
248-
password = cert.load_private_key_password
249-
ssl = Puppet::SSL::SSLProvider.new
250-
ssl.load_context(certname: Puppet[:certname], password: password)
251-
rescue => e
252-
# TRANSLATORS: `message` is an already translated string of why SSL failed to initialize
253-
Puppet.log_exception(e, _("Failed to initialize SSL: %{message}") % { message: e.message })
254-
# TRANSLATORS: `puppet agent -t` is a command and should not be translated
255-
Puppet.err(_("Run `puppet agent -t`"))
256-
raise e
257-
end
258-
},
245+
:ssl_context => proc { Puppet.runtime[:http].default_ssl_context },
259246
:ssl_host => proc { Puppet::SSL::Host.localhost(true) },
260247
:http_session => proc { Puppet.runtime[:http].create_session },
261248
:plugins => proc { Puppet::Plugins::Configuration.load_plugins },

lib/puppet/http/client.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,20 @@ def close
274274
@pool.close
275275
end
276276

277+
def default_ssl_context
278+
cert = Puppet::X509::CertProvider.new
279+
password = cert.load_private_key_password
280+
281+
ssl = Puppet::SSL::SSLProvider.new
282+
ssl.load_context(certname: Puppet[:certname], password: password)
283+
rescue => e
284+
# TRANSLATORS: `message` is an already translated string of why SSL failed to initialize
285+
Puppet.log_exception(e, _("Failed to initialize SSL: %{message}") % { message: e.message })
286+
# TRANSLATORS: `puppet agent -t` is a command and should not be translated
287+
Puppet.err(_("Run `puppet agent -t`"))
288+
raise e
289+
end
290+
277291
protected
278292

279293
def encode_query(url, params)

0 commit comments

Comments
 (0)