1
1
require 'puppet/network/http/handler'
3
class Puppet::Network::HTTP::MongrelREST < Puppet::Network::HTTP::Handler
3
class Puppet::Network::HTTP::MongrelREST < Mongrel::HttpHandler
5
include Puppet::Network::HTTP::Handler
7
def initialize(args={})
9
initialize_for_puppet(args)
12
# Return the query params for this request. We had to expose this method for
15
Mongrel::HttpRequest.query_parse(request.params["QUERY_STRING"]).merge(client_info(request))
8
@server.register('/' + @handler.to_s, self)
9
@server.register('/' + @handler.to_s + 's', self)
20
# which HTTP verb was used in this request
12
21
def http_method(request)
13
22
request.params[Mongrel::Const::REQUEST_METHOD]
25
# what path was requested?
17
27
# LAK:NOTE See http://snurl.com/21zf8 [groups_google_com]
18
28
x = '/' + request.params[Mongrel::Const::REQUEST_PATH].split('/')[1]
31
# return the key included in the request path
21
32
def request_key(request)
22
33
# LAK:NOTE See http://snurl.com/21zf8 [groups_google_com]
23
34
x = request.params[Mongrel::Const::REQUEST_PATH].split('/')[2]
37
# return the request body
31
Mongrel::HttpRequest.query_parse(request.params["QUERY_STRING"])
42
# produce the body of the response
34
43
def encode_result(request, response, result, status = 200)
35
44
response.start(status) do |head, body|
49
def client_info(request)
51
params = request.params
52
result[:ip] = params["REMOTE_ADDR"]
54
# JJM #906 The following dn.match regular expression is forgiving
55
# enough to match the two Distinguished Name string contents
56
# coming from Apache, Pound or other reverse SSL proxies.
57
if dn = params[Puppet[:ssl_client_header]] and dn_matchdata = dn.match(/^.*?CN\s*=\s*(.*)/)
58
result[:node] = dn_matchdata[1].to_str
59
result[:authenticated] = (params[Puppet[:ssl_client_verify_header]] == 'SUCCESS')
61
result[:authenticated] = false