Class: ChefSSL::Client::IssuedCertificate
- Inherits:
-
Object
- Object
- ChefSSL::Client::IssuedCertificate
- Defined in:
- lib/chef-ssl/client/issued_certificate.rb
Constant Summary collapse
- DATABAG =
"certificates"
Instance Method Summary collapse
-
#initialize(req, cert, ca = nil) ⇒ IssuedCertificate
constructor
A new instance of IssuedCertificate.
- #issuer ⇒ Object
- #not_after ⇒ Object
- #save! ⇒ Object
- #sha1_fingerprint ⇒ Object
- #subject ⇒ Object
- #to_pem ⇒ Object
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
#issuer ⇒ Object
27 28 29 |
# File 'lib/chef-ssl/client/issued_certificate.rb', line 27 def issuer @cert.issuer.to_s end |
#not_after ⇒ Object
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.) end end |
#sha1_fingerprint ⇒ Object
19 20 21 |
# File 'lib/chef-ssl/client/issued_certificate.rb', line 19 def sha1_fingerprint @cert.sha1_fingerprint end |
#subject ⇒ Object
23 24 25 |
# File 'lib/chef-ssl/client/issued_certificate.rb', line 23 def subject @cert.subject.to_s end |
#to_pem ⇒ Object
15 16 17 |
# File 'lib/chef-ssl/client/issued_certificate.rb', line 15 def to_pem @cert.to_pem end |