summaryrefslogtreecommitdiffstats
path: root/lib/puppet/ssl
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:05:55 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:05:55 -0700
commite8cf06336b64491a2dd7538a06651e0caaf6a48d (patch)
tree9f5d4c83d03fefa54c385462f60875056a58a82c /lib/puppet/ssl
parenteefccf252527dc5b69af5959b0b0e2ddb5c91b74 (diff)
downloadpuppet-e8cf06336b64491a2dd7538a06651e0caaf6a48d.tar.gz
puppet-e8cf06336b64491a2dd7538a06651e0caaf6a48d.tar.xz
puppet-e8cf06336b64491a2dd7538a06651e0caaf6a48d.zip
Code smell: Use string interpolation
* Replaced 83 occurances of (.*)" *[+] *([$@]?[\w_0-9.:]+?)(.to_s\b)?(?! *[*(%\w_0-9.:{\[]) with \1#{\2}" 3 Examples: The code: puts "PUPPET " + status + ": " + process + ", " + state becomes: puts "PUPPET " + status + ": " + process + ", #{state}" The code: puts "PUPPET " + status + ": #{process}" + ", #{state}" becomes: puts "PUPPET #{status}" + ": #{process}" + ", #{state}" The code: }.compact.join( "\n" ) + "\n" + t + "]\n" becomes: }.compact.join( "\n" ) + "\n#{t}" + "]\n" * Replaced 21 occurances of (.*)" *[+] *" with \1 3 Examples: The code: puts "PUPPET #{status}" + ": #{process}" + ", #{state}" becomes: puts "PUPPET #{status}" + ": #{process}, #{state}" The code: puts "PUPPET #{status}" + ": #{process}, #{state}" becomes: puts "PUPPET #{status}: #{process}, #{state}" The code: res = self.class.name + ": #{@name}" + "\n" becomes: res = self.class.name + ": #{@name}\n" * Don't use string concatenation to split lines unless they would be very long. Replaced 11 occurances of (.*)(['"]) *[+] *(['"])(.*) with 3 Examples: The code: o.define_head "The check_puppet Nagios plug-in checks that specified " + "Puppet process is running and the state file is no " + becomes: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " + The code: o.separator "Mandatory arguments to long options are mandatory for " + "short options too." becomes: o.separator "Mandatory arguments to long options are mandatory for short options too." The code: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " + "older than specified interval." becomes: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no older than specified interval." * Replaced no occurances of do (.*?) end with {\1} * Replaced 1488 occurances of "([^"\n]*%s[^"\n]*)" *% *(.+?)(?=$| *\b(do|if|while|until|unless|#)\b) with 20 Examples: The code: args[0].split(/\./).map do |s| "dc=%s"%[s] end.join(",") becomes: args[0].split(/\./).map do |s| "dc=#{s}" end.join(",") The code: puts "%s" % Puppet.version becomes: puts "#{Puppet.version}" The code: raise "Could not find information for %s" % node becomes: raise "Could not find information for #{node}" The code: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] becomes: raise Puppet::Error, "Cannot create #{dir}: basedir #{File.join(path)} is a file" The code: Puppet.err "Could not run %s: %s" % [client_class, detail] becomes: Puppet.err "Could not run #{client_class}: #{detail}" The code: raise "Could not find handler for %s" % arg becomes: raise "Could not find handler for #{arg}" The code: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] becomes: Puppet.err "Will not start without authorization file #{Puppet[:authconfig]}" The code: raise Puppet::Error, "Could not deserialize catalog from pson: %s" % detail becomes: raise Puppet::Error, "Could not deserialize catalog from pson: #{detail}" The code: raise "Could not find facts for %s" % Puppet[:certname] becomes: raise "Could not find facts for #{Puppet[:certname]}" The code: raise ArgumentError, "%s is not readable" % path becomes: raise ArgumentError, "#{path} is not readable" The code: raise ArgumentError, "Invalid handler %s" % name becomes: raise ArgumentError, "Invalid handler #{name}" The code: debug "Executing '%s' in zone %s with '%s'" % [command, @resource[:name], str] becomes: debug "Executing '#{command}' in zone #{@resource[:name]} with '#{str}'" The code: raise Puppet::Error, "unknown cert type '%s'" % hash[:type] becomes: raise Puppet::Error, "unknown cert type '#{hash[:type]}'" The code: Puppet.info "Creating a new certificate request for %s" % Puppet[:certname] becomes: Puppet.info "Creating a new certificate request for #{Puppet[:certname]}" The code: "Cannot create alias %s: object already exists" % [name] becomes: "Cannot create alias #{name}: object already exists" The code: return "replacing from source %s with contents %s" % [metadata.source, metadata.checksum] becomes: return "replacing from source #{metadata.source} with contents #{metadata.checksum}" The code: it "should have a %s parameter" % param do becomes: it "should have a #{param} parameter" do The code: describe "when registring '%s' messages" % log do becomes: describe "when registring '#{log}' messages" do The code: paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration%stest" % l } becomes: paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration#{l}test" } The code: assert_raise(Puppet::Error, "Check '%s' did not fail on false" % check) do becomes: assert_raise(Puppet::Error, "Check '#{check}' did not fail on false") do
Diffstat (limited to 'lib/puppet/ssl')
-rw-r--r--lib/puppet/ssl/base.rb4
-rw-r--r--lib/puppet/ssl/certificate_authority.rb16
-rw-r--r--lib/puppet/ssl/certificate_authority/interface.rb12
-rw-r--r--lib/puppet/ssl/certificate_factory.rb2
-rw-r--r--lib/puppet/ssl/certificate_request.rb4
-rw-r--r--lib/puppet/ssl/certificate_revocation_list.rb2
-rw-r--r--lib/puppet/ssl/host.rb6
-rw-r--r--lib/puppet/ssl/key.rb2
8 files changed, 24 insertions, 24 deletions
diff --git a/lib/puppet/ssl/base.rb b/lib/puppet/ssl/base.rb
index 7452a513d..745d733dc 100644
--- a/lib/puppet/ssl/base.rb
+++ b/lib/puppet/ssl/base.rb
@@ -18,7 +18,7 @@ class Puppet::SSL::Base
end
def self.wrapped_class
- raise(Puppet::DevError, "%s has not declared what class it wraps" % self) unless defined?(@wrapped_class)
+ raise(Puppet::DevError, "#{self} has not declared what class it wraps") unless defined?(@wrapped_class)
@wrapped_class
end
@@ -30,7 +30,7 @@ class Puppet::SSL::Base
end
def generate
- raise Puppet::DevError, "%s did not override 'generate'" % self.class
+ raise Puppet::DevError, "#{self.class} did not override 'generate'"
end
def initialize(name)
diff --git a/lib/puppet/ssl/certificate_authority.rb b/lib/puppet/ssl/certificate_authority.rb
index aa1ccf936..b66725cbf 100644
--- a/lib/puppet/ssl/certificate_authority.rb
+++ b/lib/puppet/ssl/certificate_authority.rb
@@ -78,7 +78,7 @@ class Puppet::SSL::CertificateAuthority
return false if ['false', false].include?(auto)
return true if ['true', true].include?(auto)
- raise ArgumentError, "The autosign configuration '%s' must be a fully qualified file" % auto unless auto =~ /^\//
+ raise ArgumentError, "The autosign configuration '#{auto}' must be a fully qualified file" unless auto =~ /^\//
if FileTest.exist?(auto)
return auto
else
@@ -117,7 +117,7 @@ class Puppet::SSL::CertificateAuthority
# Generate a new certificate.
def generate(name)
- raise ArgumentError, "A Certificate already exists for %s" % name if Puppet::SSL::Certificate.find(name)
+ raise ArgumentError, "A Certificate already exists for #{name}" if Puppet::SSL::Certificate.find(name)
host = Puppet::SSL::Host.new(name)
host.generate_certificate_request
@@ -170,7 +170,7 @@ class Puppet::SSL::CertificateAuthority
begin
Puppet.settings.write(:capass) { |f| f.print pass }
rescue Errno::EACCES => detail
- raise Puppet::Error, "Could not write CA password: %s" % detail.to_s
+ raise Puppet::Error, "Could not write CA password: #{detail}"
end
@password = pass
@@ -228,7 +228,7 @@ class Puppet::SSL::CertificateAuthority
if cert = Puppet::SSL::Certificate.find(name)
serial = cert.content.serial
elsif ! serial = inventory.serial(name)
- raise ArgumentError, "Could not find a serial number for %s" % name
+ raise ArgumentError, "Could not find a serial number for #{name}"
end
crl.revoke(serial, host.key.content)
end
@@ -249,7 +249,7 @@ class Puppet::SSL::CertificateAuthority
issuer = csr.content
else
unless csr = Puppet::SSL::CertificateRequest.find(hostname)
- raise ArgumentError, "Could not find certificate request for %s" % hostname
+ raise ArgumentError, "Could not find certificate request for #{hostname}"
end
issuer = host.certificate.content
end
@@ -258,7 +258,7 @@ class Puppet::SSL::CertificateAuthority
cert.content = Puppet::SSL::CertificateFactory.new(cert_type, csr.content, issuer, next_serial).result
cert.content.sign(host.key.content, OpenSSL::Digest::SHA1.new)
- Puppet.notice "Signed certificate request for %s" % hostname
+ Puppet.notice "Signed certificate request for #{hostname}"
# Add the cert to the inventory before we save it, since
# otherwise we could end up with it being duplicated, if
@@ -278,7 +278,7 @@ class Puppet::SSL::CertificateAuthority
# Verify a given host's certificate.
def verify(name)
unless cert = Puppet::SSL::Certificate.find(name)
- raise ArgumentError, "Could not find a certificate for %s" % name
+ raise ArgumentError, "Could not find a certificate for #{name}"
end
store = OpenSSL::X509::Store.new
store.add_file Puppet[:cacert]
@@ -293,7 +293,7 @@ class Puppet::SSL::CertificateAuthority
def fingerprint(name, md = :MD5)
unless cert = Puppet::SSL::Certificate.find(name) || Puppet::SSL::CertificateRequest.find(name)
- raise ArgumentError, "Could not find a certificate or csr for %s" % name
+ raise ArgumentError, "Could not find a certificate or csr for #{name}"
end
cert.fingerprint(md)
end
diff --git a/lib/puppet/ssl/certificate_authority/interface.rb b/lib/puppet/ssl/certificate_authority/interface.rb
index ffae66d2d..64e983cf6 100644
--- a/lib/puppet/ssl/certificate_authority/interface.rb
+++ b/lib/puppet/ssl/certificate_authority/interface.rb
@@ -14,7 +14,7 @@ module Puppet
# Actually perform the work.
def apply(ca)
unless subjects or method == :list
- raise ArgumentError, "You must provide hosts or :all when using %s" % method
+ raise ArgumentError, "You must provide hosts or :all when using #{method}"
end
begin
@@ -29,7 +29,7 @@ module Puppet
raise
rescue => detail
puts detail.backtrace if Puppet[:trace]
- Puppet.err "Could not call %s: %s" % [method, detail]
+ Puppet.err "Could not call #{method}: #{detail}"
end
end
@@ -84,7 +84,7 @@ module Puppet
# Set the method to apply.
def method=(method)
- raise ArgumentError, "Invalid method %s to apply" % method unless INTERFACE_METHODS.include?(method)
+ raise ArgumentError, "Invalid method #{method} to apply" unless INTERFACE_METHODS.include?(method)
@method = method
end
@@ -94,7 +94,7 @@ module Puppet
if value = ca.print(host)
puts value
else
- Puppet.err "Could not find certificate for %s" % host
+ Puppet.err "Could not find certificate for #{host}"
end
end
end
@@ -105,7 +105,7 @@ module Puppet
if value = ca.fingerprint(host, @digest)
puts "#{host} #{value}"
else
- Puppet.err "Could not find certificate for %s" % host
+ Puppet.err "Could not find certificate for #{host}"
end
end
end
@@ -122,7 +122,7 @@ module Puppet
# Set the list of hosts we're operating on. Also supports keywords.
def subjects=(value)
unless value == :all or value == :signed or value.is_a?(Array)
- raise ArgumentError, "Subjects must be an array or :all; not %s" % value
+ raise ArgumentError, "Subjects must be an array or :all; not #{value}"
end
if value.is_a?(Array) and value.empty?
diff --git a/lib/puppet/ssl/certificate_factory.rb b/lib/puppet/ssl/certificate_factory.rb
index 73b8a54c3..9273bb902 100644
--- a/lib/puppet/ssl/certificate_factory.rb
+++ b/lib/puppet/ssl/certificate_factory.rb
@@ -61,7 +61,7 @@ class Puppet::SSL::CertificateFactory
begin
send(method)
rescue NoMethodError
- raise ArgumentError, "%s is an invalid certificate type" % @cert_type
+ raise ArgumentError, "#{@cert_type} is an invalid certificate type"
end
@extensions << @ef.create_extension("nsComment", "Puppet Ruby/OpenSSL Generated Certificate")
diff --git a/lib/puppet/ssl/certificate_request.rb b/lib/puppet/ssl/certificate_request.rb
index f18fe4a16..3cd3ce0be 100644
--- a/lib/puppet/ssl/certificate_request.rb
+++ b/lib/puppet/ssl/certificate_request.rb
@@ -24,7 +24,7 @@ class Puppet::SSL::CertificateRequest < Puppet::SSL::Base
# How to create a certificate request with our system defaults.
def generate(key)
- Puppet.info "Creating a new SSL certificate request for %s" % name
+ Puppet.info "Creating a new SSL certificate request for #{name}"
# Support either an actual SSL key, or a Puppet key.
key = key.content if key.is_a?(Puppet::SSL::Key)
@@ -40,7 +40,7 @@ class Puppet::SSL::CertificateRequest < Puppet::SSL::Base
csr.public_key = key.public_key
csr.sign(key, OpenSSL::Digest::MD5.new)
- raise Puppet::Error, "CSR sign verification failed; you need to clean the certificate request for %s on the server" % name unless csr.verify(key.public_key)
+ raise Puppet::Error, "CSR sign verification failed; you need to clean the certificate request for #{name} on the server" unless csr.verify(key.public_key)
@content = csr
Puppet.info "Certificate Request fingerprint (md5): #{fingerprint}"
diff --git a/lib/puppet/ssl/certificate_revocation_list.rb b/lib/puppet/ssl/certificate_revocation_list.rb
index c725bde48..b2bff4830 100644
--- a/lib/puppet/ssl/certificate_revocation_list.rb
+++ b/lib/puppet/ssl/certificate_revocation_list.rb
@@ -53,7 +53,7 @@ class Puppet::SSL::CertificateRevocationList < Puppet::SSL::Base
# CA, then write the CRL back to disk. The REASON must be one of the
# OpenSSL::OCSP::REVOKED_* reasons
def revoke(serial, cakey, reason = OpenSSL::OCSP::REVOKED_STATUS_KEYCOMPROMISE)
- Puppet.notice "Revoked certificate with serial %s" % serial
+ Puppet.notice "Revoked certificate with serial #{serial}"
time = Time.now
# Add our revocation to the CRL.
diff --git a/lib/puppet/ssl/host.rb b/lib/puppet/ssl/host.rb
index f367adaca..6d1ae1a16 100644
--- a/lib/puppet/ssl/host.rb
+++ b/lib/puppet/ssl/host.rb
@@ -85,7 +85,7 @@ class Puppet::SSL::Host
# Specify how we expect to interact with our certificate authority.
def self.ca_location=(mode)
- raise ArgumentError, "CA Mode can only be %s" % CA_MODES.collect { |m| m.to_s }.join(", ") unless CA_MODES.include?(mode)
+ raise ArgumentError, "CA Mode can only be #{CA_MODES.collect { |m| m.to_s }.join(", ")}" unless CA_MODES.include?(mode)
@ca_location = mode
@@ -231,7 +231,7 @@ class Puppet::SSL::Host
raise
rescue Exception => detail
puts detail.backtrace if Puppet[:trace]
- Puppet.err "Could not request certificate: %s" % detail.to_s
+ Puppet.err "Could not request certificate: #{detail}"
if time < 1
puts "Exiting; failed to retrieve certificate and waitforcert is disabled"
exit(1)
@@ -253,7 +253,7 @@ class Puppet::SSL::Host
Puppet.notice "Did not receive certificate"
rescue StandardError => detail
puts detail.backtrace if Puppet[:trace]
- Puppet.err "Could not request certificate: %s" % detail.to_s
+ Puppet.err "Could not request certificate: #{detail}"
end
end
end
diff --git a/lib/puppet/ssl/key.rb b/lib/puppet/ssl/key.rb
index d91df03f6..cb03729c1 100644
--- a/lib/puppet/ssl/key.rb
+++ b/lib/puppet/ssl/key.rb
@@ -18,7 +18,7 @@ class Puppet::SSL::Key < Puppet::SSL::Base
# Knows how to create keys with our system defaults.
def generate
- Puppet.info "Creating a new SSL key for %s" % name
+ Puppet.info "Creating a new SSL key for #{name}"
@content = OpenSSL::PKey::RSA.new(Puppet[:keylength].to_i)
end