summaryrefslogtreecommitdiffstats
path: root/lib/puppet/sslcertificates
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/sslcertificates
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/sslcertificates')
-rw-r--r--lib/puppet/sslcertificates/ca.rb26
-rw-r--r--lib/puppet/sslcertificates/certificate.rb2
-rw-r--r--lib/puppet/sslcertificates/support.rb18
3 files changed, 23 insertions, 23 deletions
diff --git a/lib/puppet/sslcertificates/ca.rb b/lib/puppet/sslcertificates/ca.rb
index 5f32dd0a4..c2ed7349f 100644
--- a/lib/puppet/sslcertificates/ca.rb
+++ b/lib/puppet/sslcertificates/ca.rb
@@ -21,13 +21,13 @@ class Puppet::SSLCertificates::CA
if FileTest.exists?(file)
begin
if Puppet[:name] == "cert"
- puts "Removing %s" % file
+ puts "Removing #{file}"
else
- Puppet.info "Removing %s" % file
+ Puppet.info "Removing #{file}"
end
File.unlink(file)
rescue => detail
- raise Puppet::Error, "Could not delete %s: %s" % [file, detail]
+ raise Puppet::Error, "Could not delete #{file}: #{detail}"
end
end
@@ -57,8 +57,8 @@ class Puppet::SSLCertificates::CA
if Puppet[:capass]
if FileTest.exists?(Puppet[:capass])
- #puts "Reading %s" % Puppet[:capass]
- #system "ls -al %s" % Puppet[:capass]
+ #puts "Reading #{Puppet[:capass]}"
+ #system "ls -al #{Puppet[:capass]}"
#File.read Puppet[:capass]
@config[:password] = self.getpass
else
@@ -96,7 +96,7 @@ class Puppet::SSLCertificates::CA
if @config[:capass] and File.readable?(@config[:capass])
return File.read(@config[:capass])
else
- raise Puppet::Error, "Could not decrypt CA key with password: %s" % detail
+ raise Puppet::Error, "Could not decrypt CA key with password: #{detail}"
end
end
@@ -156,7 +156,7 @@ class Puppet::SSLCertificates::CA
# Make the root cert's name the FQDN of the host running the CA.
name = Facter["hostname"].value
if domain = Facter["domain"].value
- name += "." + domain
+ name += ".#{domain}"
end
cert = Certificate.new(
@@ -187,7 +187,7 @@ class Puppet::SSLCertificates::CA
def removeclientcsr(host)
csrfile = host2csrfile(host)
unless File.exists?(csrfile)
- raise Puppet::Error, "No certificate request for %s" % host
+ raise Puppet::Error, "No certificate request for #{host}"
end
File.unlink(csrfile)
@@ -227,12 +227,12 @@ class Puppet::SSLCertificates::CA
end
if hash.length > 0
- raise ArgumentError, "Unknown parameters %s" % hash.keys.join(",")
+ raise ArgumentError, "Unknown parameters #{hash.keys.join(",")}"
end
[:cadir, :csrdir, :signeddir].each { |dir|
unless @config[dir]
- raise Puppet::DevError, "%s is undefined" % dir
+ raise Puppet::DevError, "#{dir} is undefined"
end
}
end
@@ -241,7 +241,7 @@ class Puppet::SSLCertificates::CA
def sign(csr)
unless csr.is_a?(OpenSSL::X509::Request)
raise Puppet::Error,
- "CA#sign only accepts OpenSSL::X509::Request objects, not %s" % csr.class
+ "CA#sign only accepts OpenSSL::X509::Request objects, not #{csr.class}"
end
unless csr.verify(csr.public_key)
@@ -283,7 +283,7 @@ class Puppet::SSLCertificates::CA
csrfile = host2csrfile(host)
if File.exists?(csrfile)
- raise Puppet::Error, "Certificate request for %s already exists" % host
+ raise Puppet::Error, "Certificate request for #{host} already exists"
end
Puppet.settings.writesub(:csrdir, csrfile) do |f|
@@ -297,7 +297,7 @@ class Puppet::SSLCertificates::CA
certfile = host2certfile(host)
if File.exists?(certfile)
- Puppet.notice "Overwriting signed certificate %s for %s" % [certfile, host]
+ Puppet.notice "Overwriting signed certificate #{certfile} for #{host}"
end
Puppet::SSLCertificates::Inventory::add(cert)
diff --git a/lib/puppet/sslcertificates/certificate.rb b/lib/puppet/sslcertificates/certificate.rb
index d1acc1269..8df7605d7 100644
--- a/lib/puppet/sslcertificates/certificate.rb
+++ b/lib/puppet/sslcertificates/certificate.rb
@@ -106,7 +106,7 @@ class Puppet::SSLCertificates::Certificate
case hash[:type]
when :ca, :client, :server; @type = hash[:type]
else
- raise "Invalid Cert type %s" % hash[:type]
+ raise "Invalid Cert type #{hash[:type]}"
end
else
@type = :client
diff --git a/lib/puppet/sslcertificates/support.rb b/lib/puppet/sslcertificates/support.rb
index 6fa220f24..fc40d3538 100644
--- a/lib/puppet/sslcertificates/support.rb
+++ b/lib/puppet/sslcertificates/support.rb
@@ -10,10 +10,10 @@ module Puppet::SSLCertificates::Support
# Some metaprogramming to create methods for retrieving and creating keys.
# This probably isn't fewer lines than defining each separately...
def self.keytype(name, options, &block)
- var = "@%s" % name
+ var = "@#{name}"
- maker = "mk_%s" % name
- reader = "read_%s" % name
+ maker = "mk_#{name}"
+ reader = "read_#{name}"
unless param = options[:param]
raise ArgumentError, "You must specify the parameter for the key"
@@ -33,7 +33,7 @@ module Puppet::SSLCertificates::Support
begin
instance_variable_set(var, klass.new(File.read(Puppet[param])))
rescue => detail
- raise InvalidCertificate, "Could not read %s: %s" % [param, detail]
+ raise InvalidCertificate, "Could not read #{param}: #{detail}"
end
end
@@ -53,7 +53,7 @@ module Puppet::SSLCertificates::Support
# The key pair.
keytype :key, :param => :hostprivkey, :class => OpenSSL::PKey::RSA do
- Puppet.info "Creating a new SSL key at %s" % Puppet[:hostprivkey]
+ Puppet.info "Creating a new SSL key at #{Puppet[:hostprivkey]}"
key = OpenSSL::PKey::RSA.new(Puppet[:keylength])
# Our key meta programming can only handle one file, so we have
@@ -66,7 +66,7 @@ module Puppet::SSLCertificates::Support
# Our certificate request
keytype :csr, :param => :hostcsr, :class => OpenSSL::X509::Request do
- Puppet.info "Creating a new certificate request for %s" % Puppet[:certname]
+ Puppet.info "Creating a new certificate request for #{Puppet[:certname]}"
csr = OpenSSL::X509::Request.new
csr.version = 0
@@ -95,7 +95,7 @@ module Puppet::SSLCertificates::Support
if Puppet[:trace]
puts detail.backtrace
end
- raise Puppet::Error.new("Certificate retrieval failed: %s" % detail)
+ raise Puppet::Error.new("Certificate retrieval failed: #{detail}")
end
if cert.nil? or cert == ""
@@ -111,7 +111,7 @@ module Puppet::SSLCertificates::Support
retrieved = true
rescue => detail
raise Puppet::Error.new(
- "Invalid certificate: %s" % detail
+ "Invalid certificate: #{detail}"
)
end
@@ -142,7 +142,7 @@ module Puppet::SSLCertificates::Support
full_file = File.join(dir, real_file)
- Puppet.notice "Fixing case in %s; renaming to %s" % [full_file, file]
+ Puppet.notice "Fixing case in #{full_file}; renaming to #{file}"
File.rename(full_file, file)
return true