Class: ChefSSL::Client::IssuedCertificate

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-ssl/client/issued_certificate.rb

Constant Summary collapse

DATABAG =
"certificates"

Instance Method Summary collapse

Constructor Details

#initialize(req, cert, ca = nil) ⇒ IssuedCertificate

Returns a new instance of IssuedCertificate.



9
10
11
12
13
# File 'lib/chef-ssl/client/issued_certificate.rb', line 9

def initialize(req, cert, ca=nil)
  @ca = ca
  @req = req
  @cert = cert
end

Instance Method Details

#issuerObject



27
28
29
# File 'lib/chef-ssl/client/issued_certificate.rb', line 27

def issuer
  @cert.issuer.to_s
end

#not_afterObject



31
32
33
# File 'lib/chef-ssl/client/issued_certificate.rb', line 31

def not_after
  @cert.not_after
end

#save!Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/chef-ssl/client/issued_certificate.rb', line 35

def save!
  begin
    Spice.create_data_bag(DATABAG)
  rescue Spice::Error::Conflict
    nil
  end

  data = {
    :name => DATABAG,
    :id => @req.id,
    :dn => @req.subject,
    :ca => @req.ca,
    :csr => @req.to_pem,
    :key => @req.key,
    :type => @req.type,
    :date => Time.now.to_s,
    :not_after => @cert.not_after,
    :not_before => @cert.not_before,
    :host => @req.host,
    :certificate => @cert.to_pem
  }
  unless @ca.nil?
    data[:cacert] = @ca.certificate.to_pem
  end

  begin
    ret = Spice.create_data_bag_item(DATABAG, data)
  rescue Spice::Error::Conflict
    raise CertSaveFailed.new("Conflict - certificate data bag exists for #{@req.subject}, id #{@req.id}")
  rescue Spice::Error::ClientError => e
    raise CertSaveFailed.new(e.message)
  end
end

#sha1_fingerprintObject



19
20
21
# File 'lib/chef-ssl/client/issued_certificate.rb', line 19

def sha1_fingerprint
  @cert.sha1_fingerprint
end

#subjectObject



23
24
25
# File 'lib/chef-ssl/client/issued_certificate.rb', line 23

def subject
  @cert.subject.to_s
end

#to_pemObject



15
16
17
# File 'lib/chef-ssl/client/issued_certificate.rb', line 15

def to_pem
  @cert.to_pem
end