|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Acquia\Search\Proxy\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Acquia\Rest\ServiceManager; |
|
6
|
|
|
use Acquia\Common\Services; |
|
7
|
|
|
use Acquia\Network\AcquiaNetworkClient; |
|
8
|
|
|
use Acquia\Search\AcquiaSearchService; |
|
9
|
|
|
use Symfony\Component\Console\Command\Command; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
|
|
15
|
|
|
class AuthIndexesCommand extends Command |
|
16
|
|
|
{ |
|
17
|
|
|
protected function configure() |
|
18
|
|
|
{ |
|
19
|
|
|
$this |
|
20
|
|
|
->setName('indexes:auth') |
|
21
|
|
|
->setDescription('Authenticate Acquia Search indexes associated with a subscription') |
|
22
|
|
|
->addArgument( |
|
23
|
|
|
'config-file', |
|
24
|
|
|
InputArgument::REQUIRED, |
|
25
|
|
|
'Path to the .json that will store the index credentials' |
|
26
|
|
|
) |
|
27
|
|
|
->addOption( |
|
28
|
|
|
'identifier', |
|
29
|
|
|
null, |
|
30
|
|
|
InputOption::VALUE_REQUIRED, |
|
31
|
|
|
'The subscription\'s Acquia Network identifier, e.g. ABCD-12345' |
|
32
|
|
|
) |
|
33
|
|
|
->addOption( |
|
34
|
|
|
'key', |
|
35
|
|
|
null, |
|
36
|
|
|
InputOption::VALUE_REQUIRED, |
|
37
|
|
|
'The subscription\'s Acquia Network key' |
|
38
|
|
|
) |
|
39
|
|
|
; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
43
|
|
|
{ |
|
44
|
|
|
$configFile = $input->getArgument('config-file'); |
|
45
|
|
|
if (pathinfo($configFile, PATHINFO_EXTENSION) != 'json') { |
|
46
|
|
|
throw new \InvalidArgumentException('Configuration file must be a JSON document'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$dialog = $this->getHelperSet()->get('dialog'); |
|
50
|
|
|
if (!$identifier = $input->getOption('identifier')) { |
|
51
|
|
|
$identifier = $dialog->ask($output, 'Acquia Network Identifier: '); |
|
52
|
|
|
} |
|
53
|
|
|
if (!$key = $input->getOption('key')) { |
|
54
|
|
|
$key = $dialog->ask($output, 'Acquia Network Key: '); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$network = AcquiaNetworkClient::factory(array( |
|
58
|
|
|
'network_id' => $identifier, |
|
59
|
|
|
'network_key' => $key, |
|
60
|
|
|
)); |
|
61
|
|
|
|
|
62
|
|
|
$acquiaServices = Services::ACQUIA_SEARCH; |
|
63
|
|
|
$subscription = $network->checkSubscription($acquiaServices); |
|
64
|
|
|
$search = AcquiaSearchService::factory($subscription); |
|
65
|
|
|
|
|
66
|
|
|
$services = new ServiceManager(array( |
|
67
|
|
|
'conf_dir' => dirname($configFile), |
|
68
|
|
|
)); |
|
69
|
|
|
|
|
70
|
|
|
$group = basename($configFile, '.json'); |
|
71
|
|
|
$services->setBuilder($group, $search); |
|
72
|
|
|
$services->save(); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|