Skip to content

Commit

Permalink
fix(frontend): 账号创建不允许特殊账号名 TencentBlueKing#8162
Browse files Browse the repository at this point in the history
  • Loading branch information
3octaves committed Dec 2, 2024
1 parent d2737e4 commit dd2934e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dbm-ui/frontend/src/locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -3657,6 +3657,7 @@
"同主机关联的其他集群,勾选后一并添加": "同主机关联的其他集群,勾选后一并添加",
"点击上传": "点击上传",
"请选择本地 SQL 文件": "请选择本地 SQL 文件",
"不允许使用特殊账号名称n": "不允许使用特殊账号名称 {n}",
"这行勿动!新增翻译请在上一行添加!": ""

}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@

import PasswordInput from '@views/db-manage/common/password-input/Index.vue';

import MongoConfig from '../mongo/config';
import MysqlConfig from '../mysql/config';
import SqlserverConfig from '../sqlserver/config';

interface Props {
accountType: AccountTypes;
}
Expand Down Expand Up @@ -135,12 +139,15 @@
const passwordRef = ref<InstanceType<typeof PasswordInput>>();

const defaultUserPlaceholder = t('由_1_~_32_位字母_数字_下划线(_)_点(.)_减号(-)字符组成以字母或数字开头');
let validValue = '';

const userPlaceholder = computed(() => {
if (props.accountType === AccountTypes.MONGODB) {
return t('格式为:(库名).(名称)_如 admin.linda');
}
return defaultUserPlaceholder;
});

const rules = computed(() => ({
user: [
{
Expand All @@ -155,6 +162,20 @@
validator: (value: string) => /^([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)$/g.test(value),
}
: {},
{
trigger: 'change',
validator: (value: string) => {
const specialAccountMap = {
[AccountTypes.MYSQL]: MysqlConfig[AccountTypes.MYSQL].special_account,
[AccountTypes.TENDBCLUSTER]: MysqlConfig[AccountTypes.TENDBCLUSTER].special_account,
[AccountTypes.MONGODB]: MongoConfig.special_account,
[AccountTypes.SQLSERVER]: SqlserverConfig.special_account,
};
validValue = props.accountType === AccountTypes.MONGODB ? value.split('.')[1] : value;
return !specialAccountMap[props.accountType].includes(validValue);
},
message: t('不允许使用特殊账号名称n', { n: validValue }),
},
],
password: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export default {
'dbOwner',
'root',
],
special_account: ['dba', 'apppdba', 'monitor', 'appmonitor'],
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import { AccountTypes } from '@common/const';

const SPECIAL_ACCOUNT = [
'gcs_admin',
'gcs_dba',
'MONITOR',
'GM',
'ADMIN',
'repl',
'dba_bak_all_sel',
'yw',
'partition_yw',
'spider',
'mysql.session',
'mysql.sys',
'gcs_spider',
'sync',
];

export default {
[AccountTypes.MYSQL]: {
dbOperations: {
Expand All @@ -21,6 +38,7 @@ export default {
glob: ['file', 'reload', 'show databases', 'process', 'replication slave', 'replication client'],
},
ddlSensitiveWords: ['trigger', 'event', 'create routine', 'alter routine', 'references', 'create temporary tables'],
special_account: SPECIAL_ACCOUNT,
},
[AccountTypes.TENDBCLUSTER]: {
dbOperations: {
Expand All @@ -29,5 +47,6 @@ export default {
glob: ['file', 'reload', 'process', 'show databases'],
},
ddlSensitiveWords: [],
special_account: SPECIAL_ACCOUNT,
},
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default {
dml: ['db_datawriter', 'db_datareader'],
owner: ['db_owner'],
special_account: ['mssql_exporter', 'dbm_admin', 'sa', 'sqlserver'],
};

0 comments on commit dd2934e

Please sign in to comment.