Skip to content

Commit b021827

Browse files
committed
B2B-2134: [AWS S3] setup:config:set command is removing S3 configuration
Added code
1 parent 031fe7e commit b021827

File tree

2 files changed

+121
-3
lines changed

2 files changed

+121
-3
lines changed

app/code/Magento/RemoteStorage/Setup/ConfigOptionsList.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ public function getOptions(): array
142142
*/
143143
public function createConfig(array $options, DeploymentConfig $deploymentConfig): array
144144
{
145+
$isRemoteStorageDeploymentConfigExists = isset($deploymentConfig->getConfigData()['remote_storage']);
146+
147+
// if remote storage config is already present and driver is not in $options, return early to prevent overwrite
148+
if ($isRemoteStorageDeploymentConfigExists && !isset($options[self::OPTION_REMOTE_STORAGE_DRIVER])) {
149+
return [];
150+
}
151+
145152
$driver = $options[self::OPTION_REMOTE_STORAGE_DRIVER] ?? DriverPool::FILE;
146153

147154
if ($driver === DriverPool::FILE) {

app/code/Magento/RemoteStorage/Test/Unit/Setup/ConfigOptionsListTest.php

Lines changed: 114 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ public function testValidate(array $input, bool $isDeploymentConfigExists, array
7171
->willReturn($isDeploymentConfigExists);
7272

7373
$isConnectionToBeTested = $isDeploymentConfigExists && isset(
74-
$input['remote-storage-region'],
75-
$input['remote-storage-bucket']
76-
);
74+
$input['remote-storage-region'],
75+
$input['remote-storage-bucket']
76+
);
7777

7878
if ($isConnectionToBeTested) {
7979
$driverFactoryMock = $this->getMockBuilder(DriverFactoryInterface::class)
@@ -188,4 +188,115 @@ public function validateDataProvider()
188188
],
189189
];
190190
}
191+
192+
/**
193+
* @param array $options
194+
* @param array $deploymentConfig
195+
* @param array $expectedConfigArr
196+
* @dataProvider createConfigProvider
197+
*/
198+
public function testCreateConfig(array $options, array $deploymentConfig, array $expectedConfigArr)
199+
{
200+
$deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
201+
->disableOriginalConstructor()
202+
->getMock();
203+
204+
$deploymentConfigMock
205+
->expects(static::once())
206+
->method('getConfigData')
207+
->willReturn($deploymentConfig);
208+
209+
$configDataListArr = $this->configOptionsList->createConfig($options, $deploymentConfigMock);
210+
211+
if (count($configDataListArr)) {
212+
$this->assertCount(1, $configDataListArr);
213+
$configDataArr = $configDataListArr[0]->getData();
214+
} else {
215+
$configDataArr = [];
216+
}
217+
218+
$this->assertEquals(
219+
$expectedConfigArr,
220+
$configDataArr
221+
);
222+
}
223+
224+
/**
225+
* @return array
226+
*/
227+
public function createConfigProvider()
228+
{
229+
return [
230+
'Remote Storage Options Missing and Remote Storage Deployment Config Present' => [
231+
[
232+
'backend-frontname' => 'admin2022',
233+
],
234+
[
235+
'remote_storage' => [
236+
'driver' => 'aws-s3',
237+
]
238+
],
239+
// no config data will be passed to write to deployment config
240+
[]
241+
],
242+
'Remote Storage Options Missing and Remote Storage Deployment Config Missing' => [
243+
[
244+
'backend-frontname' => 'admin2022',
245+
],
246+
[],
247+
[
248+
// will create default config with file driver
249+
'remote_storage' => [
250+
'driver' => 'file',
251+
]
252+
]
253+
],
254+
'Remote Storage Options Present and Remote Storage Deployment Config Missing' => [
255+
[
256+
'remote-storage-driver' => 'aws-s3',
257+
'remote-storage-region' => 'us-east-1',
258+
'remote-storage-bucket' => 'bucket1',
259+
'remote-storage-prefix' => 'pre_',
260+
],
261+
[],
262+
[
263+
'remote_storage' => [
264+
'driver' => 'aws-s3',
265+
'prefix' => 'pre_',
266+
'config' => [
267+
'bucket' => 'bucket1',
268+
'region' => 'us-east-1',
269+
],
270+
]
271+
]
272+
],
273+
'Remote Storage Options Present and Remote Storage Deployment Config Present' => [
274+
[
275+
'remote-storage-driver' => 'aws-s3',
276+
'remote-storage-region' => 'us-east-1_NEW',
277+
'remote-storage-bucket' => 'bucket_NEW',
278+
],
279+
[
280+
'remote_storage' => [
281+
'driver' => 'aws-s3',
282+
'prefix' => 'pre_OLD',
283+
'config' => [
284+
'bucket' => 'bucket_OLD',
285+
'region' => 'us-east-1_OLD',
286+
],
287+
]
288+
],
289+
[
290+
'remote_storage' => [
291+
'driver' => 'aws-s3',
292+
// prefix should be removed as it was not passed in options
293+
'config' => [
294+
'bucket' => 'bucket_NEW',
295+
'region' => 'us-east-1_NEW',
296+
],
297+
]
298+
]
299+
],
300+
];
301+
}
191302
}

0 commit comments

Comments
 (0)