1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the XabbuhPandaBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Xabbuh\PandaBundle\Command; |
13
|
|
|
|
14
|
|
|
use Http\Client\HttpClient; |
15
|
|
|
use Symfony\Component\Console\Command\Command; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Input\InputOption; |
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
20
|
|
|
use Xabbuh\PandaClient\Api\AccountManagerInterface; |
21
|
|
|
use Xabbuh\PandaClient\Api\Cloud; |
22
|
|
|
use Xabbuh\PandaClient\Api\HttplugClient; |
23
|
|
|
use Xabbuh\PandaClient\Transformer\TransformerRegistry; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Modify a panda cloud via command-line. |
27
|
|
|
* |
28
|
|
|
* @author Christian Flothmann <[email protected]> |
29
|
|
|
* |
30
|
|
|
* @final |
31
|
|
|
*/ |
32
|
|
|
class ModifyCloudCommand extends Command |
33
|
|
|
{ |
34
|
|
|
protected static $defaultName = 'panda:cloud:modify'; |
35
|
|
|
|
36
|
|
|
private $accountManager; |
37
|
|
|
private $transformerRegistry; |
38
|
|
|
private $httpClient; |
39
|
|
|
|
40
|
6 |
|
public function __construct(AccountManagerInterface $accountManager, TransformerRegistry $transformerRegistry, HttpClient $httpClient = null) |
41
|
|
|
{ |
42
|
6 |
|
parent::__construct(); |
43
|
|
|
|
44
|
6 |
|
$this->accountManager = $accountManager; |
45
|
6 |
|
$this->transformerRegistry = $transformerRegistry; |
46
|
6 |
|
$this->httpClient = $httpClient; |
47
|
6 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritDoc} |
51
|
|
|
*/ |
52
|
6 |
|
protected function configure() |
53
|
|
|
{ |
54
|
6 |
|
$this->setName(static::$defaultName); // BC with Symfony Console 3.3 and older not handling the property automatically |
55
|
6 |
|
$this->setDescription('Modify a cloud'); |
56
|
6 |
|
$this->addOption( |
57
|
6 |
|
'account', |
58
|
6 |
|
'a', |
59
|
6 |
|
InputOption::VALUE_REQUIRED, |
60
|
6 |
|
'The account to use to authenticate to the panda service' |
61
|
|
|
); |
62
|
6 |
|
$this->addOption('name', null, InputOption::VALUE_REQUIRED, 'The new cloud name'); |
63
|
6 |
|
$this->addOption('s3-bucket', null, InputOption::VALUE_REQUIRED, 'The new AWS S3 bucket'); |
64
|
6 |
|
$this->addOption('access-key', null, InputOption::VALUE_REQUIRED, 'The new access key'); |
65
|
6 |
|
$this->addOption('secret-key', null, InputOption::VALUE_REQUIRED, 'The new secret key'); |
66
|
6 |
|
$this->addArgument('cloud-id', InputArgument::REQUIRED, 'The id of the cloud being modified'); |
67
|
6 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritDoc} |
71
|
|
|
*/ |
72
|
4 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
73
|
|
|
{ |
74
|
4 |
|
$data = array(); |
75
|
|
|
|
76
|
|
|
// change the cloud name |
77
|
4 |
|
if ($name = $input->getOption('name')) { |
78
|
1 |
|
$data['name'] = $name; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
// change the s3 bucket |
82
|
4 |
|
if ($s3bucket = $input->getOption('s3-bucket')) { |
83
|
1 |
|
$data['s3_videos_bucket'] = $s3bucket; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// change the access key |
87
|
4 |
|
if ($accessKey = $input->getOption('access-key')) { |
88
|
1 |
|
$data['aws_access_key'] = $accessKey; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
// change the secret key |
92
|
4 |
|
if ($secretKey = $input->getOption('secret-key')) { |
93
|
1 |
|
$data['aws_secret_key'] = $secretKey; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// if anything has changed |
97
|
4 |
|
if (count($data) > 0) { |
98
|
3 |
|
$cloud = $this->getCloud($input->getArgument('cloud-id'), $input->getOption('account')); |
|
|
|
|
99
|
3 |
|
$cloud->setCloud($data, $input->getArgument('cloud-id')); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
4 |
|
return 0; |
103
|
|
|
} |
104
|
|
|
|
105
|
3 |
|
private function getCloud(string $cloudId, ?string $accountKey): Cloud |
106
|
|
|
{ |
107
|
3 |
|
if (null === $this->accountManager) { |
108
|
|
|
$this->accountManager = $this->getContainer()->get('xabbuh_panda.account_manager'); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
3 |
|
if (null === $this->transformerRegistry) { |
112
|
|
|
$this->transformerRegistry = $this->getContainer()->get('xabbuh_panda.transformer'); |
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
3 |
|
$account = $this->accountManager->getAccount($accountKey); |
116
|
|
|
|
117
|
3 |
|
$httpClient = new HttplugClient($this->httpClient); |
118
|
3 |
|
$httpClient->setCloudId($cloudId); |
119
|
3 |
|
$httpClient->setAccount($account); |
120
|
|
|
|
121
|
3 |
|
$cloud = new Cloud(); |
122
|
3 |
|
$cloud->setHttpClient($httpClient); |
123
|
3 |
|
$cloud->setTransformers($this->transformerRegistry); |
124
|
|
|
|
125
|
3 |
|
return $cloud; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.