mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
ImportSourceCoreApi: provide database. Not so nice
This commit is contained in:
parent
a362ef4e42
commit
94456f90ff
@ -3,6 +3,7 @@
|
||||
namespace Icinga\Module\Director\Import;
|
||||
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Module\Director\Db;
|
||||
use Icinga\Module\Director\Core\CoreApi;
|
||||
use Icinga\Module\Director\Core\RestApiClient;
|
||||
use Icinga\Module\Director\Util;
|
||||
@ -13,6 +14,8 @@ class ImportSourceCoreApi extends ImportSourceHook
|
||||
{
|
||||
protected $connection;
|
||||
|
||||
protected $db;
|
||||
|
||||
public function fetchData()
|
||||
{
|
||||
$func = 'get' . $this->getSetting('object_type') . 'Objects';
|
||||
@ -55,6 +58,19 @@ class ImportSourceCoreApi extends ImportSourceHook
|
||||
$client = new RestApiClient($apiconfig->get('address'), $apiconfig->get('port'));
|
||||
$client->setCredentials($apiconfig->get('username'), $apiconfig->get('password'));
|
||||
$api = new CoreApi($client);
|
||||
$api->setDb($this->db());
|
||||
return $api;
|
||||
}
|
||||
|
||||
protected function db()
|
||||
{
|
||||
if ($this->db === null) {
|
||||
$resourceName = Config::module('director')->get('db', 'resource');
|
||||
if ($resourceName) {
|
||||
$this->db = Db::fromResourceName($resourceName);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->db;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user