Class: Puppet::Network::HTTP::WEBrickREST
- Inherits:
-
WEBrick::HTTPServlet::AbstractServlet
- Object
- WEBrick::HTTPServlet::AbstractServlet
- Puppet::Network::HTTP::WEBrickREST
- Includes:
- Handler
- Defined in:
- lib/puppet/network/http/webrick/rest.rb
Overview
Constant Summary
Constants included from Handler
Constants included from API::V1
Instance Attribute Summary
Attributes included from Handler
Instance Method Summary collapse
- #accept_header(request) ⇒ Object
- #body(request) ⇒ Object
- #client_cert(request) ⇒ Object
-
#client_information(request) ⇒ Object
Retrieve node/cert/ip information from the request object.
- #content_type_header(request) ⇒ Object
- #headers(request) ⇒ Object
- #http_method(request) ⇒ Object
-
#initialize(server, handler) ⇒ WEBrickREST
constructor
A new instance of WEBrickREST.
-
#params(request) ⇒ Object
Retrieve the request parameters, including authentication information.
- #path(request) ⇒ Object
-
#service(request, response) ⇒ Object
WEBrick uses a service method to respond to requests.
-
#set_content_type(response, format) ⇒ Object
Set the specified format as the content type of the response.
- #set_response(response, result, status = 200) ⇒ Object
Methods included from Handler
#do_destroy, #do_exception, #do_find, #do_head, #do_save, #do_search, #format_to_mime, #initialize_for_puppet, #process, #request_format, #resolve_node
Methods included from Authentication
Methods included from Authorization
#authconfig, #check_authorization
Methods included from API::V1
#indirection2uri, #indirection_method, #plurality, #pluralize, #request_to_uri_and_body, #uri2indirection
Constructor Details
#initialize(server, handler) ⇒ WEBrickREST
Returns a new instance of WEBrickREST.
10 11 12 13 14 |
# File 'lib/puppet/network/http/webrick/rest.rb', line 10 def initialize(server, handler) raise ArgumentError, "server is required" unless server super(server) initialize_for_puppet(:server => server, :handler => handler) end |
Instance Method Details
#accept_header(request) ⇒ Object
42 43 44 |
# File 'lib/puppet/network/http/webrick/rest.rb', line 42 def accept_header(request) request["accept"] end |
#body(request) ⇒ Object
58 59 60 |
# File 'lib/puppet/network/http/webrick/rest.rb', line 58 def body(request) request.body end |
#client_cert(request) ⇒ Object
62 63 64 |
# File 'lib/puppet/network/http/webrick/rest.rb', line 62 def client_cert(request) request.client_cert end |
#client_information(request) ⇒ Object
Retrieve node/cert/ip information from the request object.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/puppet/network/http/webrick/rest.rb', line 81 def client_information(request) result = {} if peer = request.peeraddr and ip = peer[3] result[:ip] = ip end # If they have a certificate (which will almost always be true) # then we get the hostname from the cert, instead of via IP # info result[:authenticated] = false if cert = request.client_cert and cn = Puppet::Util::SSL.cn_from_subject(cert.subject) result[:node] = cn result[:authenticated] = true else result[:node] = resolve_node(result) end result end |
#content_type_header(request) ⇒ Object
46 47 48 |
# File 'lib/puppet/network/http/webrick/rest.rb', line 46 def content_type_header(request) request["content-type"] end |
#headers(request) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/puppet/network/http/webrick/rest.rb', line 34 def headers(request) result = {} request.each do |k, v| result[k.downcase] = v end result end |
#http_method(request) ⇒ Object
50 51 52 |
# File 'lib/puppet/network/http/webrick/rest.rb', line 50 def http_method(request) request.request_method end |
#params(request) ⇒ Object
Retrieve the request parameters, including authentication information.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/puppet/network/http/webrick/rest.rb', line 17 def params(request) params = request.query || {} params = Hash[params.collect do |key, value| all_values = value.list [key, all_values.length == 1 ? value : all_values] end] params = decode_params(params) params.merge(client_information(request)) end |
#path(request) ⇒ Object
54 55 56 |
# File 'lib/puppet/network/http/webrick/rest.rb', line 54 def path(request) request.path end |
#service(request, response) ⇒ Object
WEBrick uses a service method to respond to requests. Simply delegate to the handler response method.
30 31 32 |
# File 'lib/puppet/network/http/webrick/rest.rb', line 30 def service(request, response) process(request, response) end |
#set_content_type(response, format) ⇒ Object
Set the specified format as the content type of the response.
67 68 69 |
# File 'lib/puppet/network/http/webrick/rest.rb', line 67 def set_content_type(response, format) response["content-type"] = format_to_mime(format) end |
#set_response(response, result, status = 200) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/puppet/network/http/webrick/rest.rb', line 71 def set_response(response, result, status = 200) response.status = status if status >= 200 and status != 304 response.body = result response["content-length"] = result.stat.size if result.is_a?(File) end response.reason_phrase = result if status < 200 or status >= 300 end |