diff options
author | Robin Appelman <robin@icewind.nl> | 2017-03-28 11:02:18 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2017-03-28 11:02:18 +0200 |
commit | 5062d0ac50facc1944fe9e721c19164675894f8b (patch) | |
tree | f64eefe62b5895ca040cb22458a920483f3cf1cb | |
parent | f154b1d32ce0d469e5c4f96195e169f1aa4d5406 (diff) | |
download | nextcloud-server-5062d0ac50facc1944fe9e721c19164675894f8b.tar.gz nextcloud-server-5062d0ac50facc1944fe9e721c19164675894f8b.zip |
better error messages when swift authentication fails
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r-- | lib/private/Files/ObjectStore/Swift.php | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/private/Files/ObjectStore/Swift.php b/lib/private/Files/ObjectStore/Swift.php index 2ccaad27e88..4f994b6f40c 100644 --- a/lib/private/Files/ObjectStore/Swift.php +++ b/lib/private/Files/ObjectStore/Swift.php @@ -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; } |