Skip to content

Commit 9804ad9

Browse files
[AWS S3] MC-37479: Support by Magento Content Design (#6179)
* MC-37479: Support by Magento Content Design
1 parent e8f5cd5 commit 9804ad9

File tree

19 files changed

+903
-333
lines changed

19 files changed

+903
-333
lines changed

app/code/Magento/AwsS3/Driver/AwsS3.php

Lines changed: 125 additions & 84 deletions
Large diffs are not rendered by default.

app/code/Magento/AwsS3/Driver/AwsS3Factory.php

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,35 @@
77

88
namespace Magento\AwsS3\Driver;
99

10+
use Aws\S3\S3Client;
11+
use League\Flysystem\AwsS3v3\AwsS3Adapter;
1012
use Magento\AwsS3\Model\Config;
11-
1213
use Magento\Framework\Filesystem\DriverInterface;
14+
use Magento\Framework\ObjectManagerInterface;
1315
use Magento\RemoteStorage\Driver\DriverFactoryInterface;
1416

1517
/**
1618
* Creates a pre-configured instance of AWS S3 driver.
1719
*/
1820
class AwsS3Factory implements DriverFactoryInterface
1921
{
22+
/**
23+
* @var ObjectManagerInterface
24+
*/
25+
private $objectManager;
26+
2027
/**
2128
* @var Config
2229
*/
2330
private $config;
2431

2532
/**
33+
* @param ObjectManagerInterface $objectManager
2634
* @param Config $config
2735
*/
28-
public function __construct(Config $config)
36+
public function __construct(ObjectManagerInterface $objectManager, Config $config)
2937
{
38+
$this->objectManager = $objectManager;
3039
$this->config = $config;
3140
}
3241

@@ -37,11 +46,33 @@ public function __construct(Config $config)
3746
*/
3847
public function create(): DriverInterface
3948
{
40-
return new AwsS3(
41-
$this->config->getRegion(),
42-
$this->config->getBucket(),
43-
$this->config->getAccessKey(),
44-
$this->config->getSecretKey()
49+
$config = [
50+
'region' => $this->config->getRegion(),
51+
'version' => 'latest'
52+
];
53+
54+
$key = $this->config->getAccessKey();
55+
$secret = $this->config->getSecretKey();
56+
57+
if ($key && $secret) {
58+
$config['credentials'] = [
59+
'key' => $key,
60+
'secret' => $secret,
61+
];
62+
}
63+
64+
return $this->objectManager->create(
65+
AwsS3::class,
66+
[
67+
'adapter' => $this->objectManager->create(
68+
AwsS3Adapter::class,
69+
[
70+
'client' => $this->objectManager->create(S3Client::class, ['args' => $config]),
71+
'bucket' => $this->config->getBucket(),
72+
'prefix' => $this->config->getPrefix()
73+
]
74+
)
75+
]
4576
);
4677
}
4778
}

app/code/Magento/AwsS3/Model/Config.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@
77

88
namespace Magento\AwsS3\Model;
99

10-
use Magento\Framework\App\Config\ScopeConfigInterface;
10+
use Magento\Framework\App\DeploymentConfig;
1111

1212
/**
1313
* Configuration for AWS S3.
1414
*/
1515
class Config
1616
{
17-
public const PATH_DRIVER = 'system/file_system/driver';
18-
public const PATH_REGION = 'system/file_system/region';
19-
public const PATH_BUCKET = 'system/file_system/bucket';
20-
public const PATH_ACCESS_KEY = 'system/file_system/access_key';
21-
public const PATH_SECRET_KEY = 'system/file_system/secret_key';
17+
public const PATH_REGION = 'remote_storage/region';
18+
public const PATH_BUCKET = 'remote_storage/bucket';
19+
public const PATH_ACCESS_KEY = 'remote_storage/access_key';
20+
public const PATH_SECRET_KEY = 'remote_storage/secret_key';
21+
public const PATH_PREFIX = 'remote_storage/prefix';
2222

2323
/**
24-
* @var ScopeConfigInterface
24+
* @var DeploymentConfig
2525
*/
2626
private $config;
2727

2828
/**
29-
* @param ScopeConfigInterface $config
29+
* @param DeploymentConfig $config
3030
*/
31-
public function __construct(ScopeConfigInterface $config)
31+
public function __construct(DeploymentConfig $config)
3232
{
3333
$this->config = $config;
3434
}
@@ -40,7 +40,7 @@ public function __construct(ScopeConfigInterface $config)
4040
*/
4141
public function getRegion(): string
4242
{
43-
return (string)$this->config->getValue(self::PATH_REGION);
43+
return (string)$this->config->get(self::PATH_REGION);
4444
}
4545

4646
/**
@@ -50,7 +50,7 @@ public function getRegion(): string
5050
*/
5151
public function getBucket(): string
5252
{
53-
return (string)$this->config->getValue(self::PATH_BUCKET);
53+
return (string)$this->config->get(self::PATH_BUCKET);
5454
}
5555

5656
/**
@@ -60,7 +60,7 @@ public function getBucket(): string
6060
*/
6161
public function getAccessKey(): string
6262
{
63-
return (string)$this->config->getValue(self::PATH_ACCESS_KEY);
63+
return (string)$this->config->get(self::PATH_ACCESS_KEY);
6464
}
6565

6666
/**
@@ -70,6 +70,16 @@ public function getAccessKey(): string
7070
*/
7171
public function getSecretKey(): string
7272
{
73-
return (string)$this->config->getValue(self::PATH_SECRET_KEY);
73+
return (string)$this->config->get(self::PATH_SECRET_KEY);
74+
}
75+
76+
/**
77+
* Retrieves prefix.
78+
*
79+
* @return string
80+
*/
81+
public function getPrefix(): string
82+
{
83+
return (string)$this->config->get(self::PATH_PREFIX, '');
7484
}
7585
}

0 commit comments

Comments
 (0)