-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partial POC for MP multi-file uploader to S3
- Loading branch information
1 parent
5da6831
commit f9193e6
Showing
95 changed files
with
4,239 additions
and
4 deletions.
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
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,37 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Spryker Commerce OS. | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Pyz\Service\AwsS3; | ||
|
||
use Pyz\Shared\AwsS3\AwsS3Constants; | ||
use Spryker\Service\Kernel\AbstractBundleConfig; | ||
|
||
class AwsS3Config extends AbstractBundleConfig | ||
{ | ||
private const AWS_S3_URL_PATTERN = 's3://%s/%s'; | ||
|
||
private const CDN_URL_PATTERN = '{schema}://{cdnHost}/{fileName}'; | ||
|
||
public function getAwsS3UrlPattern(): string | ||
{ | ||
return self::AWS_S3_URL_PATTERN; | ||
} | ||
|
||
public function getCdnUrlPattern(): string | ||
{ | ||
return self::CDN_URL_PATTERN; | ||
} | ||
|
||
public function getClientConfigurationForObjectType(string $objectType): array | ||
{ | ||
$bucketsConfigurationMap = $this->get(AwsS3Constants::BUCKETS_CONFIGURATION_MAP, []); | ||
|
||
return $bucketsConfigurationMap[$objectType] ?? []; | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Spryker Commerce OS. | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Pyz\Service\AwsS3; | ||
|
||
use Pyz\Service\AwsS3\Dependency\S3ClientProviderPluginInterface; | ||
use Pyz\Service\AwsS3\Plugin\AwsS3\S3ClientProviderPlugin; | ||
use Spryker\Service\Kernel\AbstractBundleDependencyProvider; | ||
use Spryker\Service\Kernel\Container; | ||
|
||
/** | ||
* @method \Pyz\Service\AwsS3\AwsS3Config getConfig() | ||
*/ | ||
class AwsS3DependencyProvider extends AbstractBundleDependencyProvider | ||
{ | ||
public const PLUGIN_S3_CLIENT_PROVIDER = 'PLUGIN_S3_CLIENT_PROVIDER_PLUGIN'; | ||
|
||
public function provideServiceDependencies(Container $container): Container | ||
{ | ||
$container = parent::provideServiceDependencies($container); | ||
$container = $this->addS3ClientProviderPlugin($container); | ||
|
||
return $container; | ||
} | ||
|
||
private function addS3ClientProviderPlugin(Container $container): Container | ||
{ | ||
$container->set( | ||
static::PLUGIN_S3_CLIENT_PROVIDER, | ||
static function (): S3ClientProviderPluginInterface { | ||
return new S3ClientProviderPlugin(); | ||
}, | ||
); | ||
|
||
return $container; | ||
} | ||
} |
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,57 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Spryker Commerce OS. | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Pyz\Service\AwsS3; | ||
|
||
use Pyz\Shared\AwsS3\AwsS3Config as SharedAwsS3Config; | ||
use Spryker\Service\Kernel\AbstractService; | ||
|
||
/** | ||
* @method \Pyz\Service\AwsS3\AwsS3ServiceFactory getFactory() | ||
*/ | ||
class AwsS3Service extends AbstractService implements AwsS3ServiceInterface | ||
{ | ||
public function getPresignedUrl(string $fileName, string $objectType): string | ||
{ | ||
return $this->getFactory() | ||
->createUrlCreator($objectType) | ||
->getPresignedUrl($fileName); | ||
} | ||
|
||
public function getS3ObjectUrl(string $fileName, string $objectType): string | ||
{ | ||
return $this->getFactory() | ||
->createAwsS3ObjectReader($objectType) | ||
->getS3ObjectUrl($fileName); | ||
} | ||
|
||
/** | ||
* @param string $objectType | ||
* | ||
* @return void | ||
*/ | ||
public function registerStreamWrapper(string $objectType = SharedAwsS3Config::OBJECT_TYPE_CVS_IMPORT): void | ||
{ | ||
$this->getFactory() | ||
->createUtilAws($objectType) | ||
->registerStreamWrapper(); | ||
} | ||
|
||
public function getCdnUrl(string $fileName, string $objectType): string | ||
{ | ||
return $this->getFactory() | ||
->createUrlCreator($objectType) | ||
->getCdnUrl($fileName); | ||
} | ||
|
||
public function deleteS3Object(string $objectType, string $path): void | ||
{ | ||
$this->getFactory() | ||
->createAwsS3ObjectDeleter($objectType) | ||
->deleteS3Object($path); | ||
} | ||
} |
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,71 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Spryker Commerce OS. | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Pyz\Service\AwsS3; | ||
|
||
use Aws\S3\S3Client; | ||
use Aws\S3\S3ClientInterface; | ||
use Pyz\Service\AwsS3\Creator\UrlCreator; | ||
use Pyz\Service\AwsS3\Creator\UrlCreatorInterface; | ||
use Pyz\Service\AwsS3\Deleter\AwsS3ObjectDeleter; | ||
use Pyz\Service\AwsS3\Deleter\AwsS3ObjectDeleterInterface; | ||
use Pyz\Service\AwsS3\Dependency\S3ClientProviderPluginInterface; | ||
use Pyz\Service\AwsS3\Reader\AwsS3ObjectReader; | ||
use Pyz\Service\AwsS3\Reader\AwsS3ObjectReaderInterface; | ||
use Pyz\Service\AwsS3\Util\UtilAws; | ||
use Pyz\Service\AwsS3\Util\UtilAwsInterface; | ||
use Spryker\Service\Kernel\AbstractServiceFactory; | ||
|
||
/** | ||
* @method \Pyz\Service\AwsS3\AwsS3Config getConfig() | ||
*/ | ||
class AwsS3ServiceFactory extends AbstractServiceFactory | ||
{ | ||
public function createUrlCreator(string $objectType): UrlCreatorInterface | ||
{ | ||
$s3Client = $this | ||
->getS3ClientProviderPlugin() | ||
->provideConfiguredClientForObjectType($objectType); | ||
|
||
return new UrlCreator( | ||
$this->getConfig(), | ||
$s3Client, | ||
$objectType, | ||
); | ||
} | ||
|
||
public function createAwsS3ObjectReader(string $objectType): AwsS3ObjectReaderInterface | ||
{ | ||
return new AwsS3ObjectReader($this->getConfig(), $objectType); | ||
} | ||
|
||
public function createAwsS3ObjectDeleter(string $objectType): AwsS3ObjectDeleterInterface | ||
{ | ||
return new AwsS3ObjectDeleter( | ||
$this->createUtilAws($objectType), | ||
); | ||
} | ||
|
||
public function createUtilAws(string $objectType): UtilAwsInterface | ||
{ | ||
$s3Client = $this | ||
->getS3ClientProviderPlugin() | ||
->provideConfiguredClientForObjectType($objectType); | ||
|
||
return new UtilAws($s3Client); | ||
} | ||
|
||
public function createS3Client(array $configuration): S3ClientInterface | ||
{ | ||
return new S3Client($configuration); | ||
} | ||
|
||
public function getS3ClientProviderPlugin(): S3ClientProviderPluginInterface | ||
{ | ||
return $this->getProvidedDependency(AwsS3DependencyProvider::PLUGIN_S3_CLIENT_PROVIDER); | ||
} | ||
} |
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,75 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Spryker Commerce OS. | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Pyz\Service\AwsS3; | ||
|
||
interface AwsS3ServiceInterface | ||
{ | ||
/** | ||
* Specification: | ||
* - Returns the presigned URL for the given file name. | ||
* | ||
* @api | ||
* | ||
* @param string $fileName | ||
* @param string $objectType | ||
* | ||
* @return string | ||
*/ | ||
public function getPresignedUrl(string $fileName, string $objectType): string; | ||
|
||
/** | ||
* Specification: | ||
* - Returns the S3 object URL for the given file name. | ||
* | ||
* @api | ||
* | ||
* @param string $fileName | ||
* @param string $objectType | ||
* | ||
* @return string | ||
*/ | ||
public function getS3ObjectUrl(string $fileName, string $objectType): string; | ||
|
||
/** | ||
* Specification: | ||
* - Deletes the S3 object for the given path. | ||
* | ||
* @api | ||
* | ||
* @param string $objectType | ||
* @param string $path | ||
* | ||
* @return void | ||
*/ | ||
public function deleteS3Object(string $objectType, string $path): void; | ||
|
||
/** | ||
* Specification: | ||
* - Registers the stream wrapper for the S3 client. | ||
* | ||
* @api | ||
* | ||
* @param string $objectType | ||
* | ||
* @return void | ||
*/ | ||
public function registerStreamWrapper(string $objectType): void; | ||
|
||
/** | ||
* Specification: | ||
* - Returns the CDN URL for the given file name and object type. | ||
* | ||
* @api | ||
* | ||
* @param string $fileName | ||
* @param string $objectType | ||
* | ||
* @return string | ||
*/ | ||
public function getCdnUrl(string $fileName, string $objectType): string; | ||
} |
Oops, something went wrong.