Skip to content

Commit

Permalink
Feature: Certbot plugin Apache
Browse files Browse the repository at this point in the history
It was strange to me that the module mentions the apache plugin, but
has no installation of said plugin anywhere.

In the meantime i used standalone and did an ugly cron pre/post combo
But this should address the issue properly

* adds the plugin class 'apache'
* adds python2 package names for old EL7 distro's
* includes green tests.
  • Loading branch information
NeatNerdPrime committed Sep 9, 2024
1 parent e6acdf5 commit e9180cc
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 0 deletions.
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

0 comments on commit e9180cc

Please sign in to comment.