mirror of https://github.com/certd/certd
perf: ssh登录支持openssh格式私钥、支持私钥密码
parent
fd54c2ffac
commit
5c2c50839a
|
@ -11,6 +11,7 @@ import { CertInfo, CertReader } from '@certd/plugin-cert';
|
||||||
@IsTaskPlugin({
|
@IsTaskPlugin({
|
||||||
name: 'CloudflareDeployToCDN',
|
name: 'CloudflareDeployToCDN',
|
||||||
title: '部署证书到CF CDN',
|
title: '部署证书到CF CDN',
|
||||||
|
desc: '暂未实现,不可用',
|
||||||
default: {
|
default: {
|
||||||
strategy: {
|
strategy: {
|
||||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { AccessInput, IAccess, IsAccess } from '@certd/pipeline';
|
import { AccessInput, IAccess, IsAccess } from '@certd/pipeline';
|
||||||
|
import { ConnectConfig } from 'ssh2';
|
||||||
|
|
||||||
@IsAccess({
|
@IsAccess({
|
||||||
name: 'ssh',
|
name: 'ssh',
|
||||||
|
@ -6,7 +7,7 @@ import { AccessInput, IAccess, IsAccess } from '@certd/pipeline';
|
||||||
desc: '',
|
desc: '',
|
||||||
input: {},
|
input: {},
|
||||||
})
|
})
|
||||||
export class SshAccess implements IAccess {
|
export class SshAccess implements IAccess, ConnectConfig {
|
||||||
@AccessInput({
|
@AccessInput({
|
||||||
title: '主机地址',
|
title: '主机地址',
|
||||||
component: {
|
component: {
|
||||||
|
@ -19,11 +20,12 @@ export class SshAccess implements IAccess {
|
||||||
title: '端口',
|
title: '端口',
|
||||||
value: '22',
|
value: '22',
|
||||||
component: {
|
component: {
|
||||||
|
name: 'a-input-number',
|
||||||
placeholder: '22',
|
placeholder: '22',
|
||||||
},
|
},
|
||||||
rules: [{ required: true, message: '此项必填' }],
|
rules: [{ required: true, message: '此项必填' }],
|
||||||
})
|
})
|
||||||
port!: string;
|
port!: number;
|
||||||
@AccessInput({
|
@AccessInput({
|
||||||
title: '用户名',
|
title: '用户名',
|
||||||
value: 'root',
|
value: 'root',
|
||||||
|
@ -40,14 +42,24 @@ export class SshAccess implements IAccess {
|
||||||
})
|
})
|
||||||
password!: string;
|
password!: string;
|
||||||
@AccessInput({
|
@AccessInput({
|
||||||
title: '密钥',
|
title: '私钥登录',
|
||||||
helper: '密钥或密码必填一项',
|
helper: '私钥或密码必填一项',
|
||||||
component: {
|
component: {
|
||||||
name: 'a-textarea',
|
name: 'a-textarea',
|
||||||
vModel: 'value',
|
vModel: 'value',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
privateKey!: string;
|
privateKey!: string;
|
||||||
|
|
||||||
|
@AccessInput({
|
||||||
|
title: '私钥密码',
|
||||||
|
helper: '如果你的私钥有密码的话',
|
||||||
|
component: {
|
||||||
|
name: 'a-input-password',
|
||||||
|
vModel: 'value',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
passphrase!: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
new SshAccess();
|
new SshAccess();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import ssh2 from 'ssh2';
|
import ssh2, { ConnectConfig } from 'ssh2';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { ILogger } from '@certd/pipeline';
|
import { ILogger } from '@certd/pipeline';
|
||||||
|
@ -19,7 +19,7 @@ export class SshClient {
|
||||||
}
|
}
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
uploadFiles(options: { connectConf: any; transports: any }) {
|
uploadFiles(options: { connectConf: ConnectConfig; transports: any }) {
|
||||||
const { connectConf, transports } = options;
|
const { connectConf, transports } = options;
|
||||||
const conn = new ssh2.Client();
|
const conn = new ssh2.Client();
|
||||||
|
|
||||||
|
@ -53,7 +53,10 @@ export class SshClient {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
exec(options: { connectConf: any; script: string | Array<string> }) {
|
exec(options: {
|
||||||
|
connectConf: ConnectConfig;
|
||||||
|
script: string | Array<string>;
|
||||||
|
}) {
|
||||||
let { script } = options;
|
let { script } = options;
|
||||||
const { connectConf } = options;
|
const { connectConf } = options;
|
||||||
if (_.isArray(script)) {
|
if (_.isArray(script)) {
|
||||||
|
@ -99,7 +102,7 @@ export class SshClient {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
shell(options: { connectConf: any; script: string }) {
|
shell(options: { connectConf: ConnectConfig; script: string }) {
|
||||||
const { connectConf, script } = options;
|
const { connectConf, script } = options;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.connect({
|
this.connect({
|
||||||
|
@ -132,7 +135,7 @@ export class SshClient {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(options: { connectConf: any; onReady: any; onError: any }) {
|
connect(options: { connectConf: ConnectConfig; onReady: any; onError: any }) {
|
||||||
const { connectConf, onReady, onError } = options;
|
const { connectConf, onReady, onError } = options;
|
||||||
const conn = new ssh2.Client();
|
const conn = new ssh2.Client();
|
||||||
conn
|
conn
|
||||||
|
|
|
@ -32,9 +32,9 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
|
||||||
crtPath!: string;
|
crtPath!: string;
|
||||||
@TaskInput({
|
@TaskInput({
|
||||||
title: '私钥保存路径',
|
title: '私钥保存路径',
|
||||||
helper: '需要有写入权限,路径要包含证书文件名',
|
helper: '需要有写入权限,路径要包含私钥文件名',
|
||||||
component: {
|
component: {
|
||||||
placeholder: '/root/deploy/nginx/cert.crt',
|
placeholder: '/root/deploy/nginx/cert.key',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
keyPath!: string;
|
keyPath!: string;
|
||||||
|
|
Loading…
Reference in New Issue