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/ssl | |
| 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/ssl')
| -rw-r--r-- | lib/puppet/ssl/certificate_authority.rb | 24 | ||||
| -rw-r--r-- | lib/puppet/ssl/certificate_authority/interface.rb | 8 | ||||
| -rw-r--r-- | lib/puppet/ssl/host.rb | 2 |
3 files changed, 9 insertions, 25 deletions
diff --git a/lib/puppet/ssl/certificate_authority.rb b/lib/puppet/ssl/certificate_authority.rb index b66725cbf..8a3d0b4d5 100644 --- a/lib/puppet/ssl/certificate_authority.rb +++ b/lib/puppet/ssl/certificate_authority.rb @@ -50,9 +50,7 @@ class Puppet::SSL::CertificateAuthority # Create and run an applicator. I wanted to build an interface where you could do # something like 'ca.apply(:generate).to(:all) but I don't think it's really possible. def apply(method, options) - unless options[:to] - raise ArgumentError, "You must specify the hosts to apply to; valid values are an array or the symbol :all" - end + raise ArgumentError, "You must specify the hosts to apply to; valid values are an array or the symbol :all" unless options[:to] applier = Interface.new(method, options) applier.apply(self) @@ -63,9 +61,7 @@ class Puppet::SSL::CertificateAuthority return unless auto = autosign? store = nil - if auto != true - store = autosign_store(auto) - end + store = autosign_store(auto) if auto != true Puppet::SSL::CertificateRequest.search("*").each do |csr| sign(csr.name) if auto == true or store.allowed?(csr.name, "127.1.1.1") @@ -156,9 +152,7 @@ class Puppet::SSL::CertificateAuthority # Retrieve (or create, if necessary) our inventory manager. def inventory - unless defined?(@inventory) - @inventory = Puppet::SSL::Inventory.new - end + @inventory = Puppet::SSL::Inventory.new unless defined?(@inventory) @inventory end @@ -191,14 +185,10 @@ class Puppet::SSL::CertificateAuthority # This is slightly odd. If the file doesn't exist, our readwritelock creates # it, but with a mode we can't actually read in some cases. So, use # a default before the lock. - unless FileTest.exist?(Puppet[:serial]) - serial = 0x1 - end + serial = 0x1 unless FileTest.exist?(Puppet[:serial]) Puppet.settings.readwritelock(:serial) { |f| - if FileTest.exist?(Puppet[:serial]) - serial ||= File.read(Puppet.settings[:serial]).chomp.hex - end + serial ||= File.read(Puppet.settings[:serial]).chomp.hex if FileTest.exist?(Puppet[:serial]) # We store the next valid serial, not the one we just used. f << "%04X" % (serial + 1) @@ -286,9 +276,7 @@ class Puppet::SSL::CertificateAuthority store.purpose = OpenSSL::X509::PURPOSE_SSL_CLIENT store.flags = OpenSSL::X509::V_FLAG_CRL_CHECK_ALL|OpenSSL::X509::V_FLAG_CRL_CHECK if Puppet.settings[:certificate_revocation] - unless store.verify(cert.content) - raise CertificateVerificationError.new(store.error), store.error_string - end + raise CertificateVerificationError.new(store.error), store.error_string unless store.verify(cert.content) end def fingerprint(name, md = :MD5) diff --git a/lib/puppet/ssl/certificate_authority/interface.rb b/lib/puppet/ssl/certificate_authority/interface.rb index 64e983cf6..e5ede3c6c 100644 --- a/lib/puppet/ssl/certificate_authority/interface.rb +++ b/lib/puppet/ssl/certificate_authority/interface.rb @@ -18,9 +18,7 @@ module Puppet end begin - if respond_to?(method) - return send(method, ca) - end + return send(method, ca) if respond_to?(method) (subjects == :all ? ca.list : subjects).each do |host| ca.send(method, host) @@ -125,9 +123,7 @@ module Puppet raise ArgumentError, "Subjects must be an array or :all; not #{value}" end - if value.is_a?(Array) and value.empty? - value = nil - end + value = nil if value.is_a?(Array) and value.empty? @subjects = value end diff --git a/lib/puppet/ssl/host.rb b/lib/puppet/ssl/host.rb index 6d1ae1a16..2b1db7e42 100644 --- a/lib/puppet/ssl/host.rb +++ b/lib/puppet/ssl/host.rb @@ -246,7 +246,7 @@ class Puppet::SSL::Host exit(1) end - while true do + while true sleep time begin break if certificate |
