Class: Puppet::SSL::Inventory
Overview
Keep track of all of our known certificates.
Instance Attribute Summary collapse
- #path ⇒ Object readonly
Instance Method Summary collapse
-
#add(cert) ⇒ Object
Add a certificate to our inventory.
-
#format(cert) ⇒ Object
Format our certificate for output.
-
#initialize ⇒ Inventory
constructor
A new instance of Inventory.
-
#rebuild ⇒ Object
Rebuild the inventory from scratch.
-
#serials(name) ⇒ Object
Find all serial numbers for a given certificate.
Constructor Details
Instance Attribute Details
Instance Method Details
#add(cert) ⇒ Object
Add a certificate to our inventory.
9 10 11 12 13 14 |
# File 'lib/puppet/ssl/inventory.rb', line 9 def add(cert) cert = cert.content if cert.is_a?(Puppet::SSL::Certificate) Puppet.settings.setting(:cert_inventory).open("a") do |f| f.print format(cert) end end |
#format(cert) ⇒ Object
Format our certificate for output.
17 18 19 20 |
# File 'lib/puppet/ssl/inventory.rb', line 17 def format(cert) iso = '%Y-%m-%dT%H:%M:%S%Z' "0x%04x %s %s %s\n" % [cert.serial, cert.not_before.strftime(iso), cert.not_after.strftime(iso), cert.subject] end |
#rebuild ⇒ Object
Rebuild the inventory from scratch. This should happen if the file is entirely missing or if it’s somehow corrupted.
28 29 30 31 32 33 34 35 36 |
# File 'lib/puppet/ssl/inventory.rb', line 28 def rebuild Puppet.notice "Rebuilding inventory file" Puppet.settings.setting(:cert_inventory).open('w') do |f| Puppet::SSL::Certificate.indirection.search("*").each do |cert| f.print format(cert.content) end end end |
#serials(name) ⇒ Object
Find all serial numbers for a given certificate. If none can be found, returns an empty array.
40 41 42 43 44 45 46 |
# File 'lib/puppet/ssl/inventory.rb', line 40 def serials(name) return [] unless Puppet::FileSystem.exist?(@path) File.readlines(@path).collect do |line| /^(\S+).+\/CN=#{name}$/.match(line) end.compact.map { |m| Integer(m[1]) } end |