mirror of
https://github.com/certbot/certbot.git
synced 2026-08-03 03:41:53 +02:00
add hooks.deploy_hook
This commit is contained in:
+17
-2
@@ -18,6 +18,7 @@ def validate_hooks(config):
|
|||||||
"""Check hook commands are executable."""
|
"""Check hook commands are executable."""
|
||||||
validate_hook(config.pre_hook, "pre")
|
validate_hook(config.pre_hook, "pre")
|
||||||
validate_hook(config.post_hook, "post")
|
validate_hook(config.post_hook, "post")
|
||||||
|
validate_hook(config.deploy_hook, "deploy")
|
||||||
validate_hook(config.renew_hook, "renew")
|
validate_hook(config.renew_hook, "renew")
|
||||||
|
|
||||||
|
|
||||||
@@ -95,16 +96,30 @@ def run_saved_post_hooks():
|
|||||||
_run_hook(cmd)
|
_run_hook(cmd)
|
||||||
|
|
||||||
|
|
||||||
|
def deploy_hook(config, domains, lineage_path):
|
||||||
|
"""Run post-issuance hook if defined.
|
||||||
|
|
||||||
|
:param configuration.NamespaceConfig config: Certbot settings
|
||||||
|
:param domains: domains in the obtained certificate
|
||||||
|
:type domains: `list` of `str`
|
||||||
|
:param str lineage_path: live directory path for the new cert
|
||||||
|
|
||||||
|
"""
|
||||||
|
if config.deploy_hook:
|
||||||
|
renew_hook(config, domains, lineage_path)
|
||||||
|
|
||||||
|
|
||||||
def renew_hook(config, domains, lineage_path):
|
def renew_hook(config, domains, lineage_path):
|
||||||
"""Run post-renewal hook if defined."""
|
"""Run post-renewal hook if defined."""
|
||||||
if config.renew_hook:
|
if config.renew_hook:
|
||||||
if not config.dry_run:
|
if not config.dry_run:
|
||||||
os.environ["RENEWED_DOMAINS"] = " ".join(domains)
|
os.environ["RENEWED_DOMAINS"] = " ".join(domains)
|
||||||
os.environ["RENEWED_LINEAGE"] = lineage_path
|
os.environ["RENEWED_LINEAGE"] = lineage_path
|
||||||
logger.info("Running renew-hook command: %s", config.renew_hook)
|
logger.info("Running deploy-hook command: %s", config.renew_hook)
|
||||||
_run_hook(config.renew_hook)
|
_run_hook(config.renew_hook)
|
||||||
else:
|
else:
|
||||||
logger.warning("Dry run: skipping renewal hook command: %s", config.renew_hook)
|
logger.warning(
|
||||||
|
"Dry run: skipping deploy hook command: %s", config.renew_hook)
|
||||||
|
|
||||||
|
|
||||||
def _run_hook(shell_cmd):
|
def _run_hook(shell_cmd):
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ class HookTest(unittest.TestCase):
|
|||||||
|
|
||||||
@mock.patch('certbot.hooks._prog')
|
@mock.patch('certbot.hooks._prog')
|
||||||
def test_validate_hooks(self, mock_prog):
|
def test_validate_hooks(self, mock_prog):
|
||||||
config = mock.MagicMock(pre_hook="", post_hook="ls -lR", renew_hook="uptime")
|
config = mock.MagicMock(deploy_hook=None, pre_hook="",
|
||||||
|
post_hook="ls -lR", renew_hook="uptime")
|
||||||
hooks.validate_hooks(config)
|
hooks.validate_hooks(config)
|
||||||
self.assertEqual(mock_prog.call_count, 2)
|
self.assertEqual(mock_prog.call_count, 2)
|
||||||
self.assertEqual(mock_prog.call_args_list[1][0][0], 'uptime')
|
self.assertEqual(mock_prog.call_args_list[1][0][0], 'uptime')
|
||||||
|
|||||||
Reference in New Issue
Block a user