Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Migrate/Command/AbstractEnvCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ protected function init(InputInterface $input, OutputInterface $output, $env = n
$username = ArrayUtil::get($conf['connection'], 'username');
$password = ArrayUtil::get($conf['connection'], 'password');
$charset = ArrayUtil::get($conf['connection'], 'charset');
$sslCert = ArrayUtil::get($conf['connection'], 'cert');
$sslCertVerify = ArrayUtil::get($conf['connection'], 'cert-verify') || false;
$sslKey = ArrayUtil::get($conf['connection'], 'ssl-key');
$sslSecret = ArrayUtil::get($conf['connection'], 'ssl-secret');

$uri = $driver;
$opt = array();

if ($driver == 'sqlite') {
$uri .= ":$dbname";
Expand All @@ -89,6 +94,22 @@ protected function init(InputInterface $input, OutputInterface $output, $env = n
$uri .= ($host === null) ? '' : ";host=$host";
$uri .= ($port === null) ? '' : ";port=$port";
$uri .= ($charset === null) ? '' : ";charset=$charset";

// add an ssl cert
if (!empty($sslCert)) {
$opt['PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT'] => "'" . $sslCert . "'";
$opt['PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT'] => "'" . $sslCertVerify . "'";
}

// add ssl an key
if (!empty($sslKey)) {
$opt['PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT'] => "'" . $sslKey . "'";
}

// add ssl an secret
if (!empty($sslSecret)) {
$opt['PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT'] => "'" . $sslSecret . "'";
}
}
$this->db = new \PDO(
$uri,
Expand Down
28 changes: 28 additions & 0 deletions Migrate/Command/AddEnvCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,30 @@ protected function execute(InputInterface $input, OutputInterface $output)
);
$defaultEditor = $questions->ask($input, $output, $defaultEditorQuestion);

$sslCertQuestion = new Question(
"Please enter the path and name of the SSL certificate to use (if any): ",
"vim"
);
$sslCert = $questions->ask($input, $output, $sslCertQuestion);

$sslCertVerifyQuestion = new Question(
"Please enter whether to verify the SSL certificate <info>(default false)</info>: ",
"vim"
);
$sslCertVerify = $questions->ask($input, $output, $sslCertVerifyQuestion);

$sslKeyQuestion = new Question(
"Please enter the text editor to use by default <info>(default vim)</info>: ",
"vim"
);
$sslKey = $questions->ask($input, $output, $sslKeyQuestion);

$sslSecretQuestion = new Question(
"Please enter the text editor to use by default <info>(default vim)</info>: ",
"vim"
);
$sslSecret = $questions->ask($input, $output, $sslSecretQuestion);

$confTemplate = file_get_contents(__DIR__ . '/../../templates/env.' . $format . '.tpl');
$confTemplate = str_replace('{DRIVER}', $driver, $confTemplate);
$confTemplate = str_replace('{HOST}', $dbHost, $confTemplate);
Expand All @@ -111,6 +135,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$confTemplate = str_replace('{CHARSET}', $dbCharset, $confTemplate);
$confTemplate = str_replace('{CHANGELOG}', $changelogTable, $confTemplate);
$confTemplate = str_replace('{EDITOR}', $defaultEditor, $confTemplate);
$confTemplate = str_replace('{SSLCERT}', $sslCert, $confTemplate);
$confTemplate = str_replace('{SSLCERTVERIFY}', $sslCertVerify, $confTemplate);
$confTemplate = str_replace('{SSLKEY}', $sslKey, $confTemplate);
$confTemplate = str_replace('{SSLSECRET}', $sslSecret, $confTemplate);

file_put_contents($envConfigFile, $confTemplate);
}
Expand Down
6 changes: 5 additions & 1 deletion templates/env.json.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"port": "{PORT}",
"username": "{USERNAME}",
"password": "{PASSWORD}",
"database": "{DATABASE}"
"database": "{DATABASE}",
"ssl-cert": "{SSLCERT}",
"ssl-cert-verify": "{SSLCERTVERIFY}",
"ssl-key": "{SSLKEY}",
"ssl-secret": "{SSLSECRET}",
},
"changelog": "{CHANGELOG}",
"default_editor": "{EDITOR}"
Expand Down
6 changes: 5 additions & 1 deletion templates/env.php.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ return [
"port" => "{PORT}",
"username" => "{USERNAME}",
"password" => "{PASSWORD}",
"database" => "{DATABASE}"
"database" => "{DATABASE}",
"ssl-cert" => "{SSLCERT}",
"ssl-cert-verify" => "{SSLCERTVERIFY}",
"ssl-key" => "{SSLKEY}",
"ssl-secret" => "{SSLSECRET}",
],
"changelog" => "{CHANGELOG}",
"default_editor" => "{EDITOR}"
Expand Down
18 changes: 11 additions & 7 deletions templates/env.yml.tpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
connection:
host: {HOST}
driver: {DRIVER}
port: {PORT}
username: {USERNAME}
password: {PASSWORD}
database: {DATABASE}
charset: {CHARSET}
host: {HOST}
driver: {DRIVER}
port: {PORT}
username: {USERNAME}
password: {PASSWORD}
database: {DATABASE}
charset: {CHARSET}
ssl-cert: {SSLCERT}
ssl-cert: {SSLCERTVERIFY}
ssl-key: {SSLKEY}
ssl-secret: {SSLSECRET}

changelog: {CHANGELOG}
default_editor: {EDITOR}