mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
KickstartForm: remove logic, use new helper
This commit is contained in:
parent
9764f300b6
commit
81335598a6
@ -2,17 +2,13 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Forms;
|
namespace Icinga\Module\Director\Forms;
|
||||||
|
|
||||||
use Icinga\Module\Director\Objects\IcingaApiUser;
|
use Icinga\Module\Director\KickstartHelper;
|
||||||
use Icinga\Module\Director\Core\CoreApi;
|
|
||||||
use Icinga\Module\Director\Core\RestApiClient;
|
|
||||||
use Icinga\Module\Director\Web\Form\QuickForm;
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
||||||
|
|
||||||
class KickstartForm extends QuickForm
|
class KickstartForm extends QuickForm
|
||||||
{
|
{
|
||||||
protected $db;
|
protected $db;
|
||||||
|
|
||||||
protected $apiUser;
|
|
||||||
|
|
||||||
public function setup()
|
public function setup()
|
||||||
{
|
{
|
||||||
$this->addHtmlHint(
|
$this->addHtmlHint(
|
||||||
@ -52,72 +48,11 @@ class KickstartForm extends QuickForm
|
|||||||
|
|
||||||
public function onSuccess()
|
public function onSuccess()
|
||||||
{
|
{
|
||||||
$this->importZones()
|
$kickstart = new KickstartHelper($this->db);
|
||||||
->importEndpoints()
|
$kickstart->setConfig($this->getValues())->run();
|
||||||
->importCommands();
|
|
||||||
|
|
||||||
$this->apiUser()->store();
|
|
||||||
parent::onSuccess();
|
parent::onSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function apiUser()
|
|
||||||
{
|
|
||||||
if ($this->apiUser === null) {
|
|
||||||
$this->apiUser = IcingaApiUser::create(array(
|
|
||||||
'object_name' => $this->getValue('username'),
|
|
||||||
'object_type' => 'external_object',
|
|
||||||
'password' => $this->getValue('password')
|
|
||||||
), $this->db);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->apiUser;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function importZones()
|
|
||||||
{
|
|
||||||
$db = $this->db;
|
|
||||||
foreach ($this->api()->setDb($db)->getZoneObjects() as $object) {
|
|
||||||
if (! $object::exists($object->object_name, $db)) {
|
|
||||||
$object->store();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function importEndpoints()
|
|
||||||
{
|
|
||||||
$db = $this->db;
|
|
||||||
$master = $this->getValue('endpoint');
|
|
||||||
|
|
||||||
foreach ($this->api()->setDb($db)->getEndpointObjects() as $object) {
|
|
||||||
|
|
||||||
if ($object->object_name === $master) {
|
|
||||||
$apiuser = $this->apiUser();
|
|
||||||
$apiuser->store();
|
|
||||||
$object->apiuser = $apiuser->object_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $object::exists($object->object_name, $db)) {
|
|
||||||
$object->store();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function importCommands()
|
|
||||||
{
|
|
||||||
$db = $this->db;
|
|
||||||
foreach ($this->api()->setDb($db)->getCheckCommandObjects() as $object) {
|
|
||||||
if (! $object::exists($object->object_name, $db)) {
|
|
||||||
$object->store();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setDb($db)
|
public function setDb($db)
|
||||||
{
|
{
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
@ -127,18 +62,4 @@ class KickstartForm extends QuickForm
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function api()
|
|
||||||
{
|
|
||||||
$client = new RestApiClient(
|
|
||||||
$this->getValue('host'),
|
|
||||||
$this->getValue('port')
|
|
||||||
);
|
|
||||||
|
|
||||||
$apiuser = $this->apiUser();
|
|
||||||
$client->setCredentials($apiuser->object_name, $apiuser->password);
|
|
||||||
|
|
||||||
$api = new CoreApi($client);
|
|
||||||
return $api;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user