diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/indirector/ssl_file.rb | 12 | ||||
-rw-r--r-- | lib/puppet/ssl/host.rb | 19 |
2 files changed, 31 insertions, 0 deletions
diff --git a/lib/puppet/indirector/ssl_file.rb b/lib/puppet/indirector/ssl_file.rb index 7a1501dbf..17cb0a144 100644 --- a/lib/puppet/indirector/ssl_file.rb +++ b/lib/puppet/indirector/ssl_file.rb @@ -62,6 +62,18 @@ class Puppet::Indirector::SslFile < Puppet::Indirector::Terminus end end + # Search for more than one file. At this point, it just returns + # an instance for every file in the directory. + def search(options = {}) + dir = collection_directory + Dir.entries(dir).reject { |file| file !~ /\.pem$/ }.collect do |file| + name = file.sub(/\.pem$/, '') + result = model.new(name) + result.read(File.join(dir, file)) + result + end + end + private # A demeterish pointer to the collection directory. diff --git a/lib/puppet/ssl/host.rb b/lib/puppet/ssl/host.rb index 0e65d30b1..373ee5003 100644 --- a/lib/puppet/ssl/host.rb +++ b/lib/puppet/ssl/host.rb @@ -17,6 +17,25 @@ class Puppet::SSL::Host attr_reader :name attr_accessor :ca + # Search for more than one host, optionally only specifying + # an interest in hosts with a given file type. + def self.search(options = {}) + classes = [Key, CertificateRequest, Certificate] + if klass = options[:for] + classlist = [klass].flatten + 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| + 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) |