forked from voxpupuli/puppet-letsencrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request voxpupuli#279 from bkuebler/feature/plugins/dns-cl…
…oudflare Add Cloudflare DNS plugin support
- Loading branch information
Showing
11 changed files
with
276 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
--- | ||
letsencrypt::plugin::dns_rfc2136::package_name: 'python3-certbot-dns-rfc2136' | ||
letsencrypt::plugin::dns_route53::package_name: 'python3-certbot-dns-route53' | ||
letsencrypt::plugin::dns_cloudflare::package_name: 'python3-certbot-dns-cloudflare' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
--- | ||
letsencrypt::plugin::dns_rfc2136::package_name: 'python2-certbot-dns-rfc2136' | ||
letsencrypt::plugin::dns_route53::package_name: 'python2-certbot-dns-route53' | ||
letsencrypt::plugin::dns_cloudflare::package_name: 'python2-certbot-dns-cloudflare' | ||
letsencrypt::plugin::nginx::package_name: 'python2-certbot-nginx' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
--- | ||
letsencrypt::plugin::dns_rfc2136::package_name: 'python2-certbot-dns-rfc2136' | ||
letsencrypt::plugin::dns_route53::package_name: 'python2-certbot-dns-route53' | ||
letsencrypt::plugin::dns_cloudflare::package_name: 'python2-certbot-dns-cloudflare' | ||
letsencrypt::plugin::nginx::package_name: 'python2-certbot-nginx' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# @summary Installs and configures the dns-cloudflare plugin | ||
# | ||
# This class installs and configures the Let's Encrypt dns-cloudflare plugin. | ||
# https://certbot-dns-cloudflare.readthedocs.io | ||
# | ||
# @param package_name The name of the package to install when $manage_package is true. | ||
# @param api_key | ||
# Optional string, cloudflare api key value for authentication. | ||
# @param api_token | ||
# Optional string, cloudflare api token value for authentication. | ||
# @param email | ||
# Optional string, cloudflare account email address, used in conjunction with api_key. | ||
# @param config_dir The path to the configuration directory. | ||
# @param manage_package Manage the plugin package. | ||
# @param propagation_seconds Number of seconds to wait for the DNS server to propagate the DNS-01 challenge. | ||
# | ||
class letsencrypt::plugin::dns_cloudflare ( | ||
Optional[String[1]] $package_name = undef, | ||
Optional[String[1]] $api_key = undef, | ||
Optional[String[1]] $api_token = undef, | ||
Optional[String[1]] $email = undef, | ||
Stdlib::Absolutepath $config_path = "${letsencrypt::config_dir}/dns-cloudflare.ini", | ||
Boolean $manage_package = true, | ||
Integer $propagation_seconds = 10, | ||
) { | ||
require letsencrypt::install | ||
|
||
if ! $api_key and ! $api_token { | ||
fail('No authentication method provided, please specify either api_token or api_key and api_email.') | ||
} | ||
|
||
if $manage_package { | ||
if ! $package_name { | ||
fail('No package name provided for certbot dns cloudflare plugin.') | ||
} | ||
|
||
package { $package_name: | ||
ensure => installed, | ||
} | ||
} | ||
|
||
if $api_token { | ||
$ini_vars = { | ||
dns_cloudflare_api_token => $api_token, | ||
} | ||
} | ||
else { | ||
if ! $email { | ||
fail('Cloudflare email not provided for specified api_key.') | ||
} | ||
|
||
$ini_vars = { | ||
dns_cloudflare_api_key => $api_key, | ||
dns_cloudflare_email => $email, | ||
} | ||
} | ||
|
||
file { $config_path: | ||
ensure => file, | ||
owner => 'root', | ||
group => 'root', | ||
mode => '0400', | ||
content => epp('letsencrypt/ini.epp', { | ||
vars => { '' => $ini_vars }, | ||
}), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper_acceptance' | ||
|
||
describe 'letsencrypt::plugin::dns_cloudflare' do | ||
it_behaves_like 'an idempotent resource' do | ||
let(:manifest) do | ||
<<-PUPPET | ||
class { 'letsencrypt' : | ||
email => '[email protected]', | ||
config => { | ||
'server' => 'https://acme-staging-v02.api.letsencrypt.org/directory', | ||
}, | ||
} | ||
class { 'letsencrypt::plugin::dns_cloudflare': | ||
api_token => 'dummy-cloudflare-api-token', | ||
} | ||
PUPPET | ||
end | ||
end | ||
|
||
describe file('/etc/letsencrypt/dns-cloudflare.ini') do | ||
it { is_expected.to be_file } | ||
it { is_expected.to be_owned_by 'root' } | ||
it { is_expected.to be_grouped_into 'root' } | ||
it { is_expected.to be_mode 400 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'letsencrypt::plugin::dns_cloudflare' do | ||
on_supported_os.each do |os, os_facts| | ||
context "on #{os} based operating systems" do | ||
let(:facts) { os_facts } | ||
let(:params) { { 'api_token' => 'dummy-cloudflare-api-token' } } | ||
let(:pre_condition) do | ||
<<-PUPPET | ||
class { 'letsencrypt': | ||
email => '[email protected]', | ||
} | ||
PUPPET | ||
end | ||
let(:package_name) do | ||
osname = facts[:os]['name'] | ||
osrelease = facts[:os]['release']['major'] | ||
osfull = "#{osname}-#{osrelease}" | ||
if %w[RedHat-7 CentOS-7].include?(osfull) | ||
'python2-certbot-dns-cloudflare' | ||
elsif %w[Debian RedHat].include?(facts[:os]['family']) | ||
'python3-certbot-dns-cloudflare' | ||
elsif %w[FreeBSD].include?(facts[:os]['family']) | ||
'py38-certbot-dns-cloudflare' | ||
end | ||
end | ||
|
||
context 'with required parameters' do | ||
it do | ||
if package_name.nil? | ||
is_expected.not_to compile | ||
else | ||
is_expected.to compile.with_all_deps | ||
end | ||
end | ||
|
||
describe 'with manage_package => true' do | ||
let(:params) { super().merge(manage_package: true) } | ||
|
||
it do | ||
if package_name.nil? | ||
is_expected.not_to compile | ||
else | ||
is_expected.to contain_class('letsencrypt::plugin::dns_cloudflare').with_package_name(package_name) | ||
is_expected.to contain_package(package_name).with_ensure('installed') | ||
end | ||
end | ||
end | ||
|
||
describe 'with manage_package => false' do | ||
let(:params) { super().merge(manage_package: false, package_name: 'dns-cloudflare-package') } | ||
|
||
it { is_expected.not_to contain_package('dns-cloudflare-package') } | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ | |
end | ||
it { is_expected.to contain_exec('initialize letsencrypt') } | ||
it { is_expected.to contain_exec('letsencrypt certonly foo.example.com') } | ||
it { is_expected.to contain_exec('letsencrypt certonly foo.example.com').with_unless "/usr/local/sbin/letsencrypt-domain-validation #{pathprefix}/etc/letsencrypt/live/foo.example.com/cert.pem 'foo.example.com'" } | ||
it { is_expected.to contain_exec('letsencrypt certonly foo.example.com').with_unless(['test ! -f /usr/local/sbin/letsencrypt-domain-validation', "/usr/local/sbin/letsencrypt-domain-validation #{pathprefix}/etc/letsencrypt/live/foo.example.com/cert.pem 'foo.example.com'"]) } | ||
end | ||
|
||
context 'with ensure absent' do | ||
|
@@ -186,6 +186,27 @@ class { 'letsencrypt::plugin::nginx': | |
it { is_expected.to contain_exec('letsencrypt certonly foo.example.com').with_command "letsencrypt --text --agree-tos --non-interactive certonly --rsa-key-size 4096 -a nginx --cert-name 'foo.example.com' -d 'foo.example.com'" } | ||
end | ||
|
||
context 'with dns-cloudflare plugin' do | ||
let(:title) { 'foo.example.com' } | ||
let(:params) { { plugin: 'dns-cloudflare', letsencrypt_command: 'letsencrypt' } } | ||
let(:pre_condition) do | ||
<<-PUPPET | ||
class { 'letsencrypt': | ||
email => '[email protected]', | ||
config_dir => '/etc/letsencrypt', | ||
} | ||
class { 'letsencrypt::plugin::dns_cloudflare': | ||
package_name => 'irrelevant', | ||
api_token => 'dummy-cloudflare-api-token', | ||
} | ||
PUPPET | ||
end | ||
|
||
it { is_expected.to compile.with_all_deps } | ||
it { is_expected.to contain_class('letsencrypt::plugin::dns_cloudflare') } | ||
it { is_expected.to contain_exec('letsencrypt certonly foo.example.com').with_command "letsencrypt --text --agree-tos --non-interactive certonly --rsa-key-size 4096 -a dns-cloudflare --cert-name 'foo.example.com' -d 'foo.example.com' --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/dns-cloudflare.ini --dns-cloudflare-propagation-seconds 10" } | ||
end | ||
|
||
context 'with custom plugin' do | ||
let(:title) { 'foo.example.com' } | ||
let(:params) { { plugin: 'apache' } } | ||
|
@@ -462,7 +483,7 @@ class { 'letsencrypt::plugin::nginx': | |
|
||
it { is_expected.to compile.with_all_deps } | ||
it { is_expected.to contain_file('/foo/bar/baz').with_ensure('directory') } | ||
it { is_expected.to contain_exec('letsencrypt certonly foo.example.com').with_unless '/usr/local/sbin/letsencrypt-domain-validation /foo/bar/baz/live/foo.example.com/cert.pem \'foo.example.com\'' } | ||
it { is_expected.to contain_exec('letsencrypt certonly foo.example.com').with_unless(['test ! -f /usr/local/sbin/letsencrypt-domain-validation', '/usr/local/sbin/letsencrypt-domain-validation /foo/bar/baz/live/foo.example.com/cert.pem \'foo.example.com\'']) } | ||
end | ||
|
||
context 'on FreeBSD', if: facts[:os]['name'] == 'FreeBSD' do | ||
|
@@ -474,7 +495,7 @@ class { 'letsencrypt::plugin::nginx': | |
it { is_expected.to contain_ini_setting('/usr/local/etc/letsencrypt/cli.ini email [email protected]') } | ||
it { is_expected.to contain_ini_setting('/usr/local/etc/letsencrypt/cli.ini server https://acme-v02.api.letsencrypt.org/directory') } | ||
it { is_expected.to contain_file('/usr/local/etc/letsencrypt').with_ensure('directory') } | ||
it { is_expected.to contain_exec('letsencrypt certonly foo.example.com').with_unless '/usr/local/sbin/letsencrypt-domain-validation /usr/local/etc/letsencrypt/live/foo.example.com/cert.pem \'foo.example.com\'' } | ||
it { is_expected.to contain_exec('letsencrypt certonly foo.example.com').with_unless(['test ! -f /usr/local/sbin/letsencrypt-domain-validation', '/usr/local/sbin/letsencrypt-domain-validation /usr/local/etc/letsencrypt/live/foo.example.com/cert.pem \'foo.example.com\'']) } | ||
end | ||
end | ||
end | ||
|