|
1
|
|
|
<?php |
|
2
|
|
|
namespace Shlinkio\Shlink\CLI\Command\Api; |
|
3
|
|
|
|
|
4
|
|
|
use Acelaya\ZsmAnnotatedServices\Annotation\Inject; |
|
5
|
|
|
use Shlinkio\Shlink\Rest\Service\ApiKeyService; |
|
6
|
|
|
use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; |
|
7
|
|
|
use Symfony\Component\Console\Command\Command; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
use Zend\I18n\Translator\TranslatorInterface; |
|
12
|
|
|
|
|
13
|
|
|
class DisableKeyCommand extends Command |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var ApiKeyServiceInterface |
|
17
|
|
|
*/ |
|
18
|
|
|
private $apiKeyService; |
|
19
|
|
|
/** |
|
20
|
|
|
* @var TranslatorInterface |
|
21
|
|
|
*/ |
|
22
|
|
|
private $translator; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* DisableKeyCommand constructor. |
|
26
|
|
|
* @param ApiKeyServiceInterface|ApiKeyService $apiKeyService |
|
27
|
|
|
* @param TranslatorInterface $translator |
|
28
|
|
|
* |
|
29
|
|
|
* @Inject({ApiKeyService::class, "translator"}) |
|
30
|
|
|
*/ |
|
31
|
2 |
|
public function __construct(ApiKeyServiceInterface $apiKeyService, TranslatorInterface $translator) |
|
32
|
|
|
{ |
|
33
|
2 |
|
$this->apiKeyService = $apiKeyService; |
|
34
|
2 |
|
$this->translator = $translator; |
|
35
|
2 |
|
parent::__construct(null); |
|
36
|
2 |
|
} |
|
37
|
|
|
|
|
38
|
2 |
|
public function configure() |
|
39
|
|
|
{ |
|
40
|
2 |
|
$this->setName('api-key:disable') |
|
41
|
2 |
|
->setDescription($this->translator->translate('Disables an API key.')) |
|
42
|
2 |
|
->addArgument('apiKey', InputArgument::REQUIRED, $this->translator->translate('The API key to disable')); |
|
43
|
2 |
|
} |
|
44
|
|
|
|
|
45
|
2 |
|
public function execute(InputInterface $input, OutputInterface $output) |
|
46
|
|
|
{ |
|
47
|
2 |
|
$apiKey = $input->getArgument('apiKey'); |
|
48
|
|
|
|
|
49
|
|
|
try { |
|
50
|
2 |
|
$this->apiKeyService->disable($apiKey); |
|
51
|
1 |
|
$output->writeln(sprintf( |
|
52
|
1 |
|
$this->translator->translate('API key %s properly disabled'), |
|
53
|
1 |
|
'<info>' . $apiKey . '</info>' |
|
54
|
1 |
|
)); |
|
55
|
2 |
|
} catch (\InvalidArgumentException $e) { |
|
56
|
2 |
|
$output->writeln(sprintf( |
|
57
|
1 |
|
'<error>' . $this->translator->translate('API key "%s" does not exist.') . '</error>', |
|
58
|
|
|
$apiKey |
|
59
|
1 |
|
)); |
|
60
|
|
|
} |
|
61
|
2 |
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|