mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
ApiKey: add new related forms
This commit is contained in:
parent
7d8db0f0c8
commit
70034b5afe
34
application/forms/IcingaForgetApiKeyForm.php
Normal file
34
application/forms/IcingaForgetApiKeyForm.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Forms;
|
||||
|
||||
use Icinga\Module\Director\Objects\IcingaHost;
|
||||
use Icinga\Module\Director\Web\Form\DirectorForm;
|
||||
|
||||
class IcingaForgetApiKeyForm extends DirectorForm
|
||||
{
|
||||
/** @var IcingaHost */
|
||||
protected $host;
|
||||
|
||||
public function setHost(IcingaHost $host)
|
||||
{
|
||||
$this->host = $host;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->addStandaloneSubmitButton(sprintf(
|
||||
$this->translate('Drop Self Service API key'),
|
||||
$this->host->getObjectName()
|
||||
));
|
||||
}
|
||||
|
||||
public function onSuccess()
|
||||
{
|
||||
$this->host->set('api_key', null)->store();
|
||||
$this->redirectOnSuccess(sprintf($this->translate(
|
||||
'The Self Service API key for %s has been dropped'
|
||||
), $this->host->getObjectName()));
|
||||
}
|
||||
}
|
42
application/forms/IcingaGenerateApiKeyForm.php
Normal file
42
application/forms/IcingaGenerateApiKeyForm.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Forms;
|
||||
|
||||
use Icinga\Module\Director\Objects\IcingaHost;
|
||||
use Icinga\Module\Director\Web\Form\DirectorForm;
|
||||
|
||||
class IcingaGenerateApiKeyForm extends DirectorForm
|
||||
{
|
||||
/** @var IcingaHost */
|
||||
protected $host;
|
||||
|
||||
public function setHost(IcingaHost $host)
|
||||
{
|
||||
$this->host = $host;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setup()
|
||||
{
|
||||
if ($this->host->getProperty('api_key')) {
|
||||
$label = $this->translate('Regenerate Self Service API key');
|
||||
} else {
|
||||
$label = $this->translate('Generate Self Service API key');
|
||||
}
|
||||
|
||||
$this->addStandaloneSubmitButton(sprintf(
|
||||
$label,
|
||||
$this->host->getObjectName()
|
||||
));
|
||||
}
|
||||
|
||||
public function onSuccess()
|
||||
{
|
||||
$host = $this->host;
|
||||
$host->generateApiKey();
|
||||
$host->store();
|
||||
$this->redirectOnSuccess(sprintf($this->translate(
|
||||
'A new Self Service API key for %s has been generated'
|
||||
), $host->getObjectName()));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user