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
41 changes: 20 additions & 21 deletions Migrate/Command/AbstractEnvCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,12 @@ 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');
$sslCaCert = ArrayUtil::get($conf['connection'], 'ssl-ca-cert');
$sslCert = ArrayUtil::get($conf['connection'], 'ssl-cert');
$sslKey = ArrayUtil::get($conf['connection'], 'ssl-key');

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

if ($driver == 'sqlite') {
$uri .= ":$dbname";
Expand All @@ -95,27 +94,27 @@ protected function init(InputInterface $input, OutputInterface $output, $env = n
$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 . "'";
}
// add an ssl ca cert
if (!empty($sslCaCert)) {
$opt[\PDO::MYSQL_ATTR_SSL_CA] = $sslCaCert;
}

// add an ssl cert
if (!empty($sslCert)) {
$opt[\PDO::MYSQL_ATTR_SSL_CERT] = $sslCert;
}

// add an ssl key
if (!empty($sslKey)) {
$opt[\PDO::MYSQL_ATTR_SSL_KEY] = $sslKey;
}
}

$this->db = new \PDO(
$uri,
$username,
$password,
array()
$opt
);

$output->writeln('<info>connected</info>');
Expand Down
33 changes: 13 additions & 20 deletions Migrate/Command/AddEnvCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,24 @@ 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): ",
$sslCaCertQuestion = new Question(
"Please enter the path and name of the SSL certificate authority certificate to use (if any): ",
"vim"
);
$sslCert = $questions->ask($input, $output, $sslCertQuestion);
$sslCaCert = $questions->ask($input, $output, $sslCaCertQuestion);

$sslCertVerifyQuestion = new Question(
"Please enter whether to verify the SSL certificate <info>(default false)</info>: ",
"vim"
$sslCertQuestion = new Question(
"Please enter the path and name of the SSL certificate to use (if any): ",
""
);
$sslCertVerify = $questions->ask($input, $output, $sslCertVerifyQuestion);
$sslCert = $questions->ask($input, $output, $sslCertQuestion);

$sslKeyQuestion = new Question(
"Please enter the text editor to use by default <info>(default vim)</info>: ",
"vim"
$sslKeyQuestion = new Question(
"Please enter the path and name of the SSL certificate key to use (if any): ",
""
);
$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 @@ -135,10 +129,9 @@ 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);
$confTemplate = str_replace('{SSLCACERT}', $sslCaCert, $confTemplate);
$confTemplate = str_replace('{SSLCERT}', $sslCert, $confTemplate);
$confTemplate = str_replace('{SSLKEY}', $sslKey, $confTemplate);

file_put_contents($envConfigFile, $confTemplate);
}
Expand Down
7 changes: 3 additions & 4 deletions templates/env.json.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
"username": "{USERNAME}",
"password": "{PASSWORD}",
"database": "{DATABASE}",
"ssl-cert": "{SSLCERT}",
"ssl-cert-verify": "{SSLCERTVERIFY}",
"ssl-key": "{SSLKEY}",
"ssl-secret": "{SSLSECRET}",
"ssl-ca-cert": "{SSLCACERT}",
"ssl-cert": "{SSLCERT}",
"ssl-key": "{SSLKEY}",
},
"changelog": "{CHANGELOG}",
"default_editor": "{EDITOR}"
Expand Down
7 changes: 3 additions & 4 deletions templates/env.php.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ return [
"username" => "{USERNAME}",
"password" => "{PASSWORD}",
"database" => "{DATABASE}",
"ssl-cert" => "{SSLCERT}",
"ssl-cert-verify" => "{SSLCERTVERIFY}",
"ssl-key" => "{SSLKEY}",
"ssl-secret" => "{SSLSECRET}",
"ssl-ca-cert" => "{SSLCACERT}",
"ssl-cert" => "{SSLCERT}",
"ssl-key" => "{SSLKEY}",
],
"changelog" => "{CHANGELOG}",
"default_editor" => "{EDITOR}"
Expand Down
7 changes: 3 additions & 4 deletions templates/env.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ connection:
password: {PASSWORD}
database: {DATABASE}
charset: {CHARSET}
ssl-cert: {SSLCERT}
ssl-cert: {SSLCERTVERIFY}
ssl-key: {SSLKEY}
ssl-secret: {SSLSECRET}
ssl-ca-cert: {SSLCACERT}
ssl-cert: {SSLCERT}
ssl-key: {SSLKEY}

changelog: {CHANGELOG}
default_editor: {EDITOR}