Skip to content

Commit 42d3b56

Browse files
authored
Add check Secret (#262)
1 parent eca88fc commit 42d3b56

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Client.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,26 +180,34 @@ public function __construct(array $cosConfig) {
180180
$this->signature = new Signature($this->cosConfig['secretId'], $this->cosConfig['secretKey'], $this->cosConfig, $this->cosConfig['token']);
181181
$area = $this->cosConfig['allow_accelerate'] ? 'accelerate' : $this->cosConfig['region'];
182182
$this->httpClient = new HttpClient([
183-
'base_uri' => $this->cosConfig['schema'].'://cos.' . $area . '.myqcloud.com/',
183+
'base_uri' => "{$this->cosConfig['schema']}://cos.{$area}.myqcloud.com/",
184184
'timeout' => $this->cosConfig['timeout'],
185185
'handler' => $handler,
186186
'proxy' => $this->cosConfig['proxy'],
187187
'allow_redirects' => $this->cosConfig['allow_redirects']
188188
]);
189189
$this->desc = new Description($service);
190-
$this->api = (array)($this->desc->getOperations());
190+
$this->api = (array) $this->desc->getOperations();
191191
parent::__construct($this->httpClient, $this->desc, [$this,
192192
'commandToRequestTransformer'], [$this, 'responseToResultTransformer'],
193193
null);
194194
}
195195

196196
public function inputCheck() {
197+
$message = null;
197198
//检查Region
198199
if (empty($this->cosConfig['region']) &&
199200
empty($this->cosConfig['domain']) &&
200201
empty($this->cosConfig['endpoint']) &&
201202
empty($this->cosConfig['ip'])) {
202-
$e = new Exception\CosException('Region is empty');
203+
$message = 'Region is empty';
204+
}
205+
//检查Secret
206+
if (empty($this->cosConfig['secretId']) || empty($this->cosConfig['secretKey'])) {
207+
$message = 'Secret is empty';
208+
}
209+
if ($message !== null) {
210+
$e = new Exception\CosException($message);
203211
$e->setExceptionCode('Invalid Argument');
204212
throw $e;
205213
}

0 commit comments

Comments
 (0)