|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Incapsula\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
|
|
10
|
|
|
class SubAccountListCommand extends AbstractCommand |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
private $accountName; |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
protected function configure() |
|
18
|
|
|
{ |
|
19
|
|
|
parent::configure(); |
|
20
|
|
|
|
|
21
|
|
|
$this |
|
22
|
|
|
->setName('subaccount:list') |
|
23
|
|
|
->addOption('json', null, InputOption::VALUE_NONE, 'Output as JSON') |
|
24
|
|
|
->setDescription('List all sites') |
|
25
|
|
|
; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param InputInterface $input |
|
30
|
|
|
* @param OutputInterface $output |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function initialize(InputInterface $input, OutputInterface $output) |
|
33
|
|
|
{ |
|
34
|
|
|
parent::initialize($input, $output); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param InputInterface $input |
|
39
|
|
|
* @param OutputInterface $output |
|
40
|
|
|
* |
|
41
|
|
|
* @return int |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
44
|
|
|
{ |
|
45
|
|
|
$api = $this->client->accounts(); |
|
46
|
|
|
$subAcc = []; |
|
47
|
|
|
$page = 0; |
|
48
|
|
|
|
|
49
|
|
|
while (true) { |
|
50
|
|
|
$resp = $api->list(50, $page); |
|
51
|
|
|
if (empty($resp['resultList'])) { |
|
52
|
|
|
break; |
|
53
|
|
|
} |
|
54
|
|
|
$subAcc = array_merge($subAcc, $resp['resultList']); |
|
55
|
|
|
++$page; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
if (true === $input->getOption('json')) { |
|
59
|
|
|
$output->write(json_encode($subAcc)); |
|
60
|
|
|
|
|
61
|
|
|
return 0; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$table = new Table($output); |
|
65
|
|
|
$table->setHeaders(['Name', 'AccountID']); |
|
66
|
|
|
foreach ($subAcc as $acc) { |
|
67
|
|
|
$table->addRow([$acc['sub_account_name'], $acc['sub_account_id']]); |
|
68
|
|
|
} |
|
69
|
|
|
$table->render(); |
|
70
|
|
|
|
|
71
|
|
|
return 0; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|