mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 01:04:12 +02:00
ActionController: get api from endpoint object
This commit is contained in:
parent
402b4c31e2
commit
e33d548d1b
@ -7,9 +7,8 @@ use Icinga\Data\Paginatable;
|
|||||||
use Icinga\Exception\AuthenticationException;
|
use Icinga\Exception\AuthenticationException;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
use Icinga\Exception\NotFoundError;
|
use Icinga\Exception\NotFoundError;
|
||||||
use Icinga\Module\Director\Core\RestApiClient;
|
|
||||||
use Icinga\Module\Director\Core\CoreApi;
|
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
|
use Icinga\Module\Director\Objects\IcingaEndpoint;
|
||||||
use Icinga\Module\Director\Web\Form\FormLoader;
|
use Icinga\Module\Director\Web\Form\FormLoader;
|
||||||
use Icinga\Module\Director\Web\Table\TableLoader;
|
use Icinga\Module\Director\Web\Table\TableLoader;
|
||||||
use Icinga\Web\Controller;
|
use Icinga\Web\Controller;
|
||||||
@ -21,6 +20,8 @@ abstract class ActionController extends Controller
|
|||||||
|
|
||||||
protected $isApified = false;
|
protected $isApified = false;
|
||||||
|
|
||||||
|
private $api;
|
||||||
|
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
if ($this->getRequest()->isApiRequest()) {
|
if ($this->getRequest()->isApiRequest()) {
|
||||||
@ -122,13 +123,19 @@ abstract class ActionController extends Controller
|
|||||||
return $this->view->tabs;
|
return $this->view->tabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function api()
|
protected function api($endpointName = null)
|
||||||
{
|
{
|
||||||
$apiconfig = $this->Config()->getSection('api');
|
if ($this->api === null) {
|
||||||
$client = new RestApiClient($apiconfig->get('address'), $apiconfig->get('port'));
|
if ($endpointName === null) {
|
||||||
$client->setCredentials($apiconfig->get('username'), $apiconfig->get('password'));
|
$endpoint = $this->db()->getDeploymentEndpoint();
|
||||||
$api = new CoreApi($client);
|
} else {
|
||||||
return $api;
|
$endpoint = IcingaEndpoint::load($endpointName, $this->db());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->api = $endpoint->api();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->api;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function db()
|
protected function db()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user