File: api.rb

package info (click to toggle)
puppet-agent 8.10.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,404 kB
  • sloc: ruby: 286,820; sh: 492; xml: 116; makefile: 88; cs: 68
file content (41 lines) | stat: -rw-r--r-- 2,047 bytes parent folder | download | duplicates (2)
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
# frozen_string_literal: true

class Puppet::Network::HTTP::API
  require_relative '../../../puppet/version'

  def self.not_found
    Puppet::Network::HTTP::Route
      .path(/.*/)
      .any(lambda do |req, _res|
        raise Puppet::Network::HTTP::Error::HTTPNotFoundError.new("No route for #{req.method} #{req.path}", Puppet::Network::HTTP::Issues::HANDLER_NOT_FOUND)
      end)
  end

  def self.not_found_upgrade
    Puppet::Network::HTTP::Route
      .path(/.*/)
      .any(lambda do |_req, _res|
        raise Puppet::Network::HTTP::Error::HTTPNotFoundError.new("Error: Invalid URL - Puppet expects requests that conform to the " \
                                                                  "/puppet and /puppet-ca APIs.\n\n" \
                                                                  "Note that Puppet 3 agents aren't compatible with this version; if you're " \
                                                                  "running Puppet 3, you must either upgrade your agents to match the server " \
                                                                  "or point them to a server running Puppet 3.\n\n" \
                                                                  "Server Info:\n" \
                                                                  "  Puppet version: #{Puppet.version}\n" \
                                                                  "  Supported /puppet API versions: #{Puppet::Network::HTTP::SERVER_URL_VERSIONS}\n",
                                                                  Puppet::Network::HTTP::Issues::HANDLER_NOT_FOUND)
      end)
  end

  def self.server_routes
    server_prefix = Regexp.new("^#{Puppet::Network::HTTP::SERVER_URL_PREFIX}/")
    Puppet::Network::HTTP::Route.path(server_prefix)
                                .any
                                .chain(Puppet::Network::HTTP::API::Server::V3.routes,
                                       Puppet::Network::HTTP::API.not_found)
  end

  def self.master_routes
    server_routes
  end
end