Files
certd/packages/ui/certd-server/src/plugins/plugin-host/plugin/host-shell-execute/index.ts
T

58 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-08-13 20:30:42 +08:00
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline';
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',
group: pluginGroups.host.key,
desc: '可以执行重启nginx等操作让证书生效',
2023-01-11 20:39:48 +08:00
input: {},
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: {
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;
const connectConf = await this.getAccess(accessId);
2022-11-07 23:31:20 +08:00
const sshClient = new SshClient(this.logger);
const scripts = script.split('\n');
await sshClient.exec({
2022-11-07 23:31:20 +08:00
connectConf,
script: scripts,
2022-11-07 23:31:20 +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();