summaryrefslogtreecommitdiffstats
path: root/lib/puppet/ssl
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-04-16 12:34:53 -0500
committerLuke Kanies <luke@madstop.com>2008-04-16 12:34:53 -0500
commitc19c9d436d4d8ca0a5773065b53348242d237651 (patch)
tree8d676822ba0d372963f14cb3e33b3ddf36cc4316 /lib/puppet/ssl
parent054e4e431a145737c42d767249f1b94685c9a6d7 (diff)
downloadpuppet-c19c9d436d4d8ca0a5773065b53348242d237651.tar.gz
puppet-c19c9d436d4d8ca0a5773065b53348242d237651.tar.xz
puppet-c19c9d436d4d8ca0a5773065b53348242d237651.zip
Removing all the cases where the ssl host specifies
a terminus. Also, getting rid of some metaprogramming that wasn't really helping.
Diffstat (limited to 'lib/puppet/ssl')
-rw-r--r--lib/puppet/ssl/host.rb88
1 files changed, 18 insertions, 70 deletions
diff --git a/lib/puppet/ssl/host.rb b/lib/puppet/ssl/host.rb
index 373ee5003..6f49175aa 100644
--- a/lib/puppet/ssl/host.rb
+++ b/lib/puppet/ssl/host.rb
@@ -19,6 +19,8 @@ class Puppet::SSL::Host
# Search for more than one host, optionally only specifying
# an interest in hosts with a given file type.
+ # This just allows our non-indirected class to have one of
+ # indirection methods.
def self.search(options = {})
classes = [Key, CertificateRequest, Certificate]
if klass = options[:for]
@@ -26,62 +28,35 @@ class Puppet::SSL::Host
else
classlist = [Key, CertificateRequest, Certificate]
end
- args = {}
- args[:in] = options[:in] if options[:in]
# Collect the results from each class, flatten them, collect all of the names, make the name list unique,
# then create a Host instance for each one.
- classlist.collect { |klass| klass.search(args) }.flatten.collect { |r| r.name }.uniq.collect do |name|
+ classlist.collect { |klass| klass.search }.flatten.collect { |r| r.name }.uniq.collect do |name|
new(name)
end
end
- # A bit of metaprogramming that we use to define all of
- # the methods for managing our ssl-related files.
- def self.manage_file(name, &block)
- var = "@%s" % name
-
- maker = "generate_%s" % name
- reader = "read_%s" % name
-
- classname = file2constant(name.to_s)
-
- begin
- klass = const_get(classname)
- rescue
- raise Puppet::DevError, "Cannot map %s to a valid constant" % name
- end
-
- # Define the method that creates it.
- define_method(maker, &block)
-
- # Define the reading method.
- define_method(reader) do
- klass.find(self.name)
- end
-
- # Define the overall method, which just calls the reader and maker
- # as appropriate.
- define_method(name) do
- unless cert = instance_variable_get(var)
- return nil unless cert = send(reader)
- instance_variable_set(var, cert)
- end
- cert.content
- end
+ def key
+ return nil unless (defined?(@key) and @key) or @key = Key.find(name)
+ @key.content
end
# This is the private key; we can create it from scratch
# with no inputs.
- manage_file :key do
+ def generate_key
@key = Key.new(name)
@key.generate
@key.save :in => :file
true
end
+ def certificate_request
+ return nil unless (defined?(@certificate_request) and @certificate_request) or @certificate_request = CertificateRequest.find(name)
+ @certificate_request.content
+ end
+
# Our certificate request requires the key but that's all.
- manage_file :certificate_request do
+ def generate_certificate_request
generate_key unless key
@certificate_request = CertificateRequest.new(name)
@certificate_request.generate(key)
@@ -89,19 +64,11 @@ class Puppet::SSL::Host
return true
end
- # Our certificate itself might not successfully "generate", since
- # that generation is actually accomplished by a CA signing the
- # stored CSR.
- manage_file :certificate do
- generate_certificate_request unless certificate_request
-
- @certificate = Certificate.new(name)
- if @certificate.generate(certificate_request)
- @certificate.save :in => :file
- return true
- else
- return false
- end
+ # There's no ability to generate a certificate -- if we don't have it, then we should be
+ # automatically looking in the ca, and if the ca doesn't have it, we don't have one.
+ def certificate
+ return nil unless (defined?(@certificate) and @certificate) or @certificate = Certificate.find(name)
+ @certificate.content
end
# Is this a ca host, meaning that all of its files go in the CA collections?
@@ -126,23 +93,4 @@ class Puppet::SSL::Host
def public_key
key.public_key
end
-
- # Try to get our signed certificate.
- def retrieve_signed_certificate(source = :ca_file)
- if cert = Puppet::SSL::Certificate.find(name, :in => source)
- @certificate = cert
- @certificate.save :in => :file
- return true
- else
- return false
- end
- end
-
- # Send our CSR to the server, defaulting to the
- # local CA.
- def send_certificate_request(dest = :ca_file)
- raise ArgumentError, "Must generate CSR before sending to server" unless certificate_request
-
- @certificate_request.save :in => dest
- end
end