Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SSL support to MySQL.credentials and MySQL.node #1644

Merged
merged 2 commits into from
Apr 14, 2021
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
59 changes: 58 additions & 1 deletion packages/nodes-base/credentials/MySql.credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,63 @@ export class MySql implements ICredentialType {
type: 'number' as NodePropertyTypes,
default: 10000,
description: 'The milliseconds before a timeout occurs during the initial connection to the MySQL server.',
},
},
{
displayName: 'SSL',
name: 'ssl',
type: 'boolean' as NodePropertyTypes,
default: false,
},
{
displayName: 'CA Certificate',
name: 'caCertificate',
typeOptions: {
alwaysOpenEditWindow: true,
password: true,
},
displayOptions: {
show: {
ssl: [
true,
],
},
},
type: 'string' as NodePropertyTypes,
default: '',
},
{
displayName: 'Client Private Key',
name: 'clientPrivateKey',
typeOptions: {
alwaysOpenEditWindow: true,
password: true,
},
displayOptions: {
show: {
ssl: [
true,
],
},
},
type: 'string' as NodePropertyTypes,
default: '',
},
{
displayName: 'Client Certificate',
name: 'clientCertificate',
typeOptions: {
alwaysOpenEditWindow: true,
password: true,
},
displayOptions: {
show: {
ssl: [
true,
],
},
},
type: 'string' as NodePropertyTypes,
default: '',
},
];
}
25 changes: 24 additions & 1 deletion packages/nodes-base/nodes/MySql/MySql.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,30 @@ export class MySql implements INodeType {
throw new Error('No credentials got returned!');
}

const connection = await mysql2.createConnection(credentials);
// Destructuring SSL configuration
const {
ssl,
caCertificate,
clientCertificate,
clientPrivateKey,
...baseCredentials
} = credentials;

if (ssl) {
baseCredentials.ssl = {};

if (caCertificate) {
baseCredentials.ssl.ca = caCertificate;
}

// client certificates might not be required
if (clientCertificate || clientPrivateKey) {
baseCredentials.ssl.cert = clientCertificate;
baseCredentials.ssl.key = clientPrivateKey;
}
}

const connection = await mysql2.createConnection(baseCredentials);
const items = this.getInputData();
const operation = this.getNodeParameter('operation', 0) as string;
let returnItems = [];
Expand Down