Sha256: 16fadb56538b47d1291d852726f221ada6b21e8338e33e8cbc125970014ff0f4

Contents?: true

Size: 1.56 KB

Versions: 50

Compression:

Stored size: 1.56 KB

Contents

require 'puppet/ssl'
require 'puppet/ssl/certificate'

# Keep track of all of our known certificates.
class Puppet::SSL::Inventory
  attr_reader :path

  # Add a certificate to our inventory.
  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 our certificate for output.
  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

  def initialize
    @path = Puppet[:cert_inventory]
  end

  # Rebuild the inventory from scratch.  This should happen if
  # the file is entirely missing or if it's somehow corrupted.
  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

  # Find the serial number for a given certificate.
  def serial(name)
    Puppet.deprecation_warning 'Inventory#serial is deprecated, use Inventory#serials instead.'
    return nil unless Puppet::FileSystem.exist?(@path)
    serials(name).first
  end

  # Find all serial numbers for a given certificate. If none can be found, returns
  # an empty array.
  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

end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
puppet-retrospec-0.12.2 vendor/gems/puppet-3.7.3/lib/puppet/ssl/inventory.rb
puppet-3.8.7 lib/puppet/ssl/inventory.rb
puppet-3.8.7-x86-mingw32 lib/puppet/ssl/inventory.rb
puppet-3.8.7-x64-mingw32 lib/puppet/ssl/inventory.rb
puppet-3.8.6 lib/puppet/ssl/inventory.rb
puppet-3.8.6-x86-mingw32 lib/puppet/ssl/inventory.rb
puppet-retrospec-0.12.1 vendor/gems/puppet-3.7.3/lib/puppet/ssl/inventory.rb
puppet-3.8.6-x64-mingw32 lib/puppet/ssl/inventory.rb
puppet-retrospec-0.12.0 vendor/gems/puppet-3.7.3/lib/puppet/ssl/inventory.rb
puppet-3.8.5 lib/puppet/ssl/inventory.rb
puppet-3.8.5-x86-mingw32 lib/puppet/ssl/inventory.rb
puppet-3.8.5-x64-mingw32 lib/puppet/ssl/inventory.rb
puppet-3.8.4 lib/puppet/ssl/inventory.rb
puppet-3.8.4-x86-mingw32 lib/puppet/ssl/inventory.rb
puppet-3.8.4-x64-mingw32 lib/puppet/ssl/inventory.rb
puppet-retrospec-0.11.0 vendor/gems/puppet-3.7.3/lib/puppet/ssl/inventory.rb
puppet-retrospec-0.10.0 vendor/gems/puppet-3.7.3/lib/puppet/ssl/inventory.rb
puppet-retrospec-0.9.1 vendor/gems/puppet-3.7.3/lib/puppet/ssl/inventory.rb
puppet-retrospec-0.9.0 vendor/gems/puppet-3.7.3/lib/puppet/ssl/inventory.rb
puppet-retrospec-0.8.1 vendor/gems/puppet-3.7.3/lib/puppet/ssl/inventory.rb