~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to lib/puppet/network/http/mongrel/rest.rb

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mfrom: (1.1.8 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080726154345-c03m49twzxewdwjn
Tags: 0.24.5-2
* Fix puppetlast to work with 0.24.5
* Adjust logcheck to match against new log messages in 0.24.5
* Update standards version to 3.8.0 (no changes)
* Update changelog to reduce length of line to make lintian happy

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
require 'puppet/network/http/handler'
2
2
 
3
 
class Puppet::Network::HTTP::MongrelREST < Puppet::Network::HTTP::Handler
 
3
class Puppet::Network::HTTP::MongrelREST < Mongrel::HttpHandler
 
4
 
 
5
    include Puppet::Network::HTTP::Handler
 
6
 
 
7
    def initialize(args={})
 
8
        super()
 
9
        initialize_for_puppet(args)
 
10
    end
 
11
 
 
12
    # Return the query params for this request.  We had to expose this method for
 
13
    # testing purposes.
 
14
    def params(request)
 
15
        Mongrel::HttpRequest.query_parse(request.params["QUERY_STRING"]).merge(client_info(request))
 
16
    end
4
17
 
5
18
  private
6
 
    
7
 
    def register_handler
8
 
        @server.register('/' + @handler.to_s, self)
9
 
        @server.register('/' + @handler.to_s + 's', self)
10
 
    end
11
 
    
 
19
 
 
20
    # which HTTP verb was used in this request
12
21
    def http_method(request)
13
22
        request.params[Mongrel::Const::REQUEST_METHOD]
14
23
    end
15
 
    
 
24
 
 
25
    # what path was requested?
16
26
    def path(request)
17
27
        # LAK:NOTE See http://snurl.com/21zf8  [groups_google_com] 
18
28
        x = '/' + request.params[Mongrel::Const::REQUEST_PATH].split('/')[1]
19
29
    end
20
 
    
 
30
 
 
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]        
24
35
    end
25
 
    
 
36
 
 
37
    # return the request body
26
38
    def body(request)
27
39
        request.body
28
40
    end
29
 
    
30
 
    def params(request)
31
 
        Mongrel::HttpRequest.query_parse(request.params["QUERY_STRING"])
32
 
    end
33
 
    
 
41
 
 
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|
36
45
            body.write(result)
37
46
        end
38
47
    end
 
48
 
 
49
    def client_info(request)
 
50
        result = {}
 
51
        params = request.params
 
52
        result[:ip] = params["REMOTE_ADDR"]
 
53
 
 
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')
 
60
        else
 
61
            result[:authenticated] = false
 
62
        end
 
63
 
 
64
        return result
 
65
    end
39
66
end