Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

Commit

Permalink
Add support to set the SSL connection option (sqlectron/sqlectron-gui#72
Browse files Browse the repository at this point in the history
)
  • Loading branch information
maxcnunes committed Dec 15, 2015
1 parent 81ec8f5 commit 5aac85e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions spec/servers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('servers', () => {
const newServer = {
'name': 'My New Mysql Server',
'client': 'mysql',
'ssl': true,
'host': '10.10.10.15',
'port': 3306,
'database': 'authentication',
Expand All @@ -43,6 +44,7 @@ describe('servers', () => {
id,
'name': 'mysql-vm',
'client': 'mysql',
'ssl': false,
'host': '10.10.10.10',
'port': 3306,
'database': 'mydb',
Expand All @@ -65,6 +67,7 @@ describe('servers', () => {
const newServer = {
'name': 'My New Mysql Server',
'client': 'mysql',
'ssl': false,
'host': '10.10.10.15',
'port': 3306,
'database': 'authentication',
Expand All @@ -87,6 +90,7 @@ describe('servers', () => {
id,
'name': 'mysql-vm',
'client': 'mysql',
'ssl': false,
'host': '10.10.10.10',
'port': 3306,
'database': 'mydb',
Expand Down
5 changes: 5 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ export async function prepare() {
const result = await readJSONFile(filename);

result.servers = result.servers.map(srv => {
// ensure all server has an unique id
if (!srv.id) { srv.id = uuid.v4(); }

// ensure all servers has the new fileld SSL
if (srv.ssl === undefined) { srv.ssl = false; }

return srv;
});
await writeJSONFile(filename, result);
Expand Down
9 changes: 9 additions & 0 deletions src/db/clients/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,14 @@ function _configDatabase(serverInfo, databaseName, localPort) {
multipleStatements: true,
};

if (serverInfo.ssl) {
serverInfo.ssl = {
// It is not the best recommend way to use SSL with node-mysql
// https://github.com/felixge/node-mysql#ssl-options
// But this way we have compatibility with all clients.
rejectUnauthorized: false,
};
}

return config;
}
1 change: 1 addition & 0 deletions src/db/clients/postgresql.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ function _configDatabase(serverInfo, databaseName, localPort) {
const config = {
host,
port,
ssl: serverInfo.ssl,
user: serverInfo.user,
password: serverInfo.password,
database: databaseName,
Expand Down
3 changes: 2 additions & 1 deletion src/db/clients/sqlserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ const _configDatabase = (serverInfo, databaseName) => {
database: databaseName,
port,
options: {
encrypt: true,
encrypt: serverInfo.ssl,
},
};

return config;
};

Expand Down
3 changes: 3 additions & 0 deletions src/validators/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ const SERVER_SCHEMA = {
{ validator: Valida.Validator.required },
{ validator: clientValidator },
],
ssl: [
{ validator: Valida.Validator.required },
],
host: [
{ sanitizer: Valida.Sanitizer.trim },
{ validator: Valida.Validator.len, min: 1, max: 250 },
Expand Down

0 comments on commit 5aac85e

Please sign in to comment.