Skip to content

Commit 9756f83

Browse files
authored
Merge pull request #405 from bastelfreak/cleanup
(#396) Add support for adding hooks after cert creation
2 parents a42ea99 + 03a4ca3 commit 9756f83

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

manifests/certonly.pp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@
257257
}
258258
}
259259

260+
# certbot uses --cert-name to generate the file path
261+
$live_path_certname = regsubst($cert_name, '^\*\.', '')
262+
$live_path = "${config_dir}/live/${live_path_certname}/cert.pem"
263+
260264
$hook_args = ['pre', 'post', 'deploy'].map | String $type | {
261265
$commands = getvar("${type}_hook_commands")
262266
if (!empty($commands)) {
@@ -267,17 +271,27 @@
267271
commands => $commands,
268272
before => Exec["letsencrypt certonly ${title}"],
269273
}
274+
# if ensure is set to present, ensure that the hooks exist in the config file for the domain
275+
# this has to happen after the exec, because `certbot certonly` creates the initial config file
276+
# certbot won't update the config. But an update is required if new hooks are added afterwards
277+
#
278+
# we cannot add it to letsencrypt::hook because the defined resource runs before the Exec, not afterwards
279+
ini_setting { "${title}-${type}":
280+
ensure => $ensure,
281+
path => "${config_dir}/renewal/${live_path_certname}.conf",
282+
section => 'renewalparams',
283+
setting => "${type}_hook",
284+
value => $hook_file,
285+
require => Exec["letsencrypt certonly ${title}"],
286+
}
287+
270288
"--${type}-hook \"${hook_file}\""
271289
}
272290
else {
273291
undef
274292
}
275293
}
276294

277-
# certbot uses --cert-name to generate the file path
278-
$live_path_certname = regsubst($cert_name, '^\*\.', '')
279-
$live_path = "${config_dir}/live/${live_path_certname}/cert.pem"
280-
281295
$_command = flatten(
282296
[
283297
$letsencrypt_command,

spec/defines/letsencrypt_certonly_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ class { 'letsencrypt::plugin::dns_linode':
285285
it do
286286
is_expected.to compile.with_all_deps
287287
is_expected.to contain_letsencrypt__hook('foo.example.com-pre').with_hook_file('/etc/letsencrypt/renewal-hooks-puppet/foo.example.com-pre.sh')
288+
is_expected.to contain_ini_setting('foo.example.com-pre')
288289
end
289290
end
290291

@@ -295,6 +296,7 @@ class { 'letsencrypt::plugin::dns_linode':
295296
it do
296297
is_expected.to compile.with_all_deps
297298
is_expected.to contain_letsencrypt__hook('*.example.com-pre').with_hook_file('/etc/letsencrypt/renewal-hooks-puppet/example.com-pre.sh')
299+
is_expected.to contain_ini_setting('*.example.com-pre')
298300
end
299301
end
300302

@@ -305,6 +307,7 @@ class { 'letsencrypt::plugin::dns_linode':
305307
it do
306308
is_expected.to compile.with_all_deps
307309
is_expected.to contain_letsencrypt__hook('foo.example.com-post').with_hook_file('/etc/letsencrypt/renewal-hooks-puppet/foo.example.com-post.sh')
310+
is_expected.to contain_ini_setting('foo.example.com-post')
308311
end
309312
end
310313

@@ -315,6 +318,7 @@ class { 'letsencrypt::plugin::dns_linode':
315318
it do
316319
is_expected.to compile.with_all_deps
317320
is_expected.to contain_letsencrypt__hook('foo.example.com-deploy').with_hook_file('/etc/letsencrypt/renewal-hooks-puppet/foo.example.com-deploy.sh')
321+
is_expected.to contain_ini_setting('foo.example.com-deploy')
318322
end
319323
end
320324
end
@@ -566,6 +570,9 @@ class { 'letsencrypt::plugin::dns_linode':
566570
it { is_expected.to contain_letsencrypt__hook('foo.example.com-pre') }
567571
it { is_expected.to contain_letsencrypt__hook('foo.example.com-post') }
568572
it { is_expected.to contain_letsencrypt__hook('foo.example.com-deploy') }
573+
it { is_expected.to contain_ini_setting('foo.example.com-pre') }
574+
it { is_expected.to contain_ini_setting('foo.example.com-post') }
575+
it { is_expected.to contain_ini_setting('foo.example.com-deploy') }
569576
it { is_expected.to have_letsencrypt__hook_resource_count(3) }
570577
end
571578
end

0 commit comments

Comments
 (0)