File: puppetserver.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 (53 lines) | stat: -rw-r--r-- 1,655 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
49
50
51
52
53
# The puppetserver service.
#
# @api public
#
class Puppet::HTTP::Service::Puppetserver < Puppet::HTTP::Service

  # Use `Puppet::HTTP::Session.route_to(:puppetserver)` to create or get an instance of this class.
  #
  # @param [Puppet::HTTP::Client] client
  # @param [Puppet::HTTP::Session] session
  # @param [String] server (`Puppet[:server]`) If an explicit server is given,
  #   create a service using that server. If server is nil, the default value
  #   is used to create the service.
  # @param [Integer] port (`Puppet[:masterport]`) If an explicit port is given, create
  #   a service using that port. If port is nil, the default value is used to
  #   create the service.
  #
  def initialize(client, session, server, port)
    url = build_url('', server || Puppet[:server], port || Puppet[:serverport])
    super(client, session, url)
  end

  # Request the puppetserver's simple status.
  #
  # @param [Puppet::SSL::SSLContext] ssl_context to use when establishing
  # the connection.
  # @return Puppet::HTTP::Response The HTTP response
  #
  # @api public
  #
  def get_simple_status(ssl_context: nil)
    request_path = "/status/v1/simple/server"

    begin
      response = @client.get(
        with_base_url(request_path),
        headers: add_puppet_headers({}),
        options: {ssl_context: ssl_context}
      )

      process_response(response)
    rescue Puppet::HTTP::ResponseError => e
      if e.response.code == 404 && e.response.url.path == "/status/v1/simple/server"
        request_path = "/status/v1/simple/master"
        retry
      else
        raise e
      end
    end

    [response, response.body.to_s]
  end
end