3 # Resource:: ssl_certificate
5 # Copyright 2017, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
20 default_action :create
22 property :name, String
23 property :domains, [String, Array], :required => true
24 property :fallback_certificate, String
27 node.default[:letsencrypt][:certificates][name] = {
28 :domains => Array(domains)
32 certificate = letsencrypt["certificate"]
33 key = letsencrypt["key"]
37 file "/etc/ssl/certs/#{name}.pem" do
43 manage_symlink_source false
47 file "/etc/ssl/private/#{name}.key" do
53 manage_symlink_source false
56 elsif fallback_certificate
57 link "/etc/ssl/certs/#{name}.pem" do
58 to "#{fallback_certificate}.pem"
61 link "/etc/ssl/private/#{name}.key" do
62 to "#{fallback_certificate}.key"
65 template "/tmp/#{name}.ssl.cnf" do
71 variables :domains => Array(new_resource.domains)
73 ::File.exist?("/etc/ssl/certs/#{new_resource.name}.pem") && ::File.exist?("/etc/ssl/private/#{new_resource.name}.key")
77 execute "/etc/ssl/certs/#{name}.pem" do
78 command "openssl req -x509 -newkey rsa:2048 -keyout /etc/ssl/private/#{new_resource.name}.key -out /etc/ssl/certs/#{new_resource.name}.pem -days 365 -nodes -config /tmp/#{new_resource.name}.ssl.cnf"
82 ::File.exist?("/etc/ssl/certs/#{new_resource.name}.pem") && ::File.exist?("/etc/ssl/private/#{new_resource.name}.key")
89 file "/etc/ssl/certs/#{name}.pem" do
93 file "/etc/ssl/private/#{name}.key" do
99 @letsencrypt ||= search(:letsencrypt, "id:#{name}").first