Relocate Backend classes

This commit is contained in:
Sukhwinder Dhillon 2023-11-17 12:56:07 +01:00
parent 9baa3c4341
commit 604667ca65
6 changed files with 17 additions and 17 deletions

View File

@ -1,10 +1,10 @@
<?php
namespace Icinga\Module\Director\Backend;
namespace Icinga\Module\Director\Integration;
use Icinga\Web\Url;
interface MonitorBackend
interface BackendInterface
{
public function isAvailable(): bool;

View File

@ -1,10 +1,11 @@
<?php
namespace Icinga\Module\Director\Backend;
namespace Icinga\Module\Director\Integration\Icingadb;
use gipfl\IcingaWeb2\Link;
use Icinga\Application\Icinga;
use Icinga\Data\Filter\Filter as DataFilter;
use Icinga\Module\Director\Integration\BackendInterface;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Common\Database;
@ -14,7 +15,7 @@ use Icinga\Module\Icingadb\Redis\VolatileStateResults;
use Icinga\Web\Url;
use ipl\Stdlib\Filter;
class MonitorBackendIcingadb implements MonitorBackend
class IcingadbBackend implements BackendInterface
{
use Database;
use Auth;

View File

@ -10,11 +10,11 @@ use Icinga\Exception\ConfigurationError;
use Icinga\Module\Director\Auth\MonitoringRestriction;
use Icinga\Module\Director\Auth\Permission;
use Icinga\Module\Director\Auth\Restriction;
use Icinga\Module\Director\Backend\MonitorBackend;
use Icinga\Module\Director\Integration\BackendInterface;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Web\Url;
class Monitoring implements MonitorBackend
class Monitoring implements BackendInterface
{
/** @var ?MonitoringBackend */
protected $backend;

View File

@ -4,8 +4,8 @@ namespace Icinga\Module\Director\ProvidedHook\Icingadb;
use Exception;
use Icinga\Application\Config;
use Icinga\Module\Director\Backend\MonitorBackendIcingadb;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\Integration\Icingadb\IcingadbBackend;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Util;
use Icinga\Module\Icingadb\Hook\HostActionsHook;
@ -44,7 +44,7 @@ class HostActions extends HostActionsHook
$allowEdit = true;
}
if (Util::hasPermission('director/monitoring/hosts')) {
$backend = new MonitorBackendIcingadb();
$backend = new IcingadbBackend();
if ($backend->isAvailable() && $backend->canModifyHost($hostname)) {
$allowEdit = IcingaHost::exists($hostname, $db);
}

View File

@ -4,8 +4,8 @@ namespace Icinga\Module\Director\ProvidedHook\Icingadb;
use Exception;
use Icinga\Application\Config;
use Icinga\Module\Director\Backend\MonitorBackendIcingadb;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\Integration\Icingadb\IcingadbBackend;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Util;
use Icinga\Module\Icingadb\Hook\ServiceActionsHook;
@ -56,7 +56,7 @@ class ServiceActions extends ServiceActionsHook
if (Util::hasPermission('director/hosts')) {
$title = mt('director', 'Modify');
} elseif (Util::hasPermission('director/monitoring/services')) {
$backend = new MonitorBackendIcingadb();
$backend = new IcingadbBackend();
if ($backend->isAvailable()
&& $backend->canModifyService($hostname, $serviceName)
) {

View File

@ -4,13 +4,12 @@ namespace Icinga\Module\Director\Web\Controller;
use gipfl\Translation\StaticTranslator;
use Icinga\Application\Benchmark;
use Icinga\Application\Icinga;
use Icinga\Application\Modules\Module;
use Icinga\Data\Paginatable;
use Icinga\Exception\NotFoundError;
use Icinga\Exception\ProgrammingError;
use Icinga\Module\Director\Backend\MonitorBackend;
use Icinga\Module\Director\Backend\MonitorBackendIcingadb;
use Icinga\Module\Director\Integration\Icingadb\IcingadbBackend;
use Icinga\Module\Director\Integration\BackendInterface;
use Icinga\Module\Director\Integration\MonitoringModule\Monitoring;
use Icinga\Module\Director\Web\Controller\Extension\CoreApi;
use Icinga\Module\Director\Web\Controller\Extension\DirectorDb;
@ -40,7 +39,7 @@ abstract class ActionController extends Controller implements ControlsAndContent
/** @var UrlParams Hint for IDE, somehow does not work in web */
protected $params;
/** @var MonitorBackend */
/** @var BackendInterface */
private $backend;
/**
@ -244,13 +243,13 @@ abstract class ActionController extends Controller implements ControlsAndContent
}
/**
* @return MonitorBackend
* @return BackendInterface
*/
protected function backend()
protected function backend(): BackendInterface
{
if ($this->backend === null) {
if (Module::exists('icingadb')) {
$this->backend = new MonitorBackendIcingadb();
$this->backend = new IcingadbBackend();
} else {
$this->backend = new Monitoring($this->Auth());
}