Skip to content

Commit 41e1793

Browse files
committed
Convert a PR for 2.2-develop into 2.3-develop
1 parent 548ef66 commit 41e1793

File tree

13 files changed

+333
-12
lines changed

13 files changed

+333
-12
lines changed

lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ConfigOptionsListConstants
1919
const CONFIG_PATH_CRYPT_KEY = 'crypt/key';
2020
const CONFIG_PATH_SESSION_SAVE = 'session/save';
2121
const CONFIG_PATH_RESOURCE_DEFAULT_SETUP = 'resource/default_setup/connection';
22+
const CONFIG_PATH_DB_CONNECTION_DEFAULT_DRIVER_OPTIONS = 'db/connection/default/driver_options';
2223
const CONFIG_PATH_DB_CONNECTION_DEFAULT = 'db/connection/default';
2324
const CONFIG_PATH_DB_CONNECTIONS = 'db/connection';
2425
const CONFIG_PATH_DB_PREFIX = 'db/table_prefix';
@@ -62,6 +63,10 @@ class ConfigOptionsListConstants
6263
const INPUT_KEY_DB_MODEL = 'db-model';
6364
const INPUT_KEY_DB_INIT_STATEMENTS = 'db-init-statements';
6465
const INPUT_KEY_DB_ENGINE = 'db-engine';
66+
const INPUT_KEY_DB_SSL_KEY = 'db-ssl-key';
67+
const INPUT_KEY_DB_SSL_CERT = 'db-ssl-cert';
68+
const INPUT_KEY_DB_SSL_CA = 'db-ssl-ca';
69+
const INPUT_KEY_DB_SSL_VERIFY = 'db-ssl-verify';
6570
const INPUT_KEY_RESOURCE = 'resource';
6671
const INPUT_KEY_SKIP_DB_VALIDATION = 'skip-db-validation';
6772
const INPUT_KEY_CACHE_HOSTS = 'http-cache-hosts';
@@ -102,6 +107,16 @@ class ConfigOptionsListConstants
102107
const KEY_MODEL = 'model';
103108
const KEY_INIT_STATEMENTS = 'initStatements';
104109
const KEY_ACTIVE = 'active';
110+
const KEY_DRIVER_OPTIONS = 'driver_options';
111+
/**#@-*/
112+
113+
/**#@+
114+
* Array keys for database driver options configurations
115+
*/
116+
const KEY_MYSQL_SSL_KEY = \PDO::MYSQL_ATTR_SSL_KEY;
117+
const KEY_MYSQL_SSL_CERT = \PDO::MYSQL_ATTR_SSL_CERT;
118+
const KEY_MYSQL_SSL_CA = \PDO::MYSQL_ATTR_SSL_CA;
119+
const KEY_MYSQL_SSL_VERIFY = \PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT;
105120
/**#@-*/
106121

107122
/**

setup/src/Magento/Setup/Controller/DatabaseCheck.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Setup\Controller;
77

8+
use Magento\Framework\Config\ConfigOptionsListConstants;
89
use Magento\Setup\Validator\DbValidator;
910
use Zend\Json\Json;
1011
use Zend\Mvc\Controller\AbstractActionController;
@@ -37,12 +38,43 @@ public function indexAction()
3738
try {
3839
$params = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
3940
$password = isset($params['password']) ? $params['password'] : '';
40-
$this->dbValidator->checkDatabaseConnection($params['name'], $params['host'], $params['user'], $password);
41+
$driverOptions = [];
42+
if ($this->isDriverOptionsGiven($params)) {
43+
if (empty($params['driverOptionsSslVerify'])) {
44+
$params['driverOptionsSslVerify'] = 0;
45+
}
46+
$driverOptions = [
47+
ConfigOptionsListConstants::KEY_MYSQL_SSL_KEY => $params['driverOptionsSslKey'],
48+
ConfigOptionsListConstants::KEY_MYSQL_SSL_CERT => $params['driverOptionsSslCert'],
49+
ConfigOptionsListConstants::KEY_MYSQL_SSL_CA => $params['driverOptionsSslCa'],
50+
ConfigOptionsListConstants::KEY_MYSQL_SSL_VERIFY => (int) $params['driverOptionsSslVerify'],
51+
];
52+
}
53+
$this->dbValidator->checkDatabaseConnectionWithDriverOptions(
54+
$params['name'],
55+
$params['host'],
56+
$params['user'],
57+
$password,
58+
$driverOptions
59+
);
4160
$tablePrefix = isset($params['tablePrefix']) ? $params['tablePrefix'] : '';
4261
$this->dbValidator->checkDatabaseTablePrefix($tablePrefix);
4362
return new JsonModel(['success' => true]);
4463
} catch (\Exception $e) {
4564
return new JsonModel(['success' => false, 'error' => $e->getMessage()]);
4665
}
4766
}
67+
68+
/**
69+
* @param array $params
70+
* @return boolean
71+
*/
72+
private function isDriverOptionsGiven($params)
73+
{
74+
return !(
75+
empty($params['driverOptionsSslKey']) ||
76+
empty($params['driverOptionsSslCert']) ||
77+
empty($params['driverOptionsSslCa'])
78+
);
79+
}
4880
}

setup/src/Magento/Setup/Model/ConfigGenerator.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\Config\ConfigOptionsListConstants;
1515
use Magento\Framework\App\State;
1616
use Magento\Framework\Math\Random;
17+
use Magento\Setup\Model\ConfigOptionsList\DriverOptions;
1718

1819
/**
1920
* Creates deployment config data based on user input array
@@ -61,6 +62,11 @@ class ConfigGenerator
6162
*/
6263
private $cryptKeyGenerator;
6364

65+
/**
66+
* @var DriverOptions
67+
*/
68+
private $driverOptions;
69+
6470
/**
6571
* Constructor
6672
*
@@ -73,12 +79,14 @@ public function __construct(
7379
Random $random,
7480
DeploymentConfig $deploymentConfig,
7581
ConfigDataFactory $configDataFactory = null,
76-
CryptKeyGeneratorInterface $cryptKeyGenerator = null
82+
CryptKeyGeneratorInterface $cryptKeyGenerator = null,
83+
DriverOptions $driverOptions = null
7784
) {
7885
$this->random = $random;
7986
$this->deploymentConfig = $deploymentConfig;
8087
$this->configDataFactory = $configDataFactory ?? ObjectManager::getInstance()->get(ConfigDataFactory::class);
8188
$this->cryptKeyGenerator = $cryptKeyGenerator ?? ObjectManager::getInstance()->get(CryptKeyGenerator::class);
89+
$this->driverOptions = $driverOptions ?? ObjectManager::getInstance()->get(DriverOptions::class);
8290
}
8391

8492
/**
@@ -179,6 +187,9 @@ public function createDbConfig(array $data)
179187
$configData->set($dbConnectionPrefix . ConfigOptionsListConstants::KEY_ACTIVE, '1');
180188
}
181189

190+
$driverOptions = $this->driverOptions->getDriverOptions($data);
191+
$configData->set($dbConnectionPrefix . ConfigOptionsListConstants::KEY_DRIVER_OPTIONS, $driverOptions);
192+
182193
return $configData;
183194
}
184195

setup/src/Magento/Setup/Model/ConfigOptionsList.php

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Setup\Option\FlagConfigOption;
1313
use Magento\Framework\Setup\Option\SelectConfigOption;
1414
use Magento\Framework\Setup\Option\TextConfigOption;
15+
use Magento\Setup\Model\ConfigOptionsList\DriverOptions;
1516
use Magento\Setup\Validator\DbValidator;
1617

1718
/**
@@ -47,19 +48,28 @@ class ConfigOptionsList implements ConfigOptionsListInterface
4748
\Magento\Setup\Model\ConfigOptionsList\PageCache::class
4849
];
4950

51+
/**
52+
* @var DriverOptions
53+
*/
54+
private $driverOptions;
55+
5056
/**
5157
* Constructor
5258
*
5359
* @param ConfigGenerator $configGenerator
5460
* @param DbValidator $dbValidator
5561
*/
56-
public function __construct(ConfigGenerator $configGenerator, DbValidator $dbValidator)
57-
{
62+
public function __construct(
63+
ConfigGenerator $configGenerator,
64+
DbValidator $dbValidator,
65+
DriverOptions $driverOptions = null
66+
) {
5867
$this->configGenerator = $configGenerator;
5968
$this->dbValidator = $dbValidator;
6069
foreach ($this->configOptionsListClasses as $className) {
6170
$this->configOptionsCollection[] = \Magento\Framework\App\ObjectManager::getInstance()->get($className);
6271
}
72+
$this->driverOptions = $driverOptions ?? \Magento\Framework\App\ObjectManager::getInstance()->get(DriverOptions::class);
6373
}
6474

6575
/**
@@ -150,6 +160,36 @@ public function getOptions()
150160
ConfigOptionsListConstants::CONFIG_PATH_CACHE_HOSTS,
151161
'http Cache hosts'
152162
),
163+
new TextConfigOption(
164+
ConfigOptionsListConstants::INPUT_KEY_DB_SSL_KEY,
165+
TextConfigOption::FRONTEND_WIZARD_TEXT,
166+
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT_DRIVER_OPTIONS .
167+
'/' . ConfigOptionsListConstants::KEY_MYSQL_SSL_KEY,
168+
'Full path of client key file in order to establish db connection through SSL',
169+
null
170+
),
171+
new TextConfigOption(
172+
ConfigOptionsListConstants::INPUT_KEY_DB_SSL_CERT,
173+
TextConfigOption::FRONTEND_WIZARD_TEXT,
174+
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT_DRIVER_OPTIONS .
175+
'/' . ConfigOptionsListConstants::KEY_MYSQL_SSL_CERT,
176+
'Full path of client certificate file in order to establish db connection through SSL',
177+
null
178+
),
179+
new TextConfigOption(
180+
ConfigOptionsListConstants::INPUT_KEY_DB_SSL_CA,
181+
TextConfigOption::FRONTEND_WIZARD_TEXT,
182+
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT_DRIVER_OPTIONS .
183+
'/' . ConfigOptionsListConstants::KEY_MYSQL_SSL_CA,
184+
'Full path of server certificate file in order to establish db connection through SSL',
185+
null
186+
),
187+
new FlagConfigOption(
188+
ConfigOptionsListConstants::INPUT_KEY_DB_SSL_VERIFY,
189+
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT_DRIVER_OPTIONS .
190+
'/' . ConfigOptionsListConstants::KEY_MYSQL_SSL_VERIFY,
191+
'Verify server certification'
192+
),
153193
];
154194

155195
foreach ($this->configOptionsCollection as $configOptionsList) {
@@ -334,12 +374,14 @@ private function validateDbSettings(array $options, DeploymentConfig $deployment
334374
) {
335375
try {
336376
$options = $this->getDbSettings($options, $deploymentConfig);
377+
$driverOptions = $this->driverOptions->getDriverOptions($options);
337378

338-
$this->dbValidator->checkDatabaseConnection(
379+
$this->dbValidator->checkDatabaseConnectionWithDriverOptions(
339380
$options[ConfigOptionsListConstants::INPUT_KEY_DB_NAME],
340381
$options[ConfigOptionsListConstants::INPUT_KEY_DB_HOST],
341382
$options[ConfigOptionsListConstants::INPUT_KEY_DB_USER],
342-
$options[ConfigOptionsListConstants::INPUT_KEY_DB_PASSWORD]
383+
$options[ConfigOptionsListConstants::INPUT_KEY_DB_PASSWORD],
384+
$driverOptions
343385
);
344386
} catch (\Exception $exception) {
345387
$errors[] = $exception->getMessage();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php declare(strict_types=1);
2+
namespace Magento\Setup\Model\ConfigOptionsList;
3+
4+
use Magento\Framework\Config\ConfigOptionsListConstants;
5+
6+
class DriverOptions
7+
{
8+
/**
9+
* @params array $options
10+
* @return array
11+
*/
12+
public function getDriverOptions($options)
13+
{
14+
$driverOptionKeys = [
15+
ConfigOptionsListConstants::KEY_MYSQL_SSL_KEY => ConfigOptionsListConstants::INPUT_KEY_DB_SSL_KEY,
16+
ConfigOptionsListConstants::KEY_MYSQL_SSL_CERT => ConfigOptionsListConstants::INPUT_KEY_DB_SSL_CERT,
17+
ConfigOptionsListConstants::KEY_MYSQL_SSL_CA => ConfigOptionsListConstants::INPUT_KEY_DB_SSL_CA,
18+
ConfigOptionsListConstants::KEY_MYSQL_SSL_VERIFY => ConfigOptionsListConstants::INPUT_KEY_DB_SSL_VERIFY
19+
];
20+
$driverOptions = [];
21+
foreach ($driverOptionKeys as $configKey => $driverOptionKey) {
22+
if ($this->optionExists($options, $driverOptionKey)) {
23+
$driverOptions[$configKey] = $options[$driverOptionKey];
24+
}
25+
}
26+
return $driverOptions;
27+
}
28+
29+
/**
30+
* @param array $options
31+
* @param string $driverOptionKey
32+
* @return bool
33+
*/
34+
private function optionExists($options, $driverOptionKey)
35+
{
36+
return $options[$driverOptionKey] === false || !empty($options[$driverOptionKey]);
37+
}
38+
}

setup/src/Magento/Setup/Model/Installer.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,32 @@ private function deleteDeploymentConfig()
13341334
*/
13351335
private function assertDbAccessible()
13361336
{
1337-
$this->dbValidator->checkDatabaseConnection(
1337+
$driverOptionKeys = [
1338+
ConfigOptionsListConstants::KEY_MYSQL_SSL_KEY =>
1339+
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT_DRIVER_OPTIONS . '/' .
1340+
ConfigOptionsListConstants::KEY_MYSQL_SSL_KEY,
1341+
1342+
ConfigOptionsListConstants::KEY_MYSQL_SSL_CERT =>
1343+
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT_DRIVER_OPTIONS . '/' .
1344+
ConfigOptionsListConstants::KEY_MYSQL_SSL_CERT,
1345+
1346+
ConfigOptionsListConstants::KEY_MYSQL_SSL_CA =>
1347+
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT_DRIVER_OPTIONS . '/' .
1348+
ConfigOptionsListConstants::KEY_MYSQL_SSL_CA,
1349+
1350+
ConfigOptionsListConstants::KEY_MYSQL_SSL_VERIFY =>
1351+
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT_DRIVER_OPTIONS . '/' .
1352+
ConfigOptionsListConstants::KEY_MYSQL_SSL_VERIFY
1353+
];
1354+
$driverOptions = [];
1355+
foreach ($driverOptionKeys as $driverOptionKey => $driverOptionConfig) {
1356+
$config = $this->deploymentConfig->get($driverOptionConfig);
1357+
if ($config !== null) {
1358+
$driverOptions[$driverOptionKey] = $config;
1359+
}
1360+
}
1361+
1362+
$this->dbValidator->checkDatabaseConnectionWithDriverOptions(
13381363
$this->deploymentConfig->get(
13391364
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT .
13401365
'/' . ConfigOptionsListConstants::KEY_NAME
@@ -1350,7 +1375,8 @@ private function assertDbAccessible()
13501375
$this->deploymentConfig->get(
13511376
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT .
13521377
'/' . ConfigOptionsListConstants::KEY_PASSWORD
1353-
)
1378+
),
1379+
$driverOptions
13541380
);
13551381
$prefix = $this->deploymentConfig->get(
13561382
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT .

setup/src/Magento/Setup/Model/RequestDataConverter.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ private function convertDeploymentConfigForm(array $source)
5151
isset($source['db']['tablePrefix']) ? $source['db']['tablePrefix'] : '';
5252
$result[BackendConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME] = isset($source['config']['address']['admin'])
5353
? $source['config']['address']['admin'] : '';
54+
$result[SetupConfigOptionsList::INPUT_KEY_DB_SSL_KEY] = isset($source['db']['driverOptionsSslKey'])
55+
? $source['db']['driverOptionsSslKey'] : '';
56+
$result[SetupConfigOptionsList::INPUT_KEY_DB_SSL_CERT] = isset($source['db']['driverOptionsSslCert'])
57+
? $source['db']['driverOptionsSslCert'] : '';
58+
$result[SetupConfigOptionsList::INPUT_KEY_DB_SSL_CA] = isset($source['db']['driverOptionsSslCa'])
59+
? $source['db']['driverOptionsSslCa'] : '';
60+
$result[SetupConfigOptionsList::INPUT_KEY_DB_SSL_VERIFY] = isset($source['db']['driverOptionsSslVerify'])
61+
? $source['db']['driverOptionsSslVerify'] : '';
5462
$result[SetupConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY] = isset($source['config']['encrypt']['key'])
5563
? $source['config']['encrypt']['key'] : null;
5664
$result[SetupConfigOptionsList::INPUT_KEY_SESSION_SAVE] = isset($source['config']['sessionSave']['type'])

setup/src/Magento/Setup/Test/Unit/Model/ConfigGeneratorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\Config\Data\ConfigData;
1212
use Magento\Framework\Config\Data\ConfigDataFactory;
1313
use Magento\Setup\Model\ConfigGenerator;
14+
use Magento\Setup\Model\ConfigOptionsList\DriverOptions;
1415

1516
class ConfigGeneratorTest extends \PHPUnit\Framework\TestCase
1617
{
@@ -29,6 +30,11 @@ class ConfigGeneratorTest extends \PHPUnit\Framework\TestCase
2930
*/
3031
private $configDataMock;
3132

33+
/**
34+
* @var DriverOptions
35+
*/
36+
private $driverOptionsMock;
37+
3238
public function setUp()
3339
{
3440
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -50,11 +56,17 @@ public function setUp()
5056
$configDataFactoryMock->method('create')
5157
->willReturn($this->configDataMock);
5258

59+
$this->driverOptionsMock = $this->getMockBuilder(DriverOptions::class)
60+
->disableOriginalConstructor()
61+
->setMethods(['getDriverOptions'])
62+
->getMock();
63+
5364
$this->model = $objectManager->getObject(
5465
ConfigGenerator::class,
5566
[
5667
'deploymentConfig' => $this->deploymentConfigMock,
5768
'configDataFactory' => $configDataFactoryMock,
69+
'driverOptions' => $this->driverOptionsMock,
5870
]
5971
);
6072
}

setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,18 @@ class ConfigOptionsListTest extends \PHPUnit\Framework\TestCase
3333
*/
3434
private $dbValidator;
3535

36+
/**
37+
* @var ConfigOptionsList\DriverOptions
38+
*/
39+
private $driverOptionsMock;
40+
3641
protected function setUp()
3742
{
3843
$this->generator = $this->createMock(\Magento\Setup\Model\ConfigGenerator::class);
3944
$this->deploymentConfig = $this->createMock(\Magento\Framework\App\DeploymentConfig::class);
4045
$this->dbValidator = $this->createMock(\Magento\Setup\Validator\DbValidator::class);
41-
$this->object = new ConfigOptionsList($this->generator, $this->dbValidator);
46+
$this->driverOptionsMock = $this->createMock(ConfigOptionsList\DriverOptions::class);
47+
$this->object = new ConfigOptionsList($this->generator, $this->dbValidator, $this->driverOptionsMock);
4248
}
4349

4450
public function testGetOptions()
@@ -155,7 +161,10 @@ private function prepareValidationMocks()
155161
->disableOriginalConstructor()
156162
->getMock();
157163
$this->dbValidator->expects($this->once())->method('checkDatabaseTablePrefix')->willReturn($configDataMock);
158-
$this->dbValidator->expects($this->once())->method('checkDatabaseConnection')->willReturn($configDataMock);
164+
$this->dbValidator
165+
->expects($this->once())
166+
->method('checkDatabaseConnectionWithDriverOptions')
167+
->willReturn($configDataMock);
159168
}
160169

161170
/**

0 commit comments

Comments
 (0)