diff options
author | Luke Kanies <luke@madstop.com> | 2008-04-01 18:24:46 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-04-15 21:34:06 -0500 |
commit | c98ad25403dbb27289048513af48d0b3e1723b18 (patch) | |
tree | 15a544c0666d276fc645ccd9ff45d3d76f2f3b8a /lib/puppet | |
parent | d184b3539db2e857b8df424171a1beed4560a035 (diff) | |
download | puppet-c98ad25403dbb27289048513af48d0b3e1723b18.tar.gz puppet-c98ad25403dbb27289048513af48d0b3e1723b18.tar.xz puppet-c98ad25403dbb27289048513af48d0b3e1723b18.zip |
Adding a :search method to the ssl_file terminus type
and the SSL::Host class.
Diffstat (limited to 'lib/puppet')
-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) |