Updated the OpenStack driver to use the new PHP Open Cloud repo instead of the previous Rackspace one. This also completes the last provider's change to GuzzleHttp instead of Guzzle. #144 #145

This commit is contained in:
Andy Heathershaw 2020-04-22 08:19:28 +01:00
parent 132bfcdb83
commit 61c51fcd37
1 changed files with 33 additions and 11 deletions

View File

@ -3,9 +3,14 @@
namespace App\AlbumSources; namespace App\AlbumSources;
use App\Photo; use App\Photo;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Stream; use GuzzleHttp\Psr7\Stream;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use OpenStack\Common\Error\BadResponseError;
use OpenStack\Common\Transport\Utils as TransportUtils;
use OpenStack\Identity\v2\Service as IdentityV2Service;
use OpenStack\OpenStack; use OpenStack\OpenStack;
use function GuzzleHttp\Psr7\stream_for; use function GuzzleHttp\Psr7\stream_for;
@ -37,13 +42,18 @@ class OpenStackSource extends AlbumSourceBase implements IAlbumSource
try try
{ {
$this->getContainer()->deleteObject($photoPath); $this->getContainer()->getObject($photoPath)->delete();
} }
catch (GuzzleException $ex) catch (GuzzleException $ex)
{ {
// Don't worry if the file no longer exists // Don't worry if the file no longer exists
Log::warning('Failed deleting image from OpenStack.', ['error' => $ex->getMessage(), 'path' => $photoPath]); Log::warning('Failed deleting image from OpenStack.', ['error' => $ex->getMessage(), 'path' => $photoPath]);
} }
catch (BadResponseError $ex)
{
// Don't worry if the file no longer exists
Log::warning('Failed deleting image from OpenStack.', ['error' => $ex->getMessage(), 'path' => $photoPath]);
}
} }
/** /**
@ -56,7 +66,7 @@ class OpenStackSource extends AlbumSourceBase implements IAlbumSource
{ {
$object = $this->getContainer()->getObject($this->getPathToPhoto($photo, $thumbnail)); $object = $this->getContainer()->getObject($this->getPathToPhoto($photo, $thumbnail));
return stream_for($object->getContent()); return stream_for($object->download());
} }
/** /**
@ -112,17 +122,31 @@ class OpenStackSource extends AlbumSourceBase implements IAlbumSource
{ {
$photoPath = $this->getPathToPhoto($photo, $thumbnail); $photoPath = $this->getPathToPhoto($photo, $thumbnail);
$container = $this->getContainer(); $createOptions = [
$container->uploadObject($photoPath, fopen($tempFilename, 'r+')); 'name' => $photoPath,
'content' => file_get_contents($tempFilename)
];
$this->getContainer()->createObject($createOptions);
} }
protected function getClient() protected function getClient()
{ {
return new OpenStack($this->configuration->auth_url, [ $openstackOptions = [
'authUrl' => $this->configuration->auth_url,
'username' => $this->configuration->username, 'username' => $this->configuration->username,
'password' => decrypt($this->configuration->password), 'password' => decrypt($this->configuration->password),
'tenantName' => $this->configuration->tenant_name, 'tenantName' => $this->configuration->tenant_name,
]); 'region' => $this->configuration->service_region,
'identityService' => IdentityV2Service::factory(
new Client([
'base_uri' => TransportUtils::normalizeUrl( $this->configuration->auth_url),
'handler' => HandlerStack::create(),
])
)
];
return new OpenStack($openstackOptions);
} }
protected function getContainer() protected function getContainer()
@ -132,11 +156,9 @@ class OpenStackSource extends AlbumSourceBase implements IAlbumSource
protected function getStorageService() protected function getStorageService()
{ {
return $this->getClient()->objectStoreService( return $this->getClient()->objectStoreV1([
$this->configuration->service_name, 'catalogName' => $this->configuration->service_name
$this->configuration->service_region, ]);
'publicURL'
);
} }
protected function getOriginalsFolder() protected function getOriginalsFolder()