Add SSL support to MySQL.credentials and MySQL.node (#1644)

* added SSL support to MySQL.credentials and MySQL.node

*  hide certificate field data, change CA name

Co-authored-by: ahsan-virani <ahsan.virani@gmail.com>
This commit is contained in:
Cassiano Vailati 2021-04-14 13:43:12 +02:00 committed by GitHub
parent 315d3b59f5
commit 41088fcd9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 82 additions and 2 deletions

View file

@ -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: '',
},
];
}

View file

@ -218,7 +218,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 = [];