🔨 加密参数.
This commit is contained in:
@@ -33,8 +33,8 @@
|
||||
<template #type="{ record }">
|
||||
<a-tag class="flex-center" :color="getDictValue(hostTypeKey, record.type, 'color')">
|
||||
<!-- 系统类型图标 -->
|
||||
<component v-if="HostOsType[record.osType as keyof typeof HostOsType]"
|
||||
:is="HostOsType[record.osType as keyof typeof HostOsType].icon"
|
||||
<component v-if="getHostOsIcon(record.osType)"
|
||||
:is="getHostOsIcon(record.osType)"
|
||||
class="os-icon" />
|
||||
<!-- 主机类型 -->
|
||||
<span>{{ getDictValue(hostTypeKey, record.type) }}</span>
|
||||
@@ -65,7 +65,7 @@
|
||||
import { flatNodeKeys } from '@/utils/tree';
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
import { hostColumns } from '../types/table.columns';
|
||||
import { HostOsType, hostTypeKey } from '@/views/asset/host-list/types/const';
|
||||
import { getHostOsIcon, hostTypeKey } from '@/views/asset/host-list/types/const';
|
||||
import { getHostGroupRelList } from '@/api/asset/host-group';
|
||||
import HostGroupTree from '@/components/asset/host-group/tree/index.vue';
|
||||
import GrantLayout from './grant-layout.vue';
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
import { useCacheStore, useDictStore } from '@/store';
|
||||
import { dictKeys } from '../types/const';
|
||||
import { getHostConfig, updateHostConfig } from '@/api/asset/host';
|
||||
import { HostType } from '@/views/asset/host-list/types/const';
|
||||
import { encrypt } from '@/utils/rsa';
|
||||
import SshConfigForm from '../components/ssh-config-form.vue';
|
||||
|
||||
const { visible, setVisible } = useVisible();
|
||||
@@ -74,12 +76,22 @@
|
||||
|
||||
// 保存
|
||||
const save = async (conf: Record<string, any>) => {
|
||||
// 加密参数
|
||||
const newConfig = { ...conf };
|
||||
try {
|
||||
// 加密 SSH
|
||||
if (record.value.type === HostType.SSH.value) {
|
||||
newConfig.password = await encrypt(conf.password);
|
||||
}
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
setLoading(true);
|
||||
// 更新
|
||||
await updateHostConfig({
|
||||
id: hostConfig.value.id,
|
||||
config: JSON.stringify(conf)
|
||||
config: JSON.stringify(newConfig),
|
||||
});
|
||||
// 设置参数
|
||||
hostConfig.value.config = conf;
|
||||
@@ -147,7 +159,7 @@
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.title{
|
||||
.title {
|
||||
font-weight: 600;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
import { IdentityType, identityTypeKey } from '../types/const';
|
||||
import { useDictStore } from '@/store';
|
||||
import { encrypt } from '@/utils/rsa';
|
||||
import HostKeySelector from '@/components/asset/host-key/selector/index.vue';
|
||||
|
||||
const { toRadioOptions, getDictValue } = useDictStore();
|
||||
@@ -150,14 +151,21 @@
|
||||
if (error) {
|
||||
return false;
|
||||
}
|
||||
// 加密参数
|
||||
let password = undefined;
|
||||
try {
|
||||
password = await encrypt(formModel.value.password);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
if (isAddHandle.value) {
|
||||
// 新增
|
||||
await createHostIdentity(formModel.value);
|
||||
await createHostIdentity({ ...formModel.value, password });
|
||||
Message.success('创建成功');
|
||||
emits('added');
|
||||
} else {
|
||||
// 修改
|
||||
await updateHostIdentity(formModel.value);
|
||||
await updateHostIdentity({ ...formModel.value, password });
|
||||
Message.success('修改成功');
|
||||
emits('updated');
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@
|
||||
import { createHostKey, updateHostKey, getHostKey } from '@/api/asset/host-key';
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
import { readFileText } from '@/utils/file';
|
||||
import { encrypt } from '@/utils/rsa';
|
||||
|
||||
const { visible, setVisible } = useVisible();
|
||||
const { loading, setLoading } = useLoading();
|
||||
@@ -200,14 +201,25 @@
|
||||
if (error) {
|
||||
return false;
|
||||
}
|
||||
let publicKey = undefined;
|
||||
let privateKey = undefined;
|
||||
let password = undefined;
|
||||
// 加密参数
|
||||
try {
|
||||
publicKey = await encrypt(formModel.value.publicKey);
|
||||
privateKey = await encrypt(formModel.value.privateKey);
|
||||
password = await encrypt(formModel.value.password);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
if (isAddHandle.value) {
|
||||
// 新增
|
||||
await createHostKey(formModel.value);
|
||||
await createHostKey({ ...formModel.value, publicKey, privateKey, password });
|
||||
Message.success('创建成功');
|
||||
emits('added');
|
||||
} else {
|
||||
// 修改
|
||||
await updateHostKey(formModel.value);
|
||||
await updateHostKey({ ...formModel.value, publicKey, privateKey, password });
|
||||
Message.success('修改成功');
|
||||
emits('updated');
|
||||
}
|
||||
|
||||
@@ -106,8 +106,8 @@
|
||||
<template #title="{ record }">
|
||||
<div class="host-title">
|
||||
<!-- 系统类型图标 -->
|
||||
<component v-if="HostOsType[record.osType as keyof typeof HostOsType]"
|
||||
:is="HostOsType[record.osType as keyof typeof HostOsType].icon"
|
||||
<component v-if="getHostOsIcon(record.osType)"
|
||||
:is="getHostOsIcon(record.osType)"
|
||||
class="os-icon" />
|
||||
<!-- 主机名称 -->
|
||||
<span>{{ record.name }}</span>
|
||||
@@ -232,7 +232,7 @@
|
||||
import { dataColor, objectTruthKeyCount, resetObject } from '@/utils';
|
||||
import { deleteHost, getHostPage, updateHostStatus } from '@/api/asset/host';
|
||||
import { Message, Modal } from '@arco-design/web-vue';
|
||||
import { HostOsType, hostOsTypeKey, hostStatusKey, HostType, hostTypeKey, tagColor } from '../types/const';
|
||||
import { getHostOsIcon, hostOsTypeKey, hostStatusKey, HostType, hostTypeKey, tagColor } from '../types/const';
|
||||
import { copy } from '@/hooks/copy';
|
||||
import { useCacheStore, useDictStore } from '@/store';
|
||||
import { GrantKey, GrantRouteName } from '@/views/asset/grant/types/const';
|
||||
|
||||
@@ -140,8 +140,8 @@
|
||||
<template #type="{ record }">
|
||||
<a-tag class="flex-center" :color="getDictValue(hostTypeKey, record.type, 'color')">
|
||||
<!-- 系统类型图标 -->
|
||||
<component v-if="HostOsType[record.osType as keyof typeof HostOsType]"
|
||||
:is="HostOsType[record.osType as keyof typeof HostOsType].icon"
|
||||
<component v-if="getHostOsIcon(record.osType)"
|
||||
:is="getHostOsIcon(record.osType)"
|
||||
class="os-icon" />
|
||||
<!-- 主机类型 -->
|
||||
<span>{{ getDictValue(hostTypeKey, record.type) }}</span>
|
||||
@@ -267,7 +267,7 @@
|
||||
import { reactive, ref, onMounted } from 'vue';
|
||||
import { deleteHost, batchDeleteHost, getHostPage, updateHostStatus } from '@/api/asset/host';
|
||||
import { Message, Modal } from '@arco-design/web-vue';
|
||||
import { tagColor, hostTypeKey, hostStatusKey, HostType, HostOsType, hostOsTypeKey } from '../types/const';
|
||||
import { tagColor, hostTypeKey, hostStatusKey, HostType, hostOsTypeKey, getHostOsIcon } from '../types/const';
|
||||
import { useTablePagination, useRowSelection } from '@/hooks/table';
|
||||
import { useCacheStore, useDictStore } from '@/store';
|
||||
import { copy } from '@/hooks/copy';
|
||||
|
||||
@@ -30,6 +30,11 @@ export const HostOsType = {
|
||||
},
|
||||
};
|
||||
|
||||
// 获取系统类型 icon
|
||||
export const getHostOsIcon = (osType: string) => {
|
||||
return HostOsType[osType as keyof typeof HostOsType]?.icon;
|
||||
};
|
||||
|
||||
// 主机类型 字典项
|
||||
export const hostTypeKey = 'hostType';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user