From 402b4c31e26bfc4ef1ecb438c2f4d5f2020a8ba0 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 17 Feb 2016 16:39:18 +0100 Subject: [PATCH] IcingaEndpoint: add api user and client helper --- library/Director/Objects/IcingaEndpoint.php | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/library/Director/Objects/IcingaEndpoint.php b/library/Director/Objects/IcingaEndpoint.php index cc4524e8..ba16681e 100644 --- a/library/Director/Objects/IcingaEndpoint.php +++ b/library/Director/Objects/IcingaEndpoint.php @@ -2,6 +2,9 @@ namespace Icinga\Module\Director\Objects; +use Icinga\Module\Director\Core\CoreApi; +use Icinga\Module\Director\Core\RestApiClient; + class IcingaEndpoint extends IcingaObject { protected $table = 'icinga_endpoint'; @@ -25,6 +28,36 @@ class IcingaEndpoint extends IcingaObject 'apiuser' => 'IcingaApiUser', ); + public function hasApiUser() + { + return $this->getResolvedProperty('apiuser_id') !== null; + } + + public function getApiUser() + { + return $this->getRelatedObject( + 'apiuser', + $this->getResolvedProperty('apiuser_id') + ); + } + + public function api() + { + $client = new RestApiClient( + $this->getResolvedProperty('host'), + $this->getResolvedProperty('port') + ); + + $user = $this->getApiUser(); + $client->setCredentials( + // TODO: $user->client_dn, + $user->object_name, + $user->password + ); + + return new CoreApi($client); + } + protected function renderLog_duration() { return $this->renderPropertyAsSeconds('log_duration');