From 0d589dcf3dc16d01be335f34e17705a31d749c42 Mon Sep 17 00:00:00 2001 From: MoreAmazingNick Date: Thu, 24 Aug 2023 18:12:31 +0200 Subject: [PATCH 1/2] feature/introduce-BeforeStoreIcingaObjectHook --- .../Director/Hook/BeforeStoreIcingaObjectHook.php | 15 +++++++++++++++ library/Director/Objects/IcingaObject.php | 8 ++++++++ 2 files changed, 23 insertions(+) create mode 100644 library/Director/Hook/BeforeStoreIcingaObjectHook.php diff --git a/library/Director/Hook/BeforeStoreIcingaObjectHook.php b/library/Director/Hook/BeforeStoreIcingaObjectHook.php new file mode 100644 index 000000000..04d19ce60 --- /dev/null +++ b/library/Director/Hook/BeforeStoreIcingaObjectHook.php @@ -0,0 +1,15 @@ +resolveUnresolvedRelatedProperties(); if ($this->gotImports()) { $this->imports()->getObjects(); From 7536bd80fbad82d7fb0724bebd689e425f62c550 Mon Sep 17 00:00:00 2001 From: MoreAmazingNick Date: Thu, 24 Aug 2023 18:13:14 +0200 Subject: [PATCH 2/2] feature/introduce-new-deploymenthook-function --- library/Director/Core/CoreApi.php | 4 +++- library/Director/Hook/DeploymentHook.php | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/library/Director/Core/CoreApi.php b/library/Director/Core/CoreApi.php index c12296654..10c527dfa 100644 --- a/library/Director/Core/CoreApi.php +++ b/library/Director/Core/CoreApi.php @@ -845,17 +845,19 @@ public function dumpConfig(IcingaConfig $config, Db $db, $packageName = null) // 'username' => Util::getUsername(), // 'module_name' => $moduleName, )); + $files = $config->getFileContents(); /** @var DeploymentHook[] $hooks */ $hooks = Hook::all('director/Deployment'); foreach ($hooks as $hook) { $hook->beforeDeploy($deployment); + $files = $hook->beforeDump($files); } $this->assertPackageExists($packageName); $response = $this->client()->post('config/stages/' . \rawurlencode($packageName), [ - 'files' => $config->getFileContents() + 'files' => $files ]); $duration = (int) ((microtime(true) - $start) * 1000); diff --git a/library/Director/Hook/DeploymentHook.php b/library/Director/Hook/DeploymentHook.php index c8a834bb3..c1132ab47 100644 --- a/library/Director/Hook/DeploymentHook.php +++ b/library/Director/Hook/DeploymentHook.php @@ -16,6 +16,17 @@ public function beforeDeploy(DirectorDeploymentLog $deployment) { } + /** + * + * Please override this method if you want to change the deployed files before writing them to disk + * + * @param $files + * @return array with $files + */ + public function beforeDump($files){ + return $files; + } + /** * Please override this method if you want to trigger custom actions * on a successful dump of the Icinga configuration