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

61 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-06-19 00:53:53 +08:00
import {
AbstractTaskPlugin,
IAccessService,
ILogger,
IsTaskPlugin,
RunStrategy,
TaskInput,
} from '@certd/pipeline';
2024-07-15 00:30:33 +08:00
import { SshClient } from '../../lib/ssh.js';
2022-11-07 23:31:20 +08:00
2023-01-11 20:39:48 +08:00
@IsTaskPlugin({
2024-06-19 00:53:53 +08:00
name: 'hostShellExecute',
title: '执行远程主机脚本命令',
2023-01-11 20:39:48 +08:00
input: {},
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-06-19 00:53:53 +08:00
name: 'pi-access-selector',
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',
2023-01-11 20:39:48 +08:00
},
})
script!: string;
accessService!: IAccessService;
logger!: ILogger;
2023-06-25 23:25:56 +08:00
async onInstance() {
this.accessService = this.ctx.accessService;
this.logger = this.ctx.logger;
}
2023-01-11 20:39:48 +08:00
async execute(): Promise<void> {
const { script, accessId } = this;
2023-05-23 18:01:20 +08:00
const connectConf = await this.accessService.getById(accessId);
2022-11-07 23:31:20 +08:00
const sshClient = new SshClient(this.logger);
const ret = await sshClient.exec({
connectConf,
script,
});
2024-06-19 00:53:53 +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();