ServiceFinder: optional Auth

Hint: not required on CLI
This commit is contained in:
Thomas Gelf 2022-07-11 10:06:48 +02:00
parent 4a4e540700
commit b4c05738ae
1 changed files with 6 additions and 2 deletions

View File

@ -6,13 +6,14 @@ use gipfl\IcingaWeb2\Url;
use Icinga\Authentication\Auth;
use Icinga\Module\Director\Objects\HostApplyMatches;
use Icinga\Module\Director\Objects\IcingaHost;
use RuntimeException;
class ServiceFinder
{
/** @var IcingaHost */
protected $host;
/** @var Auth */
/** @var ?Auth */
protected $auth;
/** @var IcingaHost[] */
@ -24,7 +25,7 @@ class ServiceFinder
/** @var \Icinga\Module\Director\Db */
protected $db;
public function __construct(IcingaHost $host, Auth $auth)
public function __construct(IcingaHost $host, Auth $auth = null)
{
$this->host = $host;
$this->auth = $auth;
@ -55,6 +56,9 @@ class ServiceFinder
*/
public function getRedirectionUrl($serviceName)
{
if ($this->auth === null) {
throw new RuntimeException('Auth is required for ServiceFinder when dealing when asking for URLs');
}
if ($this->auth->hasPermission('director/host')) {
if ($info = $this::find($this->host, $serviceName)) {
return $info->getUrl();