Method: Puppet::Network::HttpPool.connection

Defined in:
lib/puppet/network/http_pool.rb

.connection(host, port, use_ssl: true, ssl_context: nil) ⇒ Puppet::Network::HTTP::Connection

Retrieve a connection for the given host and port.

Parameters:

  • host (String)

    The host to connect to

  • port (Integer)

    The port to connect to

  • use_ssl (Boolean) (defaults to: true)

    Whether to use SSL, defaults to ‘true`.

  • ssl_context (Puppet::SSL:SSLContext, nil) (defaults to: nil)

    The ssl context to use when making HTTPS connections. Required when ‘use_ssl` is `true`.

Returns:



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/puppet/network/http_pool.rb', line 75

def self.connection(host, port, use_ssl: true, ssl_context: nil)
  if use_ssl
    unless ssl_context
      # TRANSLATORS 'ssl_context' is an argument and should not be translated
      raise ArgumentError, _("An ssl_context is required when connecting to 'https://%{host}:%{port}'") % { host: host, port: port }
    end

    verifier = Puppet::SSL::Verifier.new(host, ssl_context)
    http_client_class.new(host, port, use_ssl: true, verifier: verifier)
  else
    if ssl_context
      # TRANSLATORS 'ssl_context' is an argument and should not be translated
      Puppet.warning(_("An ssl_context is unnecessary when connecting to 'http://%{host}:%{port}' and will be ignored") % { host: host, port: port })
    end

    http_client_class.new(host, port, use_ssl: false)
  end
end