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',
|
type: 'string',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
rows: 4,
|
rows: 4,
|
||||||
|
password: true,
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
|
|
@ -47,6 +47,14 @@ async function resolveHomeDir(
|
||||||
return path;
|
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 {
|
export class Ssh implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
displayName: 'SSH',
|
displayName: 'SSH',
|
||||||
|
@ -76,6 +84,7 @@ export class Ssh implements INodeType {
|
||||||
{
|
{
|
||||||
name: 'sshPrivateKey',
|
name: 'sshPrivateKey',
|
||||||
required: true,
|
required: true,
|
||||||
|
testedBy: 'sshConnectionTest',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
authentication: ['privateKey'],
|
authentication: ['privateKey'],
|
||||||
|
@ -297,7 +306,7 @@ export class Ssh implements INodeType {
|
||||||
} else {
|
} else {
|
||||||
const { path } = await tmpFile({ prefix: 'n8n-ssh-' });
|
const { path } = await tmpFile({ prefix: 'n8n-ssh-' });
|
||||||
temporaryFiles.push(path);
|
temporaryFiles.push(path);
|
||||||
await writeFile(path, credentials.privateKey as string);
|
await writeFile(path, sanitizePrivateKey(credentials.privateKey as string));
|
||||||
|
|
||||||
const options: Config = {
|
const options: Config = {
|
||||||
host: credentials.host as string,
|
host: credentials.host as string,
|
||||||
|
@ -358,7 +367,7 @@ export class Ssh implements INodeType {
|
||||||
|
|
||||||
const { path } = await tmpFile({ prefix: 'n8n-ssh-' });
|
const { path } = await tmpFile({ prefix: 'n8n-ssh-' });
|
||||||
temporaryFiles.push(path);
|
temporaryFiles.push(path);
|
||||||
await writeFile(path, credentials.privateKey as string);
|
await writeFile(path, sanitizePrivateKey(credentials.privateKey as string));
|
||||||
|
|
||||||
const options: Config = {
|
const options: Config = {
|
||||||
host: credentials.host as string,
|
host: credentials.host as string,
|
||||||
|
|
Loading…
Reference in a new issue