IcingadbBackend: Remove isAvailable method and property

As it is only used internally now, it is no more required
This commit is contained in:
Sukhwinder Dhillon 2024-01-16 10:27:10 +01:00
parent 2461724271
commit a850ff13d7
3 changed files with 8 additions and 31 deletions

View File

@ -6,13 +6,6 @@ use Icinga\Web\Url;
interface BackendInterface interface BackendInterface
{ {
/**
* Whether the backend is available
*
* @return bool
*/
public function isAvailable(): bool;
/** /**
* Whether the backend has the given host * Whether the backend has the given host
* *

View File

@ -2,7 +2,6 @@
namespace Icinga\Module\Director\Integration\Icingadb; namespace Icinga\Module\Director\Integration\Icingadb;
use Icinga\Application\Modules\Module;
use Icinga\Module\Director\Auth\Permission; use Icinga\Module\Director\Auth\Permission;
use Icinga\Module\Director\Auth\Restriction; use Icinga\Module\Director\Auth\Restriction;
use Icinga\Module\Director\Integration\BackendInterface; use Icinga\Module\Director\Integration\BackendInterface;
@ -19,22 +18,9 @@ class IcingadbBackend implements BackendInterface
use Database; use Database;
use Auth; use Auth;
/** @var bool */
protected $isAvailable;
public function __construct()
{
$this->isAvailable = Module::exists('icingadb');
}
public function isAvailable(): bool
{
return $this->isAvailable;
}
public function hasHost(?string $hostName): bool public function hasHost(?string $hostName): bool
{ {
if ($hostName === null || ! $this->isAvailable()) { if ($hostName === null) {
return false; return false;
} }
@ -43,7 +29,7 @@ class IcingadbBackend implements BackendInterface
public function hasService(?string $hostName, ?string $serviceName): bool public function hasService(?string $hostName, ?string $serviceName): bool
{ {
if ($hostName === null || $serviceName === null || ! $this->isAvailable()) { if ($hostName === null || $serviceName === null) {
return false; return false;
} }
@ -52,7 +38,7 @@ class IcingadbBackend implements BackendInterface
public function getHostUrl(?string $hostName): ?Url public function getHostUrl(?string $hostName): ?Url
{ {
if ($hostName === null || ! $this->isAvailable()) { if ($hostName === null) {
return null; return null;
} }
@ -62,7 +48,6 @@ class IcingadbBackend implements BackendInterface
public function canModifyHost(?string $hostName): bool public function canModifyHost(?string $hostName): bool
{ {
if ($hostName === null if ($hostName === null
|| ! $this->isAvailable()
|| ! $this->getAuth()->hasPermission(Permission::ICINGADB_HOSTS) || ! $this->getAuth()->hasPermission(Permission::ICINGADB_HOSTS)
) { ) {
return false; return false;
@ -77,7 +62,6 @@ class IcingadbBackend implements BackendInterface
{ {
if ($hostName === null if ($hostName === null
|| $serviceName === null || $serviceName === null
|| ! $this->isAvailable()
|| ! $this->getAuth()->hasPermission(Permission::ICINGADB_SERVICES) || ! $this->getAuth()->hasPermission(Permission::ICINGADB_SERVICES)
) { ) {
return false; return false;

View File

@ -28,11 +28,6 @@ class Monitoring implements BackendInterface
$this->initializeMonitoringBackend(); $this->initializeMonitoringBackend();
} }
public function isAvailable(): bool
{
return $this->backend !== null;
}
public function getHostUrl(?string $hostName): ?Url public function getHostUrl(?string $hostName): ?Url
{ {
if ($hostName === null) { if ($hostName === null) {
@ -197,4 +192,9 @@ class Monitoring implements BackendInterface
} }
} }
} }
protected function isAvailable(): bool
{
return $this->backend !== null;
}
} }