better error messages when swift authentication fails

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2017-03-28 11:02:18 +02:00
parent f154b1d32c
commit 5062d0ac50
No known key found for this signature in database
GPG Key ID: 50F2B59C6DEBBCFE
1 changed files with 17 additions and 1 deletions

View File

@ -26,6 +26,8 @@ namespace OC\Files\ObjectStore;
use Guzzle\Http\Exception\ClientErrorResponseException;
use OCP\Files\ObjectStore\IObjectStore;
use OCP\Files\StorageAuthException;
use OpenCloud\Common\Exceptions\EndpointError;
use OpenCloud\OpenStack;
use OpenCloud\Rackspace;
@ -76,6 +78,19 @@ class Swift implements IObjectStore {
return;
}
try {
$this->client->authenticate();
} catch (ClientErrorResponseException $e) {
$statusCode = $e->getResponse()->getStatusCode();
if ($statusCode == 412) {
throw new StorageAuthException('Precondition failed, verify the keystone url', $e);
} else if ($statusCode === 401) {
throw new StorageAuthException('Authentication failed, verify the username, password and possibly tenant', $e);
} else {
throw new StorageAuthException('Unknown error', $e);
}
}
// the OpenCloud client library will default to 'cloudFiles' if $serviceName is null
$serviceName = null;
if (isset($this->params['serviceName'])) {
@ -87,6 +102,7 @@ class Swift implements IObjectStore {
if (isset($this->params['urlType'])) {
$urlType = $this->params['urlType'];
}
$this->objectStoreService = $this->client->objectStoreService($serviceName, $this->params['region'], $urlType);
try {
@ -135,7 +151,7 @@ class Swift implements IObjectStore {
$stream = $objectContent->getStream();
// save the object content in the context of the stream to prevent it being gc'd until the stream is closed
stream_context_set_option($stream, 'swift','content', $objectContent);
stream_context_set_option($stream, 'swift', 'content', $objectContent);
return $stream;
}