Class: Puppet::Network::XMLRPC::WEBrickServlet

Inherits:
XMLRPC::WEBrickServlet
  • Object
show all
Includes:
Puppet::Network::XMLRPCProcessor
Defined in:
lib/vendor/puppet/network/xmlrpc/webrick_servlet.rb

Constant Summary

Constants included from Puppet::Network::XMLRPCProcessor

Puppet::Network::XMLRPCProcessor::ERR_UNAUTHORIZED

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Puppet::Network::XMLRPCProcessor

#add_handler, #handler_loaded?, #process

Methods included from Authorization

#authconfig, #authorized?, #available?, #verify

Constructor Details

#initialize(handlers) ⇒ WEBrickServlet

Accept a list of handlers and register them all.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/vendor/puppet/network/xmlrpc/webrick_servlet.rb', line 23

def initialize(handlers)
  # the servlet base class does not consume any arguments
  # and its BasicServer base class only accepts a 'class_delim'
  # option which won't change in Puppet at all
  # thus, we don't need to pass any args to our base class,
  # and we can consume them all ourselves
  super()

  setup_processor

  # Set up each of the passed handlers.
  handlers.each do |handler|
    add_handler(handler.class.interface, handler)
  end
end

Class Method Details

.log(msg) ⇒ Object

This is a hackish way to avoid an auth message every time we have a normal operation



12
13
14
15
16
17
18
19
20
# File 'lib/vendor/puppet/network/xmlrpc/webrick_servlet.rb', line 12

def self.log(msg)
  @logs ||= {}
  if @logs.include?(msg)
    @logs[msg] += 1
  else
    Puppet.info msg
    @logs[msg] = 1
  end
end

Instance Method Details

#service(request, response) ⇒ Object

Handle the actual request. We can’t use the super() method, because we need to pass a ClientRequest object to process so we can do authorization. It’s the only way to stay thread-safe.

Raises:

  • (WEBrick::HTTPStatus::BadRequest)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/vendor/puppet/network/xmlrpc/webrick_servlet.rb', line 42

def service(request, response)
  if @valid_ip
    raise WEBrick::HTTPStatus::Forbidden unless @valid_ip.any? { |ip| request.peeraddr[3] =~ ip }
  end

  if request.request_method != "POST"
    raise WEBrick::HTTPStatus::MethodNotAllowed,
      "unsupported method `#{request.request_method}'."
  end

  raise WEBrick::HTTPStatus::BadRequest if parse_content_type(request['Content-type']).first != "text/xml"

  length = (request['Content-length'] || 0).to_i

  raise WEBrick::HTTPStatus::LengthRequired unless length > 0

  data = request.body

  raise WEBrick::HTTPStatus::BadRequest if data.nil? or data.size != length

  resp = process(data, client_request(request))
  raise WEBrick::HTTPStatus::InternalServerError if resp.nil? or resp.size <= 0

  response.status = 200
  response['Content-Length'] = resp.size
  response['Content-Type']   = "text/xml; charset=utf-8"
  response.body = resp
end