diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-11-08 05:22:24 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-11-08 05:22:24 +0000 |
| commit | 744ded30a02883dd8ce5fbf2b847f10acb226d6e (patch) | |
| tree | d962b7b21f3a5d20dafd8e7f862c23a2449c2c9b /lib/puppet/sslcertificates/inventory.rb | |
| parent | dc4d98091a5566be289830839f1d6eb39367b42c (diff) | |
| download | puppet-744ded30a02883dd8ce5fbf2b847f10acb226d6e.tar.gz puppet-744ded30a02883dd8ce5fbf2b847f10acb226d6e.tar.xz puppet-744ded30a02883dd8ce5fbf2b847f10acb226d6e.zip | |
Merging the code over from the oscar branch. I will now be doing all development in the trunk again, except for larger changes, which will still get their own branch. This is a merge of the changes from revision 1826 to revision 1834.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1835 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/sslcertificates/inventory.rb')
| -rw-r--r-- | lib/puppet/sslcertificates/inventory.rb | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/lib/puppet/sslcertificates/inventory.rb b/lib/puppet/sslcertificates/inventory.rb index 4dbf60410..045780a69 100644 --- a/lib/puppet/sslcertificates/inventory.rb +++ b/lib/puppet/sslcertificates/inventory.rb @@ -3,48 +3,51 @@ module Puppet::SSLCertificates module Inventory + Puppet.config.setdefaults(:ca, + :cert_inventory => { + :default => "$cadir/inventory.txt", + :mode => 0644, + :owner => "$user", + :group => "$group", + :desc => "A Complete listing of all certificates" + } + ) + # Add CERT to the inventory of issued certs in '$cadir/inventory.txt' # If no inventory exists yet, build an inventory and list all the # certificates that have been signed so far - def Inventory.add(cert) - f = open - format(f, cert) - f.close() - end + def self.add(cert) + unless FileTest.exists?(Puppet[:cert_inventory]) + inited = false + end - def Inventory.filename - File::join(Puppet[:cadir], "inventory.txt") + Puppet.config.write(:cert_inventory, "a") do |f| + unless inited + f.puts self.init + end + f.puts format(cert) + end end private - def Inventory.open - if File::exist?(filename) - File::open(filename, "a") - else - init - end - end - def Inventory.init - if File::exist?(filename) - raise Puppet::Error, - "Inventory file #{filename} already exists" - end - inv = File.open(filename, "w") - inv.puts "# Inventory of signed certificates" - inv.puts "# SERIAL NOT_BEFORE _NOT_AFTER SUBJECT" + def self.init + inv = "# Inventory of signed certificates\n" + inv += "# SERIAL NOT_BEFORE NOT_AFTER SUBJECT\n" Dir.glob(File::join(Puppet[:signeddir], "*.pem")) do |f| - format(inv, OpenSSL::X509::Certificate.new(File::read(f))) + inv += format(OpenSSL::X509::Certificate.new(File::read(f))) + "\n" end return inv end - def Inventory.format(f, cert) + def self.format(cert) iso = '%Y-%m-%dT%H:%M:%S%Z' - f.puts "0x%04x %s %s %s" % [cert.serial, + return "0x%04x %s %s %s" % [cert.serial, cert.not_before.strftime(iso), cert.not_after.strftime(iso), cert.subject] end end end + +# $Id$ |
