2024-08-13 20:30:42 +08:00
|
|
|
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline';
|
2024-11-29 19:00:05 +08:00
|
|
|
import { SshClient } from '@certd/plugin-lib';
|
2023-01-11 20:39:48 +08:00
|
|
|
@IsTaskPlugin({
|
2024-06-19 00:53:53 +08:00
|
|
|
name: 'hostShellExecute',
|
2024-12-26 01:32:52 +08:00
|
|
|
title: '主机-执行远程主机脚本命令',
|
2024-09-20 11:11:25 +08:00
|
|
|
icon: 'tabler:brand-powershell',
|
2024-07-21 02:26:03 +08:00
|
|
|
group: pluginGroups.host.key,
|
2024-10-30 15:19:35 +08:00
|
|
|
desc: '可以执行重启nginx等操作让证书生效',
|
2023-01-11 20:39:48 +08:00
|
|
|
input: {},
|
2025-07-28 23:22:38 +08:00
|
|
|
showRunStrategy: true,
|
2023-01-11 20:39:48 +08:00
|
|
|
default: {
|
|
|
|
|
strategy: {
|
|
|
|
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
2022-11-07 23:31:20 +08:00
|
|
|
},
|
2023-01-11 20:39:48 +08:00
|
|
|
},
|
|
|
|
|
output: {},
|
2022-11-07 23:31:20 +08:00
|
|
|
})
|
2023-05-24 15:41:35 +08:00
|
|
|
export class HostShellExecutePlugin extends AbstractTaskPlugin {
|
2023-01-11 20:39:48 +08:00
|
|
|
@TaskInput({
|
2024-06-19 00:53:53 +08:00
|
|
|
title: '主机登录配置',
|
|
|
|
|
helper: '登录',
|
2023-01-11 20:39:48 +08:00
|
|
|
component: {
|
2024-10-07 03:21:16 +08:00
|
|
|
name: 'access-selector',
|
2024-06-19 00:53:53 +08:00
|
|
|
type: 'ssh',
|
2023-01-11 20:39:48 +08:00
|
|
|
},
|
|
|
|
|
required: true,
|
|
|
|
|
})
|
|
|
|
|
accessId!: string;
|
|
|
|
|
@TaskInput({
|
2024-06-19 00:53:53 +08:00
|
|
|
title: 'shell脚本命令',
|
2023-01-11 20:39:48 +08:00
|
|
|
component: {
|
2024-06-19 00:53:53 +08:00
|
|
|
name: 'a-textarea',
|
|
|
|
|
vModel: 'value',
|
2024-09-02 18:36:12 +08:00
|
|
|
rows: 6,
|
2024-10-15 17:12:42 +08:00
|
|
|
placeholder: 'systemctl restart nginx',
|
2023-01-11 20:39:48 +08:00
|
|
|
},
|
2024-09-05 14:33:45 +08:00
|
|
|
helper: '注意:如果目标主机是windows,且终端是cmd,系统会自动将多行命令通过“&&”连接成一行',
|
2024-08-05 16:00:04 +08:00
|
|
|
required: true,
|
2023-01-11 20:39:48 +08:00
|
|
|
})
|
|
|
|
|
script!: string;
|
|
|
|
|
|
2024-08-13 20:30:42 +08:00
|
|
|
async onInstance() {}
|
2023-01-11 20:39:48 +08:00
|
|
|
async execute(): Promise<void> {
|
|
|
|
|
const { script, accessId } = this;
|
2025-04-12 00:14:55 +08:00
|
|
|
const connectConf = await this.getAccess(accessId);
|
2022-11-07 23:31:20 +08:00
|
|
|
const sshClient = new SshClient(this.logger);
|
2024-09-05 00:04:31 +08:00
|
|
|
|
|
|
|
|
const scripts = script.split('\n');
|
|
|
|
|
await sshClient.exec({
|
2022-11-07 23:31:20 +08:00
|
|
|
connectConf,
|
2024-09-05 00:04:31 +08:00
|
|
|
script: scripts,
|
2022-11-07 23:31:20 +08:00
|
|
|
});
|
2024-09-04 18:29:39 +08:00
|
|
|
// this.logger.info('exec res:', ret);
|
2022-11-07 23:31:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
2023-05-09 09:56:31 +08:00
|
|
|
|
|
|
|
|
new HostShellExecutePlugin();
|