1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* SPDX-FileCopyrightText: 2024 Christoph Wurst <[email protected]> |
7
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace OCA\TwoFactorGateway\Command; |
11
|
|
|
|
12
|
|
|
use OCA\TwoFactorGateway\Provider\Gateway\AGateway; |
13
|
|
|
use OCA\TwoFactorGateway\Provider\Gateway\Factory; |
14
|
|
|
use Symfony\Component\Console\Command\Command; |
15
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
use Symfony\Component\Console\Question\ChoiceQuestion; |
20
|
|
|
|
21
|
|
|
class Remove extends Command { |
22
|
|
|
/** @var AGateway[] */ |
23
|
|
|
private array $gateways = []; |
24
|
|
|
|
25
|
1 |
|
public function __construct( |
26
|
|
|
private Factory $gatewayFactory, |
27
|
|
|
) { |
28
|
1 |
|
parent::__construct('twofactorauth:gateway:remove'); |
29
|
|
|
|
30
|
1 |
|
$fqcn = $this->gatewayFactory->getFqcnList(); |
31
|
1 |
|
foreach ($fqcn as $fqcn) { |
32
|
1 |
|
$gateway = $this->gatewayFactory->get($fqcn); |
33
|
1 |
|
$this->gateways[$gateway->getSettings()->id] = $gateway; |
34
|
|
|
} |
35
|
|
|
|
36
|
1 |
|
$this->addArgument( |
37
|
1 |
|
'gateway', |
38
|
1 |
|
InputArgument::OPTIONAL, |
39
|
1 |
|
'The name of the gateway: ' . implode(', ', array_keys($this->gateways)) |
40
|
1 |
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
4 |
|
#[\Override] |
44
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
45
|
4 |
|
$gatewayName = strtolower((string)$input->getArgument('gateway')); |
46
|
4 |
|
if (!array_key_exists($gatewayName, $this->gateways)) { |
47
|
4 |
|
$helper = new QuestionHelper(); |
48
|
4 |
|
$choiceQuestion = new ChoiceQuestion('Please choose a provider:', array_keys($this->gateways)); |
49
|
4 |
|
$selected = $helper->ask($input, $output, $choiceQuestion); |
50
|
3 |
|
$gateway = $this->gateways[$selected]; |
51
|
|
|
} |
52
|
|
|
|
53
|
3 |
|
$gateway->remove(); |
|
|
|
|
54
|
3 |
|
$output->writeln("Removed configuration for gateway $gatewayName"); |
55
|
3 |
|
return 0; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|