diff options
| author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:12:17 -0700 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:12:17 -0700 |
| commit | 3180b9d9b2c844dade1d361326600f7001ec66dd (patch) | |
| tree | 98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /lib/puppet/network/http/rack | |
| parent | 543225970225de5697734bfaf0a6eee996802c04 (diff) | |
| download | puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip | |
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with
The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people
who learned ruby in the 1900s) uses two-space indentation.
3 Examples:
The code:
end
# Tell getopt which arguments are valid
def test_get_getopt_args
element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new
assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")
becomes:
end
# Tell getopt which arguments are valid
def test_get_getopt_args
element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new
assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")
The code:
assert_equal(str, val)
assert_instance_of(Float, result)
end
# Now test it with a passed object
becomes:
assert_equal(str, val)
assert_instance_of(Float, result)
end
# Now test it with a passed object
The code:
end
assert_nothing_raised do
klass[:Yay] = "boo"
klass["Cool"] = :yayness
end
becomes:
end
assert_nothing_raised do
klass[:Yay] = "boo"
klass["Cool"] = :yayness
end
Diffstat (limited to 'lib/puppet/network/http/rack')
| -rw-r--r-- | lib/puppet/network/http/rack/httphandler.rb | 14 | ||||
| -rw-r--r-- | lib/puppet/network/http/rack/rest.rb | 168 | ||||
| -rw-r--r-- | lib/puppet/network/http/rack/xmlrpc.rb | 98 |
3 files changed, 140 insertions, 140 deletions
diff --git a/lib/puppet/network/http/rack/httphandler.rb b/lib/puppet/network/http/rack/httphandler.rb index fed06f880..c54062357 100644 --- a/lib/puppet/network/http/rack/httphandler.rb +++ b/lib/puppet/network/http/rack/httphandler.rb @@ -3,14 +3,14 @@ require 'puppet/ssl/certificate' class Puppet::Network::HTTP::RackHttpHandler - def initialize - end + def initialize + end - # do something useful with request (a Rack::Request) and use - # response to fill your Rack::Response - def process(request, response) - raise NotImplementedError, "Your RackHttpHandler subclass is supposed to override service(request)" - end + # do something useful with request (a Rack::Request) and use + # response to fill your Rack::Response + def process(request, response) + raise NotImplementedError, "Your RackHttpHandler subclass is supposed to override service(request)" + end end diff --git a/lib/puppet/network/http/rack/rest.rb b/lib/puppet/network/http/rack/rest.rb index 5245275dd..e5f50c465 100644 --- a/lib/puppet/network/http/rack/rest.rb +++ b/lib/puppet/network/http/rack/rest.rb @@ -3,100 +3,100 @@ require 'puppet/network/http/rack/httphandler' class Puppet::Network::HTTP::RackREST < Puppet::Network::HTTP::RackHttpHandler - include Puppet::Network::HTTP::Handler + include Puppet::Network::HTTP::Handler - HEADER_ACCEPT = 'HTTP_ACCEPT'.freeze - ContentType = 'Content-Type'.freeze + HEADER_ACCEPT = 'HTTP_ACCEPT'.freeze + ContentType = 'Content-Type'.freeze - CHUNK_SIZE = 8192 + CHUNK_SIZE = 8192 - class RackFile - def initialize(file) - @file = file - end - - def each - while chunk = @file.read(CHUNK_SIZE) - yield chunk - end - end - - def close - @file.close - end - end - - def initialize(args={}) - super() - initialize_for_puppet(args) + class RackFile + def initialize(file) + @file = file end - def set_content_type(response, format) - response[ContentType] = format_to_mime(format) + def each + while chunk = @file.read(CHUNK_SIZE) + yield chunk + end end - # produce the body of the response - def set_response(response, result, status = 200) - response.status = status - unless result.is_a?(File) - response.write result - else - response["Content-Length"] = result.stat.size - response.body = RackFile.new(result) - end + def close + @file.close end - - # Retrieve the accept header from the http request. - def accept_header(request) - request.env[HEADER_ACCEPT] - end - - # Retrieve the accept header from the http request. - def content_type_header(request) - request.content_type + end + + def initialize(args={}) + super() + initialize_for_puppet(args) + end + + def set_content_type(response, format) + response[ContentType] = format_to_mime(format) + end + + # produce the body of the response + def set_response(response, result, status = 200) + response.status = status + unless result.is_a?(File) + response.write result + else + response["Content-Length"] = result.stat.size + response.body = RackFile.new(result) end - - # Return which HTTP verb was used in this request. - def http_method(request) - request.request_method + end + + # Retrieve the accept header from the http request. + def accept_header(request) + request.env[HEADER_ACCEPT] + end + + # Retrieve the accept header from the http request. + def content_type_header(request) + request.content_type + end + + # Return which HTTP verb was used in this request. + def http_method(request) + request.request_method + end + + # Return the query params for this request. + def params(request) + result = decode_params(request.params) + result.merge(extract_client_info(request)) + end + + # what path was requested? (this is, without any query parameters) + def path(request) + request.path + end + + # return the request body + # request.body has some limitiations, so we need to concat it back + # into a regular string, which is something puppet can use. + def body(request) + body = '' + request.body.each { |part| body += part } + body + end + + def extract_client_info(request) + result = {} + result[:ip] = request.ip + + # if we find SSL info in the headers, use them to get a hostname. + # try this with :ssl_client_header, which defaults should work for + # Apache with StdEnvVars. + if dn = request.env[Puppet[:ssl_client_header]] and dn_matchdata = dn.match(/^.*?CN\s*=\s*(.*)/) + result[:node] = dn_matchdata[1].to_str + result[:authenticated] = (request.env[Puppet[:ssl_client_verify_header]] == 'SUCCESS') + else + result[:node] = resolve_node(result) + result[:authenticated] = false end - # Return the query params for this request. - def params(request) - result = decode_params(request.params) - result.merge(extract_client_info(request)) - end - - # what path was requested? (this is, without any query parameters) - def path(request) - request.path - end - - # return the request body - # request.body has some limitiations, so we need to concat it back - # into a regular string, which is something puppet can use. - def body(request) - body = '' - request.body.each { |part| body += part } - body - end - - def extract_client_info(request) - result = {} - result[:ip] = request.ip - - # if we find SSL info in the headers, use them to get a hostname. - # try this with :ssl_client_header, which defaults should work for - # Apache with StdEnvVars. - if dn = request.env[Puppet[:ssl_client_header]] and dn_matchdata = dn.match(/^.*?CN\s*=\s*(.*)/) - result[:node] = dn_matchdata[1].to_str - result[:authenticated] = (request.env[Puppet[:ssl_client_verify_header]] == 'SUCCESS') - else - result[:node] = resolve_node(result) - result[:authenticated] = false - end - - result - end + result + end end diff --git a/lib/puppet/network/http/rack/xmlrpc.rb b/lib/puppet/network/http/rack/xmlrpc.rb index c3209a686..f75342783 100644 --- a/lib/puppet/network/http/rack/xmlrpc.rb +++ b/lib/puppet/network/http/rack/xmlrpc.rb @@ -3,63 +3,63 @@ require 'puppet/network/xmlrpc/server' require 'resolv' class Puppet::Network::HTTP::RackXMLRPC < Puppet::Network::HTTP::RackHttpHandler - def initialize(handlers) - @xmlrpc_server = Puppet::Network::XMLRPCServer.new - handlers.each do |name| - Puppet.debug " -> register xmlrpc namespace #{name}" - unless handler = Puppet::Network::Handler.handler(name) - raise ArgumentError, "Invalid XMLRPC handler #{name}" - end - @xmlrpc_server.add_handler(handler.interface, handler.new({})) - end - super() + def initialize(handlers) + @xmlrpc_server = Puppet::Network::XMLRPCServer.new + handlers.each do |name| + Puppet.debug " -> register xmlrpc namespace #{name}" + unless handler = Puppet::Network::Handler.handler(name) + raise ArgumentError, "Invalid XMLRPC handler #{name}" + end + @xmlrpc_server.add_handler(handler.interface, handler.new({})) end + super() + end - def process(request, response) - # errors are sent as text/plain - response['Content-Type'] = 'text/plain' - if not request.post? - response.status = 405 - response.write 'Method Not Allowed' - return - end - if request.media_type != "text/xml" - response.status = 400 - response.write 'Bad Request' - return - end + def process(request, response) + # errors are sent as text/plain + response['Content-Type'] = 'text/plain' + if not request.post? + response.status = 405 + response.write 'Method Not Allowed' + return + end + if request.media_type != "text/xml" + response.status = 400 + response.write 'Bad Request' + return + end - # get auth/certificate data - client_request = build_client_request(request) + # get auth/certificate data + client_request = build_client_request(request) - response_body = @xmlrpc_server.process(request.body.read, client_request) + response_body = @xmlrpc_server.process(request.body.read, client_request) - response.status = 200 - response['Content-Type'] = 'text/xml; charset=utf-8' - response.write response_body - end + response.status = 200 + response['Content-Type'] = 'text/xml; charset=utf-8' + response.write response_body + end - def build_client_request(request) - ip = request.ip + def build_client_request(request) + ip = request.ip - # if we find SSL info in the headers, use them to get a hostname. - # try this with :ssl_client_header, which defaults should work for - # Apache with StdEnvVars. - if dn = request.env[Puppet[:ssl_client_header]] and dn_matchdata = dn.match(/^.*?CN\s*=\s*(.*)/) - node = dn_matchdata[1].to_str - authenticated = (request.env[Puppet[:ssl_client_verify_header]] == 'SUCCESS') - else - begin - node = Resolv.getname(ip) - rescue => detail - Puppet.err "Could not resolve #{ip}: #{detail}" - node = "unknown" - end - authenticated = false - end - - Puppet::Network::ClientRequest.new(node, ip, authenticated) + # if we find SSL info in the headers, use them to get a hostname. + # try this with :ssl_client_header, which defaults should work for + # Apache with StdEnvVars. + if dn = request.env[Puppet[:ssl_client_header]] and dn_matchdata = dn.match(/^.*?CN\s*=\s*(.*)/) + node = dn_matchdata[1].to_str + authenticated = (request.env[Puppet[:ssl_client_verify_header]] == 'SUCCESS') + else + begin + node = Resolv.getname(ip) + rescue => detail + Puppet.err "Could not resolve #{ip}: #{detail}" + node = "unknown" + end + authenticated = false end + Puppet::Network::ClientRequest.new(node, ip, authenticated) + end + end |
