-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c64cafc
commit cd784f9
Showing
4 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Storeman\StorageAdapter; | ||
|
||
use Aws\S3\S3Client; | ||
use League\Flysystem\AwsS3v3\AwsS3Adapter; | ||
use League\Flysystem\Filesystem; | ||
use Storeman\Config\ConfigurationException; | ||
use Storeman\Config\VaultConfiguration; | ||
|
||
class S3 extends FlysystemStorageAdapter | ||
{ | ||
public function __construct(VaultConfiguration $vaultConfiguration) | ||
{ | ||
$requiredSettings = [ | ||
'bucket', | ||
'key', | ||
'secret', | ||
]; | ||
|
||
if ($missingSettings = array_diff($requiredSettings, array_keys(array_filter($vaultConfiguration->getSettings())))) | ||
{ | ||
throw new ConfigurationException("Missing mandatory setting(s): " . implode(',', $missingSettings)); | ||
} | ||
|
||
$client = new S3Client([ | ||
'version' => '2006-03-01', | ||
'credentials' => [ | ||
'key' => $vaultConfiguration->getSetting('key'), | ||
'secret' => $vaultConfiguration->getSetting('secret'), | ||
], | ||
'region' => 'eu-central-1', | ||
]); | ||
$adapter = new AwsS3Adapter($client, $vaultConfiguration->getSetting('bucket')); | ||
$filesystem = new Filesystem($adapter); | ||
|
||
parent::__construct($filesystem); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getIdentificationString(VaultConfiguration $vaultConfiguration): string | ||
{ | ||
return "{$vaultConfiguration->getSetting('username')}@{$vaultConfiguration->getSetting('host')}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Storeman\Test\StorageAdapter; | ||
|
||
use Storeman\Config\VaultConfiguration; | ||
use Storeman\StorageAdapter\S3; | ||
use Storeman\StorageAdapter\StorageAdapterInterface; | ||
use Storeman\Test\ConfiguredMockProviderTrait; | ||
|
||
class S3Test extends AbstractStorageAdapterTest | ||
{ | ||
use ConfiguredMockProviderTrait; | ||
|
||
protected function getStorageAdapter(): StorageAdapterInterface | ||
{ | ||
$vaultConfiguration = new VaultConfiguration($this->getConfigurationMock()); | ||
$vaultConfiguration->setSettings([ | ||
'key' => getenv('s3key'), | ||
'secret' => getenv('s3secret'), | ||
'bucket' => getenv('s3bucket'), | ||
]); | ||
|
||
return new S3($vaultConfiguration); | ||
} | ||
} |