Class: Puppet::SSL::CertificateFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/ssl/certificate_factory.rb

Overview

The tedious class that does all the manipulations to the certificate to correctly sign it. Yay.

Constant Summary collapse

UNITMAP =

How we convert from various units to the required seconds.

{
  "y" => 365 * 24 * 60 * 60,
  "d" => 24 * 60 * 60,
  "h" => 60 * 60,
  "s" => 1
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cert_type, csr, issuer, serial) ⇒ CertificateFactory

Returns a new instance of CertificateFactory.



16
17
18
19
20
# File 'lib/puppet/ssl/certificate_factory.rb', line 16

def initialize(cert_type, csr, issuer, serial)
  @cert_type, @csr, @issuer, @serial = cert_type, csr, issuer, serial

  @name = @csr.subject
end

Instance Attribute Details

#cert_typeObject (readonly)

Returns the value of attribute cert_type.



14
15
16
# File 'lib/puppet/ssl/certificate_factory.rb', line 14

def cert_type
  @cert_type
end

#csrObject (readonly)

Returns the value of attribute csr.



14
15
16
# File 'lib/puppet/ssl/certificate_factory.rb', line 14

def csr
  @csr
end

#issuerObject (readonly)

Returns the value of attribute issuer.



14
15
16
# File 'lib/puppet/ssl/certificate_factory.rb', line 14

def issuer
  @issuer
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/puppet/ssl/certificate_factory.rb', line 14

def name
  @name
end

#serialObject (readonly)

Returns the value of attribute serial.



14
15
16
# File 'lib/puppet/ssl/certificate_factory.rb', line 14

def serial
  @serial
end

Instance Method Details

#resultObject

Actually generate our certificate.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/puppet/ssl/certificate_factory.rb', line 23

def result
  @cert = OpenSSL::X509::Certificate.new

  @cert.version = 2 # X509v3
  @cert.subject = @csr.subject
  @cert.issuer = @issuer.subject
  @cert.public_key = @csr.public_key
  @cert.serial = @serial

  build_extensions

  set_ttl

  @cert
end