mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
fix(SSH Node): Private key field as password and credential test (#6298)
This commit is contained in:
parent
bbe6d4c4db
commit
d5c7e6f2cf
|
@ -35,6 +35,7 @@ export class SshPrivateKey implements ICredentialType {
|
|||
type: 'string',
|
||||
typeOptions: {
|
||||
rows: 4,
|
||||
password: true,
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue