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/new deployment hook #2790

Open
wants to merge 2 commits 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
4 changes: 3 additions & 1 deletion library/Director/Core/CoreApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions library/Director/Hook/BeforeStoreIcingaObjectHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Icinga\Module\Director\Hook;

abstract class BeforeStoreIcingaObjectHook
{
/**
* The method manipulates the IcingaObject
*
* @param $object
*/
public static function manipulateIcingaObject($object){

}
}
11 changes: 11 additions & 0 deletions library/Director/Hook/DeploymentHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions library/Director/Objects/IcingaObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Icinga\Module\Director\CustomVariable\CustomVariables;
use Icinga\Module\Director\Data\Db\DbDataFormatter;
use Icinga\Module\Director\Data\Db\DbObjectTypeRegistry;
use Icinga\Module\Director\Hook\BeforeStoreIcingaObjectHook;
use Icinga\Module\Director\IcingaConfig\AssignRenderer;
use Icinga\Module\Director\Data\Db\DbObject;
use Icinga\Module\Director\Db\Cache\PrefetchCache;
Expand All @@ -21,6 +22,7 @@
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1;
use Icinga\Module\Director\Repository\IcingaTemplateRepository;
use Icinga\Web\Hook;
use LogicException;
use RuntimeException;

Expand Down Expand Up @@ -1560,6 +1562,12 @@ protected function storeRelatedObjects()
*/
protected function beforeStore()
{
/** @var BeforeStoreIcingaObjectHook[] $hooks */
$hooks = Hook::all('director/BeforeStoreIcingaObject');
foreach ($hooks as $hook) {
$hook::manipulateIcingaObject($this);
}

$this->resolveUnresolvedRelatedProperties();
if ($this->gotImports()) {
$this->imports()->getObjects();
Expand Down