Viewing File: /usr/local/cpanel/whostmgr/docroot/cgi/ncssl/source/src/Command/RefreshTokenCommand.php
<?php
namespace App\Command;
use App\Service\Whm\TokenStorageInterface;
use App\Service\Whm\WhmApiInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(name: 'app:refresh-token', description: 'Command refresh whm token')]
class RefreshTokenCommand extends Command
{
public function __construct(
private readonly WhmApiInterface $whmApi,
private readonly LoggerInterface $logger,
private readonly TokenStorageInterface $storage,
){
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
try {
$output->writeln('Start revoke WHM token');
$this->whmApi->deleteToken();
$output->writeln('Start create WHM token');
$token = $this->whmApi->createToken();
$this->storage->set($token);
$output->writeln('New WHM token was generated and save to secret vault!');
return Command::SUCCESS;
} catch (\Exception $e) {
$this->logger->error(sprintf('Error occurred while generating WHM token: %s', $e->getMessage()));
return Command::FAILURE;
}
}
}
Back to Directory
File Manager