Skip to content

Commit

Permalink
compatibility with certificate cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
rmoriz committed Apr 14, 2017
1 parent 2b1edbc commit 7422d76
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions resources/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@
end

data = {
'id' => cn,
'alt_names' => alt_names,
'id' => cn,
'alt_names' => alt_names,
'created_by' => node['fqdn'],
'created_at' => Time.now
}

# 'key', 'cert', 'chain' are also used in the data bag format used by
# https://github.com/atomic-penguin/cookbook-certificate/blob/master/providers/manage.rb
data['key'] = ::File.read(new_resource.key) if new_resource.key
data['crt'] = ::File.read(new_resource.crt) if new_resource.crt
data['cert'] = ::File.read(new_resource.crt) if new_resource.crt
data['chain'] = ::File.read(new_resource.chain) if new_resource.chain
data['fullchain'] = ::File.read(new_resource.fullchain) if new_resource.fullchain

data['created_by'] = node['fqdn']
data['created_at'] = Time.now
data['fullchain'] = ::File.read(new_resource.fullchain) if new_resource.fullchain

chef_data_bag_item "#{data_bag_name}/#{cn}" do
raw_data data
Expand Down Expand Up @@ -89,7 +91,7 @@ def self_signed?(cert)
end

def item_newer?(item, existing_cert)
item_cert = ::OpenSSL::X509::Certificate.new item['crt'] if item['crt']
item_cert = ::OpenSSL::X509::Certificate.new item['cert'] if item['cert']
item_cert ||= ::OpenSSL::X509::Certificate.new item['fullchain'] if item['fullchain']
item_cert.not_before > existing_cert.not_before
rescue OpenSSL::X509::CertificateError => e
Expand All @@ -112,10 +114,10 @@ def render_to_files(item)
owner new_resource.owner
group new_resource.group
mode 00644
content item['crt']
content item['cert']
action :create

only_if { !!item['crt'] }
only_if { !!item['cert'] }
end

file "acme_store: #{new_resource.cn} SSL fullchain" do
Expand Down

0 comments on commit 7422d76

Please sign in to comment.