File: resolver.rb

package info (click to toggle)
puppet-agent 7.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 19,092 kB
  • sloc: ruby: 245,074; sh: 456; makefile: 38; xml: 33
file content (48 lines) | stat: -rw-r--r-- 1,646 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Resolver base class. Each resolver represents a different strategy for
# resolving a service name into a list of candidate servers and ports.
#
# @abstract Subclass and override {#resolve} to create a new resolver.
# @api public
class Puppet::HTTP::Resolver
  #
  # Create a new resolver.
  #
  # @param [Puppet::HTTP::Client] client
  def initialize(client)
    @client = client
  end

  # Return a working server/port for the resolver. This is the base
  # implementation and is meant to be a placeholder.
  #
  # @param [Puppet::HTTP::Session] session
  # @param [Symbol] name the service to resolve
  # @param [Puppet::SSL::SSLContext] ssl_context (nil) optional ssl context to
  #   use when creating a connection
  # @param [Proc] canceled_handler (nil) optional callback allowing a resolver
  #   to cancel resolution.
  #
  # @raise [NotImplementedError] this base class is not implemented
  #
  # @api public
  def resolve(session, name, ssl_context: nil, canceled_handler: nil)
    raise NotImplementedError
  end

  # Check a given connection to establish if it can be relied on for future use.
  #
  # @param [Puppet::HTTP::Session] session
  # @param [Puppet::HTTP::Service] service
  # @param [Puppet::SSL::SSLContext] ssl_context
  #
  # @return [Boolean] Returns true if a connection is successful, false otherwise
  #
  # @api public
  def check_connection?(session, service, ssl_context: nil)
    service.connect(ssl_context: ssl_context)
    return true
  rescue Puppet::HTTP::ConnectionError => e
    Puppet.log_exception(e, "Connection to #{service.url} failed, trying next route: #{e.message}")
    return false
  end
end