feat: 守护进程一些字段增加校验 (#1865)

pull/1870/head
zhengkunwang 2023-08-08 14:04:19 +08:00 committed by GitHub
parent 9b02e88e3c
commit cd77c672bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 15 deletions

View File

@ -110,7 +110,7 @@ func (h *HostToolService) GetToolStatus(req request.HostToolReq) (*response.Host
if !fileOp.Stat(configPath) {
configPath = "/etc/supervisor/supervisord.conf"
if !fileOp.Stat(configPath) {
return nil, errors.New("ErrConfigNotFound")
return nil, buserr.New("ErrConfigNotFound")
}
}
}
@ -125,7 +125,7 @@ func (h *HostToolService) CreateToolConfig(req request.HostToolCreate) error {
case constant.Supervisord:
fileOp := files.NewFileOp()
if !fileOp.Stat(req.ConfigPath) {
return errors.New("ErrConfigNotFound")
return buserr.New("ErrConfigNotFound")
}
cfg, err := ini.Load(req.ConfigPath)
if err != nil {
@ -281,7 +281,7 @@ func (h *HostToolService) OperateSupervisorProcess(req request.SupervisorProcess
iniPath = path.Join(includeDir, fmt.Sprintf("%s.ini", req.Name))
fileOp = files.NewFileOp()
)
if req.Operate == "edit" || req.Operate == "create" {
if req.Operate == "update" || req.Operate == "create" {
if !fileOp.Stat(req.Dir) {
return buserr.New("ErrConfigDirNotFound")
}
@ -318,7 +318,7 @@ func (h *HostToolService) OperateSupervisorProcess(req request.SupervisorProcess
return err
}
return operateSupervisorCtl("reload", "", "")
case "edit":
case "update":
configFile, err := ini.Load(iniPath)
if err != nil {
return err

View File

@ -21,7 +21,7 @@
</el-input>
</el-form-item>
<el-form-item :label="$t('tool.supervisor.command')" prop="command">
<el-input v-model.trim="process.command"></el-input>
<el-input v-model="process.command"></el-input>
</el-form-item>
<el-form-item :label="$t('tool.supervisor.numprocs')" prop="numprocsNum">
<el-input type="number" v-model.number="process.numprocsNum"></el-input>
@ -54,7 +54,7 @@ const open = ref(false);
const loading = ref(false);
const processForm = ref<FormInstance>();
const rules = ref({
name: [Rules.requiredInput],
name: [Rules.requiredInput, Rules.simpleName],
dir: [Rules.requiredInput],
command: [Rules.requiredInput],
user: [Rules.requiredInput],
@ -64,7 +64,7 @@ const initData = () => ({
operate: 'create',
name: '',
command: '',
user: '',
user: 'root',
dir: '',
numprocsNum: 1,
numprocs: '1',
@ -89,9 +89,9 @@ const resetForm = () => {
const acceptParams = (operate: string, config: HostTool.SupersivorProcess) => {
process.value = initData();
if (operate == 'edit') {
if (operate == 'update') {
process.value = {
operate: 'edit',
operate: 'update',
name: config.name,
command: config.command,
user: config.user,

View File

@ -52,6 +52,7 @@ import { useDeleteData } from '@/hooks/use-delete-data';
import { OperateSupervisorProcessFile } from '@/api/modules/host-tool';
import i18n from '@/lang';
import { TabsPaneContext } from 'element-plus';
import { MsgSuccess } from '@/utils/message';
const extensions = [javascript(), oneDark];
const loading = ref(false);
@ -113,6 +114,7 @@ const submit = () => {
loading.value = true;
OperateSupervisorProcessFile(updateReq)
.then(() => {
MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
getContent();
})
.finally(() => {

View File

@ -20,15 +20,19 @@
</template>
<template #main v-if="showTable">
<ComplexTable :data="data" :class="{ mask: !supervisorStatus.isRunning }">
<el-table-column :label="$t('commons.table.name')" fix prop="name"></el-table-column>
<el-table-column :label="$t('commons.table.name')" fix prop="name" width="150px"></el-table-column>
<el-table-column :label="$t('tool.supervisor.command')" prop="command"></el-table-column>
<el-table-column :label="$t('tool.supervisor.dir')" prop="dir"></el-table-column>
<el-table-column :label="$t('tool.supervisor.user')" prop="user"></el-table-column>
<el-table-column :label="$t('tool.supervisor.numprocs')" prop="numprocs"></el-table-column>
<el-table-column :label="$t('commons.table.status')">
<el-table-column :label="$t('tool.supervisor.user')" prop="user" width="100px"></el-table-column>
<el-table-column
:label="$t('tool.supervisor.numprocs')"
prop="numprocs"
width="100px"
></el-table-column>
<el-table-column :label="$t('commons.table.status')" width="100px">
<template #default="{ row }">
<div v-if="row.status">
<el-popover placement="left" :width="600" trigger="hover">
<el-popover placement="bottom" :width="600" trigger="hover">
<template #reference>
<el-button type="primary" link v-if="row.status.length > 1">
{{ $t('website.check') }}
@ -173,7 +177,7 @@ const getFile = (name: string, file: string) => {
};
const edit = (row: HostTool.SupersivorProcess) => {
createRef.value.acceptParams('edit', row);
createRef.value.acceptParams('update', row);
};
const buttons = [