summaryrefslogtreecommitdiffstats
path: root/lib/puppet/network
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/network')
-rw-r--r--lib/puppet/network/authconfig.rb16
-rw-r--r--lib/puppet/network/authorization.rb4
-rwxr-xr-xlib/puppet/network/authstore.rb12
-rw-r--r--lib/puppet/network/client.rb20
-rw-r--r--lib/puppet/network/client/ca.rb4
-rw-r--r--lib/puppet/network/client/report.rb8
-rw-r--r--lib/puppet/network/client/runner.rb4
-rw-r--r--lib/puppet/network/client_request.rb4
-rw-r--r--lib/puppet/network/format.rb4
-rw-r--r--lib/puppet/network/formats.rb4
-rw-r--r--lib/puppet/network/handler.rb4
-rw-r--r--lib/puppet/network/handler/ca.rb8
-rwxr-xr-xlib/puppet/network/handler/filebucket.rb4
-rwxr-xr-xlib/puppet/network/handler/fileserver.rb44
-rw-r--r--lib/puppet/network/handler/master.rb4
-rwxr-xr-xlib/puppet/network/handler/report.rb12
-rw-r--r--lib/puppet/network/http/api/v1.rb4
-rw-r--r--lib/puppet/network/http/mongrel.rb4
-rw-r--r--lib/puppet/network/http/rack/xmlrpc.rb4
-rw-r--r--lib/puppet/network/http/webrick.rb8
-rw-r--r--lib/puppet/network/http/webrick/rest.rb4
-rw-r--r--lib/puppet/network/http_pool.rb4
-rw-r--r--lib/puppet/network/http_server/mongrel.rb8
-rw-r--r--lib/puppet/network/http_server/webrick.rb16
-rw-r--r--lib/puppet/network/rest_authorization.rb4
-rwxr-xr-xlib/puppet/network/rights.rb16
-rw-r--r--lib/puppet/network/server.rb8
-rw-r--r--lib/puppet/network/xmlrpc/client.rb16
-rw-r--r--lib/puppet/network/xmlrpc/processor.rb8
-rw-r--r--lib/puppet/network/xmlrpc/webrick_servlet.rb16
30 files changed, 72 insertions, 204 deletions
diff --git a/lib/puppet/network/authconfig.rb b/lib/puppet/network/authconfig.rb
index 7c3a51743..8c2ad5857 100644
--- a/lib/puppet/network/authconfig.rb
+++ b/lib/puppet/network/authconfig.rb
@@ -6,9 +6,7 @@ module Puppet
class Network::AuthConfig < Puppet::Util::LoadedFile
def self.main
- unless defined?(@main)
- @main = self.new()
- end
+ @main = self.new() unless defined?(@main)
@main
end
@@ -45,18 +43,14 @@ module Puppet
def initialize(file = nil, parsenow = true)
@file = file || Puppet[:authconfig]
- unless @file
- raise Puppet::DevError, "No authconfig file defined"
- end
+ raise Puppet::DevError, "No authconfig file defined" unless @file
return unless self.exists?
super(@file)
@rights = Puppet::Network::Rights.new
@configstamp = @configstatted = nil
@configtimeout = 60
- if parsenow
- read()
- end
+ read() if parsenow
end
# Read the configuration file.
@@ -106,9 +100,7 @@ module Puppet
next
when /^(?:(\[[\w.]+\])|(path)\s+((?:~\s+)?[^ ]+))\s*$/ # "namespace" or "namespace.method" or "path /path" or "path ~ regex"
name = $1
- if $2 == "path"
- name = $3
- end
+ name = $3 if $2 == "path"
name.chomp!
right = newrights.newright(name, count, @file)
when /^\s*(allow|deny|method|environment|auth(?:enticated)?)\s+(.+)$/
diff --git a/lib/puppet/network/authorization.rb b/lib/puppet/network/authorization.rb
index 97db59338..136875392 100644
--- a/lib/puppet/network/authorization.rb
+++ b/lib/puppet/network/authorization.rb
@@ -10,9 +10,7 @@ module Puppet::Network
# Create our config object if necessary. This works even if
# there's no configuration file.
def authconfig
- unless defined?(@authconfig)
- @authconfig = Puppet::Network::AuthConfig.main()
- end
+ @authconfig = Puppet::Network::AuthConfig.main() unless defined?(@authconfig)
@authconfig
end
diff --git a/lib/puppet/network/authstore.rb b/lib/puppet/network/authstore.rb
index dc3451e34..555a5df64 100755
--- a/lib/puppet/network/authstore.rb
+++ b/lib/puppet/network/authstore.rb
@@ -31,9 +31,7 @@ module Puppet
# This is probably unnecessary, and can cause some weirdnesses in
# cases where we're operating over localhost but don't have a real
# IP defined.
- unless name and ip
- raise Puppet::DevError, "Name and IP must be passed to 'allowed?'"
- end
+ raise Puppet::DevError, "Name and IP must be passed to 'allowed?'" unless name and ip
# else, we're networked and such
else
# we're local
@@ -41,9 +39,7 @@ module Puppet
end
# yay insecure overrides
- if globalallow?
- return true
- end
+ return true if globalallow?
if decl = declarations.find { |d| d.match?(name, ip) }
return decl.result
@@ -175,9 +171,7 @@ module Puppet
# Set the declaration type. Either :allow or :deny.
def type=(type)
type = symbolize(type)
- unless [:allow, :deny].include?(type)
- raise ArgumentError, "Invalid declaration type #{type}"
- end
+ raise ArgumentError, "Invalid declaration type #{type}" unless [:allow, :deny].include?(type)
@type = type
end
diff --git a/lib/puppet/network/client.rb b/lib/puppet/network/client.rb
index 7bdde65be..6d8779f5b 100644
--- a/lib/puppet/network/client.rb
+++ b/lib/puppet/network/client.rb
@@ -23,9 +23,7 @@ class Net::HTTP
# JJM: This is a "backport" of sorts to older ruby versions which
# do not have this accessor. See #896 for more information.
- unless Net::HTTP.instance_methods.include? "enable_post_connection_check"
- attr_accessor :enable_post_connection_check
- end
+ attr_accessor :enable_post_connection_check unless Net::HTTP.instance_methods.include? "enable_post_connection_check"
end
# The base class for all of the clients. Many clients just directly
@@ -50,25 +48,19 @@ class Puppet::Network::Client
# Determine what clients look for when being passed an object for local
# client/server stuff. E.g., you could call Client::CA.new(:CA => ca).
def self.drivername
- unless defined?(@drivername)
- @drivername = self.name
- end
+ @drivername = self.name unless defined?(@drivername)
@drivername
end
# Figure out the handler for our client.
def self.handler
- unless defined?(@handler)
- @handler = Puppet::Network::Handler.handler(self.name)
- end
+ @handler = Puppet::Network::Handler.handler(self.name) unless defined?(@handler)
@handler
end
# The class that handles xmlrpc interaction for us.
def self.xmlrpc_client
- unless defined?(@xmlrpc_client)
- @xmlrpc_client = Puppet::Network::XMLRPCClient.handler_class(self.handler)
- end
+ @xmlrpc_client = Puppet::Network::XMLRPCClient.handler_class(self.handler) unless defined?(@xmlrpc_client)
@xmlrpc_client
end
@@ -156,9 +148,7 @@ class Puppet::Network::Client
Puppet.notice "Already in shutdown"
else
self.stopping = true
- if self.respond_to? :running? and self.running?
- Puppet::Util::Storage.store
- end
+ Puppet::Util::Storage.store if self.respond_to? :running? and self.running?
rmpidfile()
end
end
diff --git a/lib/puppet/network/client/ca.rb b/lib/puppet/network/client/ca.rb
index 2b96cd681..1460e4d6e 100644
--- a/lib/puppet/network/client/ca.rb
+++ b/lib/puppet/network/client/ca.rb
@@ -25,9 +25,7 @@ class Puppet::Network::Client::CA < Puppet::Network::Client
begin
cert, cacert = @driver.getcert(csr.to_pem)
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
raise Puppet::Error.new("Certificate retrieval failed: #{detail}")
end
diff --git a/lib/puppet/network/client/report.rb b/lib/puppet/network/client/report.rb
index 9bd61de2e..f4a9cdaa7 100644
--- a/lib/puppet/network/client/report.rb
+++ b/lib/puppet/network/client/report.rb
@@ -2,9 +2,7 @@ class Puppet::Network::Client::Report < Puppet::Network::Client
@handler = Puppet::Network::Handler.handler(:report)
def initialize(hash = {})
- if hash.include?(:Report)
- hash[:Report] = self.class.handler.new
- end
+ hash[:Report] = self.class.handler.new if hash.include?(:Report)
super(hash)
end
@@ -14,9 +12,7 @@ class Puppet::Network::Client::Report < Puppet::Network::Client
def report(transreport)
report = YAML.dump(transreport)
- unless self.local
- report = CGI.escape(report)
- end
+ report = CGI.escape(report) unless self.local
# Now send the report
file = nil
diff --git a/lib/puppet/network/client/runner.rb b/lib/puppet/network/client/runner.rb
index 5806dd343..c6ba328b4 100644
--- a/lib/puppet/network/client/runner.rb
+++ b/lib/puppet/network/client/runner.rb
@@ -2,9 +2,7 @@ class Puppet::Network::Client::Runner < Puppet::Network::Client::ProxyClient
self.mkmethods
def initialize(hash = {})
- if hash.include?(:Runner)
- hash[:Runner] = self.class.handler.new()
- end
+ hash[:Runner] = self.class.handler.new() if hash.include?(:Runner)
super(hash)
end
diff --git a/lib/puppet/network/client_request.rb b/lib/puppet/network/client_request.rb
index 07c974799..f914bad09 100644
--- a/lib/puppet/network/client_request.rb
+++ b/lib/puppet/network/client_request.rb
@@ -12,9 +12,7 @@ module Puppet::Network # :nodoc:
# are responsible for setting the values correctly, but this common
# format makes it possible to check rights.
def call
- unless handler and method
- raise ArgumentError, "Request is not set up; cannot build call"
- end
+ raise ArgumentError, "Request is not set up; cannot build call" unless handler and method
[handler, method].join(".")
end
diff --git a/lib/puppet/network/format.rb b/lib/puppet/network/format.rb
index 59082c72a..fb5a74a1c 100644
--- a/lib/puppet/network/format.rb
+++ b/lib/puppet/network/format.rb
@@ -42,9 +42,7 @@ class Puppet::Network::Format
init_attribute(method, value)
end
- unless @options.empty?
- raise ArgumentError, "Unsupported option(s) #{@options.keys}"
- end
+ raise ArgumentError, "Unsupported option(s) #{@options.keys}" unless @options.empty?
@options = nil
diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb
index dfdb4cc67..2d519aea6 100644
--- a/lib/puppet/network/formats.rb
+++ b/lib/puppet/network/formats.rb
@@ -153,9 +153,7 @@ Puppet::Network::FormatHandler.create(:pson, :mime => "text/pson", :weight => 10
if data.is_a?(Hash) and d = data['data']
data = d
end
- if data.is_a?(klass)
- return data
- end
+ return data if data.is_a?(klass)
klass.from_pson(data)
end
end
diff --git a/lib/puppet/network/handler.rb b/lib/puppet/network/handler.rb
index 3903bdc63..4b741eb0f 100644
--- a/lib/puppet/network/handler.rb
+++ b/lib/puppet/network/handler.rb
@@ -30,9 +30,7 @@ module Puppet::Network
def self.side(side = nil)
if side
side = side.intern if side.is_a?(String)
- unless [:client, :server].include?(side)
- raise ArgumentError, "Invalid side registration '#{side}' for #{self.name}"
- end
+ raise ArgumentError, "Invalid side registration '#{side}' for #{self.name}" unless [:client, :server].include?(side)
@side = side
else
@side ||= :server
diff --git a/lib/puppet/network/handler/ca.rb b/lib/puppet/network/handler/ca.rb
index 8bafb5f9b..c72171d5d 100644
--- a/lib/puppet/network/handler/ca.rb
+++ b/lib/puppet/network/handler/ca.rb
@@ -60,9 +60,7 @@ class Puppet::Network::Handler
def initialize(hash = {})
Puppet.settings.use(:main, :ssl, :ca)
- if hash.include? :autosign
- @autosign = hash[:autosign]
- end
+ @autosign = hash[:autosign] if hash.include? :autosign
@ca = Puppet::SSLCertificates::CA.new(hash)
end
@@ -109,9 +107,7 @@ class Puppet::Network::Handler
return [cert.to_pem, cacert.to_pem]
elsif @ca
if self.autosign?(hostname) or client.nil?
- if client.nil?
- Puppet.info "Signing certificate for CA server"
- end
+ Puppet.info "Signing certificate for CA server" if client.nil?
# okay, we don't have a signed cert
# if we're a CA and autosign is turned on, then go ahead and sign
# the csr and return the results
diff --git a/lib/puppet/network/handler/filebucket.rb b/lib/puppet/network/handler/filebucket.rb
index bea1c85f5..13fee1661 100755
--- a/lib/puppet/network/handler/filebucket.rb
+++ b/lib/puppet/network/handler/filebucket.rb
@@ -26,9 +26,7 @@ class Puppet::Network::Handler # :nodoc:
# Accept a file from a client and store it by md5 sum, returning
# the sum.
def addfile(contents, path, client = nil, clientip = nil)
- if client
- contents = Base64.decode64(contents)
- end
+ contents = Base64.decode64(contents) if client
bucket = Puppet::FileBucket::File.new(contents)
return bucket.save
end
diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb
index 756e74909..cb54ca4e4 100755
--- a/lib/puppet/network/handler/fileserver.rb
+++ b/lib/puppet/network/handler/fileserver.rb
@@ -98,22 +98,16 @@ class Puppet::Network::Handler
@local = false
end
- if hash[:Config] == false
- @noreadconfig = true
- end
+ @noreadconfig = true if hash[:Config] == false
@passed_configuration_path = hash[:Config]
if hash.include?(:Mount)
@passedconfig = true
- unless hash[:Mount].is_a?(Hash)
- raise Puppet::DevError, "Invalid mount hash #{hash[:Mount].inspect}"
- end
+ raise Puppet::DevError, "Invalid mount hash #{hash[:Mount].inspect}" unless hash[:Mount].is_a?(Hash)
hash[:Mount].each { |dir, name|
- if FileTest.exists?(dir)
- self.mount(dir, name)
- end
+ self.mount(dir, name) if FileTest.exists?(dir)
}
self.mount(nil, MODULES)
self.mount(nil, PLUGINS)
@@ -179,9 +173,7 @@ class Puppet::Network::Handler
mount, path = convert(url, client, clientip)
- if client
- mount.info "Sending #{url} to #{client}"
- end
+ mount.info "Sending #{url} to #{client}" if client
unless mount.path_exists?(path, client)
mount.debug "#{mount} reported that #{path} does not exist"
@@ -264,9 +256,7 @@ class Puppet::Network::Handler
return unless configuration
- if check and ! @configuration.changed?
- return
- end
+ return if check and ! @configuration.changed?
newmounts = {}
begin
@@ -279,9 +269,7 @@ class Puppet::Network::Handler
when /^\s*$/; next # skip blank lines
when /\[([-\w]+)\]/
name = $1
- if newmounts.include?(name)
- raise FileServerError, "#{newmounts[name]} is already mounted as #{name} in #{@configuration.file}"
- end
+ raise FileServerError, "#{newmounts[name]} is already mounted as #{name} in #{@configuration.file}" if newmounts.include?(name)
mount = Mount.new(name)
newmounts[name] = mount
when /^\s*(\w+)\s+(.+)$/
@@ -379,9 +367,7 @@ class Puppet::Network::Handler
# We let the check raise an error, so that it can raise an error
# pointing to the specific problem.
newmounts.each { |name, mount|
- unless mount.valid?
- raise FileServerError, "Invalid mount #{name}"
- end
+ raise FileServerError, "Invalid mount #{name}" unless mount.valid?
}
@mounts = newmounts
end
@@ -529,9 +515,7 @@ class Puppet::Network::Handler
end
# This, ah, might be completely redundant
- unless obj[:links] == links
- obj[:links] = links
- end
+ obj[:links] = links unless obj[:links] == links
return obj
end
@@ -572,15 +556,9 @@ class Puppet::Network::Handler
# Mark that we're expandable.
@expandable = true
else
- unless FileTest.exists?(path)
- raise FileServerError, "#{path} does not exist"
- end
- unless FileTest.directory?(path)
- raise FileServerError, "#{path} is not a directory"
- end
- unless FileTest.readable?(path)
- raise FileServerError, "#{path} is not readable"
- end
+ raise FileServerError, "#{path} does not exist" unless FileTest.exists?(path)
+ raise FileServerError, "#{path} is not a directory" unless FileTest.directory?(path)
+ raise FileServerError, "#{path} is not readable" unless FileTest.readable?(path)
@expandable = false
end
@path = path
diff --git a/lib/puppet/network/handler/master.rb b/lib/puppet/network/handler/master.rb
index beb6e4c57..d55046b5b 100644
--- a/lib/puppet/network/handler/master.rb
+++ b/lib/puppet/network/handler/master.rb
@@ -45,9 +45,7 @@ class Puppet::Network::Handler
# This is only used by the cfengine module, or if --loadclasses was
# specified in +puppet+.
- if hash.include?(:Classes)
- args[:Classes] = hash[:Classes]
- end
+ args[:Classes] = hash[:Classes] if hash.include?(:Classes)
end
# Call our various handlers; this handler is getting deprecated.
diff --git a/lib/puppet/network/handler/report.rb b/lib/puppet/network/handler/report.rb
index 9f885518e..50e2fbfea 100755
--- a/lib/puppet/network/handler/report.rb
+++ b/lib/puppet/network/handler/report.rb
@@ -24,18 +24,14 @@ class Puppet::Network::Handler
# Accept a report from a client.
def report(report, client = nil, clientip = nil)
# Unescape the report
- unless @local
- report = CGI.unescape(report)
- end
+ report = CGI.unescape(report) unless @local
Puppet.info "Processing reports #{reports().join(", ")} for #{client}"
begin
process(report)
rescue => detail
Puppet.err "Could not process report for #{client}: #{detail}"
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
end
end
@@ -65,9 +61,7 @@ class Puppet::Network::Handler
newrep.extend(mod)
newrep.process
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
Puppet.err "Report #{name} failed: #{detail}"
end
else
diff --git a/lib/puppet/network/http/api/v1.rb b/lib/puppet/network/http/api/v1.rb
index 25e27c486..347da93a6 100644
--- a/lib/puppet/network/http/api/v1.rb
+++ b/lib/puppet/network/http/api/v1.rb
@@ -39,9 +39,7 @@ module Puppet::Network::HTTP::API::V1
end
def indirection_method(http_method, indirection)
- unless METHOD_MAP[http_method]
- raise ArgumentError, "No support for http method #{http_method}"
- end
+ raise ArgumentError, "No support for http method #{http_method}" unless METHOD_MAP[http_method]
unless method = METHOD_MAP[http_method][plurality(indirection)]
raise ArgumentError, "No support for plural #{http_method} operations"
diff --git a/lib/puppet/network/http/mongrel.rb b/lib/puppet/network/http/mongrel.rb
index 8181600e3..88494eea8 100644
--- a/lib/puppet/network/http/mongrel.rb
+++ b/lib/puppet/network/http/mongrel.rb
@@ -40,9 +40,7 @@ class Puppet::Network::HTTP::Mongrel
klass = class_for_protocol(:rest)
@server.register('/', klass.new(:server => @server))
- if @protocols.include?(:xmlrpc) and ! @xmlrpc_handlers.empty?
- setup_xmlrpc_handlers
- end
+ setup_xmlrpc_handlers if @protocols.include?(:xmlrpc) and ! @xmlrpc_handlers.empty?
end
# Use our existing code to provide the xmlrpc backward compatibility.
diff --git a/lib/puppet/network/http/rack/xmlrpc.rb b/lib/puppet/network/http/rack/xmlrpc.rb
index 49eb6fe49..9192b1d48 100644
--- a/lib/puppet/network/http/rack/xmlrpc.rb
+++ b/lib/puppet/network/http/rack/xmlrpc.rb
@@ -18,12 +18,12 @@ class Puppet::Network::HTTP::RackXMLRPC < Puppet::Network::HTTP::RackHttpHandler
def process(request, response)
# errors are sent as text/plain
response['Content-Type'] = 'text/plain'
- if not request.post? then
+ if not request.post?
response.status = 405
response.write 'Method Not Allowed'
return
end
- if request.media_type() != "text/xml" then
+ if request.media_type() != "text/xml"
response.status = 400
response.write 'Bad Request'
return
diff --git a/lib/puppet/network/http/webrick.rb b/lib/puppet/network/http/webrick.rb
index d0533f7ff..66932ad2c 100644
--- a/lib/puppet/network/http/webrick.rb
+++ b/lib/puppet/network/http/webrick.rb
@@ -105,9 +105,7 @@ class Puppet::Network::HTTP::WEBrick
results[:SSLStartImmediately] = true
results[:SSLEnable] = true
- unless Puppet::SSL::Certificate.find(Puppet::SSL::CA_NAME)
- raise Puppet::Error, "Could not find CA certificate"
- end
+ raise Puppet::Error, "Could not find CA certificate" unless Puppet::SSL::Certificate.find(Puppet::SSL::CA_NAME)
results[:SSLCACertificateFile] = Puppet[:localcacert]
results[:SSLVerifyClient] = OpenSSL::SSL::VERIFY_PEER
@@ -125,9 +123,7 @@ class Puppet::Network::HTTP::WEBrick
@server.mount('/', klass, :this_value_is_apparently_necessary_but_unused)
# And then set up xmlrpc, if configured.
- if @protocols.include?(:xmlrpc) and ! @xmlrpc_handlers.empty?
- @server.mount("/RPC2", xmlrpc_servlet)
- end
+ @server.mount("/RPC2", xmlrpc_servlet) if @protocols.include?(:xmlrpc) and ! @xmlrpc_handlers.empty?
end
# Create our xmlrpc servlet, which provides backward compatibility.
diff --git a/lib/puppet/network/http/webrick/rest.rb b/lib/puppet/network/http/webrick/rest.rb
index 9bfd0ce6a..9a8bf0a83 100644
--- a/lib/puppet/network/http/webrick/rest.rb
+++ b/lib/puppet/network/http/webrick/rest.rb
@@ -52,9 +52,7 @@ class Puppet::Network::HTTP::WEBrickREST < WEBrick::HTTPServlet::AbstractServlet
response.status = status
if status >= 200 and status != 304
response.body = result
- if result.is_a?(File)
- response["content-length"] = result.stat.size
- end
+ response["content-length"] = result.stat.size if result.is_a?(File)
end
response.reason_phrase = result if status < 200 or status >= 300
end
diff --git a/lib/puppet/network/http_pool.rb b/lib/puppet/network/http_pool.rb
index 458fe2c97..2bccba2e8 100644
--- a/lib/puppet/network/http_pool.rb
+++ b/lib/puppet/network/http_pool.rb
@@ -58,9 +58,7 @@ module Puppet::Network::HttpPool
http.cert = ssl_host.certificate.content
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.key = ssl_host.key.content
- if Puppet[:debug]
- http.verify_callback = self.method(:ssl_verify_callback).to_proc
- end
+ http.verify_callback = self.method(:ssl_verify_callback).to_proc if Puppet[:debug]
end
def self.ssl_verify_callback(peer_ok, x509_store_ctx)
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
diff --git a/lib/puppet/network/rest_authorization.rb b/lib/puppet/network/rest_authorization.rb
index 0cf4472f1..3c7c98a21 100644
--- a/lib/puppet/network/rest_authorization.rb
+++ b/lib/puppet/network/rest_authorization.rb
@@ -9,9 +9,7 @@ module Puppet::Network
# Create our config object if necessary. If there's no configuration file
# we install our defaults
def authconfig
- unless defined?(@authconfig)
- @authconfig = Puppet::Network::RestAuthConfig.main
- end
+ @authconfig = Puppet::Network::RestAuthConfig.main unless defined?(@authconfig)
@authconfig
end
diff --git a/lib/puppet/network/rights.rb b/lib/puppet/network/rights.rb
index 57f90727a..509a9231b 100755
--- a/lib/puppet/network/rights.rb
+++ b/lib/puppet/network/rights.rb
@@ -197,27 +197,21 @@ class Rights
def restrict_method(m)
m = m.intern if m.is_a?(String)
- unless ALL.include?(m)
- raise ArgumentError, "'#{m}' is not an allowed value for method directive"
- end
+ raise ArgumentError, "'#{m}' is not an allowed value for method directive" unless ALL.include?(m)
# if we were allowing all methods, then starts from scratch
if @methods === ALL
@methods = []
end
- if @methods.include?(m)
- raise ArgumentError, "'#{m}' is already in the '#{name}' ACL"
- end
+ raise ArgumentError, "'#{m}' is already in the '#{name}' ACL" if @methods.include?(m)
@methods << m
end
def restrict_environment(env)
env = Puppet::Node::Environment.new(env)
- if @environment.include?(env)
- raise ArgumentError, "'#{env}' is already in the '#{name}' ACL"
- end
+ raise ArgumentError, "'#{env}' is already in the '#{name}' ACL" if @environment.include?(env)
@environment << env
end
@@ -255,9 +249,7 @@ class Rights
# * regex path rights are then all queued in file order
def <=>(rhs)
# move namespace rights at front
- if self.acl_type != rhs.acl_type
- return self.acl_type == :name ? -1 : 1
- end
+ return self.acl_type == :name ? -1 : 1 if self.acl_type != rhs.acl_type
# sort by creation order (ie first match appearing in the file will win)
# that is don't sort, in which case the sort algorithm will order in the
diff --git a/lib/puppet/network/server.rb b/lib/puppet/network/server.rb
index eb22e1614..dfc7e1008 100644
--- a/lib/puppet/network/server.rb
+++ b/lib/puppet/network/server.rb
@@ -33,9 +33,7 @@ class Puppet::Network::Server
# don't try to start.
def create_pidfile
Puppet::Util.sync(Puppet[:name]).synchronize(Sync::EX) do
- unless Puppet::Util::Pidlock.new(pidfile).lock
- raise "Could not create PID file: #{pidfile}"
- end
+ raise "Could not create PID file: #{pidfile}" unless Puppet::Util::Pidlock.new(pidfile).lock
end
end
@@ -43,9 +41,7 @@ class Puppet::Network::Server
def remove_pidfile
Puppet::Util.sync(Puppet[:name]).synchronize(Sync::EX) do
locker = Puppet::Util::Pidlock.new(pidfile)
- if locker.locked?
- locker.unlock or Puppet.err "Could not remove PID file #{pidfile}"
- end
+ locker.unlock or Puppet.err "Could not remove PID file #{pidfile}" if locker.locked?
end
end
diff --git a/lib/puppet/network/xmlrpc/client.rb b/lib/puppet/network/xmlrpc/client.rb
index 828b8a77a..86b1fbd0b 100644
--- a/lib/puppet/network/xmlrpc/client.rb
+++ b/lib/puppet/network/xmlrpc/client.rb
@@ -79,9 +79,7 @@ module Puppet::Network
return :retry
end
["certificate verify failed", "hostname was not match", "hostname not match"].each do |str|
- if detail.message.include?(str)
- Puppet.warning "Certificate validation failed; consider using the certname configuration option"
- end
+ Puppet.warning "Certificate validation failed; consider using the certname configuration option" if detail.message.include?(str)
end
raise XMLRPCClientError, "Certificates were not trusted: #{detail}"
end
@@ -104,9 +102,7 @@ module Puppet::Network
return :retry
end
["certificate verify failed", "hostname was not match", "hostname not match"].each do |str|
- if detail.message.include?(str)
- Puppet.warning "Certificate validation failed; consider using the certname configuration option"
- end
+ Puppet.warning "Certificate validation failed; consider using the certname configuration option" if detail.message.include?(str)
end
raise XMLRPCClientError, "Certificates were not trusted: #{detail}"
end
@@ -154,9 +150,7 @@ module Puppet::Network
end
def http
- unless @http
- @http = Puppet::Network::HttpPool.http_instance(host, port, true)
- end
+ @http = Puppet::Network::HttpPool.http_instance(host, port, true) unless @http
@http
end
@@ -196,9 +190,7 @@ module Puppet::Network
# or we've just downloaded certs and we need to create new http instances
# with the certs added.
def recycle_connection
- if http.started?
- http.finish
- end
+ http.finish if http.started?
@http = nil
self.http # force a new one
end
diff --git a/lib/puppet/network/xmlrpc/processor.rb b/lib/puppet/network/xmlrpc/processor.rb
index 14f91d8b4..e016b177b 100644
--- a/lib/puppet/network/xmlrpc/processor.rb
+++ b/lib/puppet/network/xmlrpc/processor.rb
@@ -58,9 +58,7 @@ module Puppet::Network
1, detail.to_s
)
rescue Puppet::Error => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
Puppet.err detail.to_s
error = ::XMLRPC::FaultException.new(
1, detail.to_s
@@ -68,9 +66,7 @@ module Puppet::Network
error.set_backtrace detail.backtrace
raise error
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not call: #{detail}"
error = ::XMLRPC::FaultException.new(1, detail.to_s)
error.set_backtrace detail.backtrace
diff --git a/lib/puppet/network/xmlrpc/webrick_servlet.rb b/lib/puppet/network/xmlrpc/webrick_servlet.rb
index f58286c3a..a3022dbe9 100644
--- a/lib/puppet/network/xmlrpc/webrick_servlet.rb
+++ b/lib/puppet/network/xmlrpc/webrick_servlet.rb
@@ -10,9 +10,7 @@ module Puppet::Network::XMLRPC
# This is a hackish way to avoid an auth message every time we have a
# normal operation
def self.log(msg)
- unless defined?(@logs)
- @logs = {}
- end
+ @logs = {} unless defined?(@logs)
if @logs.include?(msg)
@logs[msg] += 1
else
@@ -51,9 +49,7 @@ module Puppet::Network::XMLRPC
"unsupported method `#{request.request_method}'."
end
- if parse_content_type(request['Content-type']).first != "text/xml"
- raise WEBrick::HTTPStatus::BadRequest
- end
+ raise WEBrick::HTTPStatus::BadRequest if parse_content_type(request['Content-type']).first != "text/xml"
length = (request['Content-length'] || 0).to_i
@@ -61,14 +57,10 @@ module Puppet::Network::XMLRPC
data = request.body
- if data.nil? or data.size != length
- raise WEBrick::HTTPStatus::BadRequest
- end
+ raise WEBrick::HTTPStatus::BadRequest if data.nil? or data.size != length
resp = process(data, client_request(request))
- if resp.nil? or resp.size <= 0
- raise WEBrick::HTTPStatus::InternalServerError
- end
+ raise WEBrick::HTTPStatus::InternalServerError if resp.nil? or resp.size <= 0
response.status = 200
response['Content-Length'] = resp.size