Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Certbot plugin Apache #357

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#### Public Classes

* [`letsencrypt`](#letsencrypt): Install and configure Certbot, the LetsEncrypt client
* [`letsencrypt::plugin::apache`](#letsencrypt--plugin--apache): install and configure the Let's Encrypt apache plugin
* [`letsencrypt::plugin::dns_cloudflare`](#letsencrypt--plugin--dns_cloudflare): Installs and configures the dns-cloudflare plugin
* [`letsencrypt::plugin::dns_rfc2136`](#letsencrypt--plugin--dns_rfc2136): Installs and configures the dns-rfc2136 plugin
* [`letsencrypt::plugin::dns_route53`](#letsencrypt--plugin--dns_route53): Installs and configures the dns-route53 plugin
Expand Down Expand Up @@ -338,6 +339,33 @@ certificate. Two environmental variables are supplied by certbot:

Default value: `[]`

### <a name="letsencrypt--plugin--apache"></a>`letsencrypt::plugin::apache`

install and configure the Let's Encrypt apache plugin

#### Parameters

The following parameters are available in the `letsencrypt::plugin::apache` class:

* [`manage_package`](#-letsencrypt--plugin--apache--manage_package)
* [`package_name`](#-letsencrypt--plugin--apache--package_name)

##### <a name="-letsencrypt--plugin--apache--manage_package"></a>`manage_package`

Data type: `Boolean`

Manage the plugin package.

Default value: `true`

##### <a name="-letsencrypt--plugin--apache--package_name"></a>`package_name`

Data type: `String[1]`

The name of the package to install when $manage_package is true.

Default value: `'python3-certbot-apache'`

### <a name="letsencrypt--plugin--dns_cloudflare"></a>`letsencrypt::plugin::dns_cloudflare`

This class installs and configures the Let's Encrypt dns-cloudflare plugin.
Expand Down
1 change: 1 addition & 0 deletions data/os/CentOS/7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ 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'
letsencrypt::plugin::apache::package_name: 'python2-certbot-apache'
1 change: 1 addition & 0 deletions data/os/RedHat/7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ 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'
letsencrypt::plugin::apache::package_name: 'python2-certbot-apache'
11 changes: 11 additions & 0 deletions manifests/certonly.pp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,17 @@
}
}

'apache': {
require letsencrypt::plugin::apache

if $ensure == 'present' {
$_domains = join($domains, '\' -d \'')
$plugin_args = "--cert-name '${cert_name}' -d '${_domains}'"
} else {
$plugin_args = "--cert-name '${cert_name}'"
}
}

default: {
if $ensure == 'present' {
$_domains = join($domains, '\' -d \'')
Expand Down
16 changes: 16 additions & 0 deletions manifests/plugin/apache.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# @summary install and configure the Let's Encrypt apache plugin
#
# @param manage_package Manage the plugin package.
# @param package_name The name of the package to install when $manage_package is true.
class letsencrypt::plugin::apache (
Boolean $manage_package = true,
String[1] $package_name = 'python3-certbot-apache',
) {
include letsencrypt

if $manage_package {
package { $package_name:
ensure => $letsencrypt::package_ensure,
}
}
}
14 changes: 14 additions & 0 deletions spec/acceptance/letsencrypt_plugin_apache_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'letsencrypt::plugin::apache' do
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
include letsencrypt
include letsencrypt::plugin::apache
PUPPET
end
end
end
41 changes: 41 additions & 0 deletions spec/classes/plugin/apache_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'letsencrypt::plugin::apache' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }
let(:params) { {} }
let(:pre_condition) do
<<-PUPPET
class { 'letsencrypt':
email => 'foo@example.com',
}
PUPPET
end
let(:package_name) do
if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7'
'python2-certbot-apache'
else
'python3-certbot-apache'
end
end

context 'with default parameters' do
it { is_expected.to compile.with_all_deps }

it 'installs the certbot apache plugin' do
is_expected.to contain_class('letsencrypt::plugin::apache')
is_expected.to contain_package(package_name).with_ensure('installed')
end

describe 'with manage_package => false' do
let(:params) { super().merge(manage_package: false, package_name: 'apache-package') }

it { is_expected.not_to contain_package('apache-package') }
end
end
end
end
end
20 changes: 20 additions & 0 deletions spec/defines/letsencrypt_certonly_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,26 @@ 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 apache plugin' do
let(:title) { 'foo.example.com' }
let(:params) { { plugin: 'apache', letsencrypt_command: 'letsencrypt' } }
let(:pre_condition) do
<<-PUPPET
class { 'letsencrypt':
email => 'foo@example.com',
config_dir => '/etc/letsencrypt',
}
class { 'letsencrypt::plugin::apache':
package_name => 'irrelevant',
}
PUPPET
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('letsencrypt::plugin::apache') }
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 apache --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' } }
Expand Down
Loading