ActionController: get api from endpoint object

This commit is contained in:
Thomas Gelf 2016-02-17 16:40:08 +01:00
parent 402b4c31e2
commit e33d548d1b

View File

@ -7,9 +7,8 @@ use Icinga\Data\Paginatable;
use Icinga\Exception\AuthenticationException;
use Icinga\Exception\ConfigurationError;
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\Objects\IcingaEndpoint;
use Icinga\Module\Director\Web\Form\FormLoader;
use Icinga\Module\Director\Web\Table\TableLoader;
use Icinga\Web\Controller;
@ -21,6 +20,8 @@ abstract class ActionController extends Controller
protected $isApified = false;
private $api;
public function init()
{
if ($this->getRequest()->isApiRequest()) {
@ -122,13 +123,19 @@ abstract class ActionController extends Controller
return $this->view->tabs;
}
protected function api()
protected function api($endpointName = null)
{
$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;
if ($this->api === null) {
if ($endpointName === null) {
$endpoint = $this->db()->getDeploymentEndpoint();
} else {
$endpoint = IcingaEndpoint::load($endpointName, $this->db());
}
$this->api = $endpoint->api();
}
return $this->api;
}
protected function db()