diff options
| author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:06:06 -0700 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:06:06 -0700 |
| commit | 81e283b28cdd91d259e3b60687aee7ea66e9d05d (patch) | |
| tree | e3c7b6e4b41cc219f75a3ae7d1294652ead6f268 /lib/puppet/network/http_server | |
| parent | e8cf06336b64491a2dd7538a06651e0caaf6a48d (diff) | |
| download | puppet-81e283b28cdd91d259e3b60687aee7ea66e9d05d.tar.gz puppet-81e283b28cdd91d259e3b60687aee7ea66e9d05d.tar.xz puppet-81e283b28cdd91d259e3b60687aee7ea66e9d05d.zip | |
Code smell: Line modifiers are preferred to one-line blocks.
* Replaced 6 occurances of (while .*?) *do$ with
The do is unneeded in the block header form and causes problems
with the block-to-one-line transformation.
3 Examples:
The code:
while line = f.gets do
becomes:
while line = f.gets
The code:
while line = shadow.gets do
becomes:
while line = shadow.gets
The code:
while wrapper = zeros.pop do
becomes:
while wrapper = zeros.pop
* Replaced 19 occurances of ((if|unless) .*?) *then$ with
The then is unneeded in the block header form and causes problems
with the block-to-one-line transformation.
3 Examples:
The code:
if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then
becomes:
if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) }
The code:
unless defined?(@spec_command) then
becomes:
unless defined?(@spec_command)
The code:
if c == ?\n then
becomes:
if c == ?\n
* Replaced 758 occurances of
((?:if|unless|while|until) .*)
(.*)
end
with
The one-line form is preferable provided:
* The condition is not used to assign a variable
* The body line is not already modified
* The resulting line is not too long
3 Examples:
The code:
if Puppet.features.libshadow?
has_feature :manages_passwords
end
becomes:
has_feature :manages_passwords if Puppet.features.libshadow?
The code:
unless (defined?(@current_pool) and @current_pool)
@current_pool = process_zpool_data(get_pool_data)
end
becomes:
@current_pool = process_zpool_data(get_pool_data) unless (defined?(@current_pool) and @current_pool)
The code:
if Puppet[:trace]
puts detail.backtrace
end
becomes:
puts detail.backtrace if Puppet[:trace]
Diffstat (limited to 'lib/puppet/network/http_server')
| -rw-r--r-- | lib/puppet/network/http_server/mongrel.rb | 8 | ||||
| -rw-r--r-- | lib/puppet/network/http_server/webrick.rb | 16 |
2 files changed, 8 insertions, 16 deletions
diff --git a/lib/puppet/network/http_server/mongrel.rb b/lib/puppet/network/http_server/mongrel.rb index b26eee602..23ab40bb0 100644 --- a/lib/puppet/network/http_server/mongrel.rb +++ b/lib/puppet/network/http_server/mongrel.rb @@ -75,27 +75,27 @@ module Puppet::Network def process(request, response) # Make sure this has been a POST as required for XMLRPC. request_method = request.params[Mongrel::Const::REQUEST_METHOD] || Mongrel::Const::GET - if request_method != "POST" then + if request_method != "POST" response.start(405) { |head, out| out.write("Method Not Allowed") } return end # Make sure the user has sent text/xml data. request_mime = request.params["CONTENT_TYPE"] || "text/plain" - if parse_content_type(request_mime).first != "text/xml" then + if parse_content_type(request_mime).first != "text/xml" response.start(400) { |head, out| out.write("Bad Request") } return end # Make sure there is data in the body at all. length = request.params[Mongrel::Const::CONTENT_LENGTH].to_i - if length <= 0 then + if length <= 0 response.start(411) { |head, out| out.write("Length Required") } return end # Check the body to be valid. - if request.body.nil? or request.body.size != length then + if request.body.nil? or request.body.size != length response.start(400) { |head, out| out.write("Bad Request") } return end diff --git a/lib/puppet/network/http_server/webrick.rb b/lib/puppet/network/http_server/webrick.rb index 6cf5c91fe..df7a87bf2 100644 --- a/lib/puppet/network/http_server/webrick.rb +++ b/lib/puppet/network/http_server/webrick.rb @@ -29,9 +29,7 @@ module Puppet store = OpenSSL::X509::Store.new store.purpose = OpenSSL::X509::PURPOSE_ANY store.flags = OpenSSL::X509::V_FLAG_CRL_CHECK_ALL|OpenSSL::X509::V_FLAG_CRL_CHECK if Puppet.settings[:certificate_revocation] - unless self.ca_cert - raise Puppet::Error, "Could not find CA certificate" - end + raise Puppet::Error, "Could not find CA certificate" unless self.ca_cert store.add_file(Puppet[:localcacert]) store.add_crl(crl) @@ -57,9 +55,7 @@ module Puppet file_io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) args << file_io - if Puppet[:debug] - args << WEBrick::Log::DEBUG - end + args << WEBrick::Log::DEBUG if Puppet[:debug] log = WEBrick::Log.new(*args) @@ -115,16 +111,12 @@ module Puppet # Create a ca client to set up our cert for us. def request_cert(ca) client = Puppet::Network::Client.ca.new(:CA => ca) - unless client.request_cert - raise Puppet::Error, "Could get certificate" - end + raise Puppet::Error, "Could get certificate" unless client.request_cert end # Create all of our handler instances. def setup_handlers(handlers) - unless handlers.is_a?(Hash) - raise ServerError, "Handlers must have arguments" - end + raise ServerError, "Handlers must have arguments" unless handlers.is_a?(Hash) handlers.collect { |handler, args| hclass = nil |
