ActionController: provide api to all controllers

This commit is contained in:
Thomas Gelf 2015-10-20 22:47:06 +02:00
parent c4e5e9dd9c
commit 29206188bf
4 changed files with 10 additions and 33 deletions

View File

@ -2,8 +2,6 @@
namespace Icinga\Module\Director\Controllers;
use Icinga\Module\Director\Core\CoreApi;
use Icinga\Module\Director\Core\RestApiClient;
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
use Icinga\Module\Director\Util;
use Icinga\Module\Director\Web\Controller\ActionController;
@ -61,13 +59,4 @@ class ConfigController extends ActionController
array('checksum' => $config->getHexChecksum()))
);
}
protected function api()
{
$apiconfig = $this->Config()->getSection('api');
$client = new RestApiClient($apiconfig->get('address'), $apiconfig->get('port'));
$client->setCredentials($apiconfig->get('username'), $apiconfig->get('password'));
$api = new CoreApi($client);
return $api;
}
}

View File

@ -3,8 +3,6 @@
namespace Icinga\Module\Director\Controllers;
use Icinga\Module\Director\Web\Controller\ActionController;
use Icinga\Module\Director\Core\RestApiClient;
use Icinga\Module\Director\Core\CoreApi;
class InspectController extends ActionController
{
@ -51,13 +49,4 @@ class InspectController extends ActionController
$this->view->status = $status = $this->api()->getStatus();
print_r($status); exit;
}
protected function api()
{
$apiconfig = $this->Config()->getSection('api');
$client = new RestApiClient($apiconfig->get('address'), $apiconfig->get('port'));
$client->setCredentials($apiconfig->get('username'), $apiconfig->get('password'));
$api = new CoreApi($client);
return $api;
}
}

View File

@ -3,8 +3,6 @@
namespace Icinga\Module\Director\Controllers;
use Icinga\Module\Director\Web\Controller\ActionController;
use Icinga\Module\Director\Core\RestApiClient;
use Icinga\Module\Director\Core\CoreApi;
use Exception;
class ListController extends ActionController
@ -184,15 +182,6 @@ class ListController extends ActionController
}
}
protected function api()
{
$apiconfig = $this->Config()->getSection('api');
$client = new RestApiClient($apiconfig->get('address'), $apiconfig->get('port'));
$client->setCredentials($apiconfig->get('username'), $apiconfig->get('password'));
$api = new CoreApi($client);
return $api;
}
protected function prepareTable($name)
{
$table = $this->loadTable($name)->setConnection($this->db());

View File

@ -4,6 +4,8 @@ namespace Icinga\Module\Director\Web\Controller;
use Icinga\Application\Icinga;
use Icinga\Data\Paginatable;
use Icinga\Module\Director\Core\RestApiClient;
use Icinga\Module\Director\Core\CoreApi;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\Web\Form\FormLoader;
use Icinga\Module\Director\Web\Table\TableLoader;
@ -70,6 +72,14 @@ abstract class ActionController extends Controller
return $this->view->tabs;
}
protected function api()
{
$apiconfig = $this->Config()->getSection('api');
$client = new RestApiClient($apiconfig->get('address'), $apiconfig->get('port'));
$client->setCredentials($apiconfig->get('username'), $apiconfig->get('password'));
$api = new CoreApi($client);
return $api;
}
protected function db()
{