fix(SSH Node): Private key field as password and credential test (#6298)

This commit is contained in:
Michael Kret 2023-05-23 12:01:24 +03:00 committed by GitHub
parent bbe6d4c4db
commit d5c7e6f2cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -35,6 +35,7 @@ export class SshPrivateKey implements ICredentialType {
type: 'string',
typeOptions: {
rows: 4,
password: true,
},
default: '',
},

View file

@ -47,6 +47,14 @@ async function resolveHomeDir(
return path;
}
function sanitizePrivateKey(privateKey: string) {
const [openSshKey, bodySshKey, endSshKey] = privateKey
.split('-----')
.filter((item) => item !== '');
return `-----${openSshKey}-----\n${bodySshKey.replace(/ /g, '\n')}\n-----${endSshKey}-----`;
}
export class Ssh implements INodeType {
description: INodeTypeDescription = {
displayName: 'SSH',
@ -76,6 +84,7 @@ export class Ssh implements INodeType {
{
name: 'sshPrivateKey',
required: true,
testedBy: 'sshConnectionTest',
displayOptions: {
show: {
authentication: ['privateKey'],
@ -297,7 +306,7 @@ export class Ssh implements INodeType {
} else {
const { path } = await tmpFile({ prefix: 'n8n-ssh-' });
temporaryFiles.push(path);
await writeFile(path, credentials.privateKey as string);
await writeFile(path, sanitizePrivateKey(credentials.privateKey as string));
const options: Config = {
host: credentials.host as string,
@ -358,7 +367,7 @@ export class Ssh implements INodeType {
const { path } = await tmpFile({ prefix: 'n8n-ssh-' });
temporaryFiles.push(path);
await writeFile(path, credentials.privateKey as string);
await writeFile(path, sanitizePrivateKey(credentials.privateKey as string));
const options: Config = {
host: credentials.host as string,