Skip to content

Commit

Permalink
feat(frontend): 新增sqlserver数据库备份和账号授权接口联调 #3505
Browse files Browse the repository at this point in the history
  • Loading branch information
3octaves authored and zhangzhw8 committed Mar 25, 2024
1 parent 68cfb1a commit ec2dd6b
Show file tree
Hide file tree
Showing 45 changed files with 3,718 additions and 688 deletions.
1 change: 1 addition & 0 deletions dbm-ui/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"vite-plugin-html-env": "1.2.8",
"vite-plugin-imp": "2.4.0",
"vite-plugin-style-import": "2.0.0",
"vue-component-type-helpers": "^2.0.6",
"vue-tsc": "^1.8.22"
},
"simple-git-hooks": {
Expand Down
Binary file not shown.
7 changes: 7 additions & 0 deletions dbm-ui/frontend/src/common/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ export enum TicketTypes {
MONGODB_BACKUP = 'MONGODB_BACKUP', // mongo 库表备份
MONGODB_RESTORE = 'MONGODB_RESTORE', // mongo 定点构造
MONGODB_TEMPORARY_DESTROY = 'MONGODB_TEMPORARY_DESTROY', // mongo 临时集群销毁
SQLSERVER_AUTHORIZE_RULES = 'SQLSERVER_AUTHORIZE_RULES', // sqlserver 集群授权
SQLSERVER_EXCEL_AUTHORIZE_RULES = 'SQLSERVER_EXCEL_AUTHORIZE_RULES', // sqlserver 导入授权
SQLSERVER_RESET = 'SQLSERVER_RESET', // sqlserver 集群重置
SQLSERVER_BACKUP_DBS = 'SQLSERVER_BACKUP_DBS', // sqlserver 数据库备份
}
export type TicketTypesStrings = keyof typeof TicketTypes;

Expand Down Expand Up @@ -499,6 +503,8 @@ export enum UserPersonalSettings {
MONGODB_INSTANCE_TABLE_SETTINGS = 'MONGODB_INSTANCE_TABLE_SETTINGS',
MONGODB_REPLICA_SET_SETTINGS = 'MONGODB_REPLICA_SET_SETTINGS',
MONGODB_SHARED_CLUSTER_SETTINGS = 'MONGODB_SHARED_CLUSTER_SETTINGS',
SQLSERVER_SINGLE_TABLE_SETTINGS = 'SQLSERVER_SINGLE_TABLE_SETTINGS',
SQLSERVER_HA_TABLE_SETTINGS = 'SQLSERVER_HA_TABLE_SETTINGS',
}

/**
Expand Down Expand Up @@ -558,6 +564,7 @@ export enum AccountTypes {
MYSQL = 'mysql',
TENDBCLUSTER = 'tendbcluster',
MONGODB = 'mongodb',
SQLSERVER = 'sqlserver',
}
export type AccountTypesValues = `${AccountTypes}`;

Expand Down
125 changes: 78 additions & 47 deletions dbm-ui/frontend/src/components/cluster-authorize/ClusterAuthorize.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</p>
</div>
<DbFormItem
v-if="accountType !== AccountTypes.MONGODB"
v-if="isMysql"
class="cluster-authorize__bold"
:label="t('访问源')"
property="source_ips"
Expand Down Expand Up @@ -63,38 +63,7 @@
}"
:title="clusterTypeTitle" />
</BkFormItem>
<template v-if="accountType === AccountTypes.MONGODB">
<BkFormItem
class="cluster-authorize__bold"
:label="t('权限规则')"
property="mongo_users"
required>
<div class="permission-item">
<BkButton
class="cluster-authorize__button"
@click="handleShowAccoutRules">
<DbIcon
class="button-icon"
type="db-icon-add" />
{{ t('添加账号规则') }}
</BkButton>
<BkButton
v-if="selectedList.length > 0"
text
theme="primary"
@click="handleDeleteAll">
<DbIcon type="delete" />
<span class="ml-6">{{ t('全部清空') }}</span>
</BkButton>
</div>
<AccountRulesTable
v-if="selectedList.length > 0"
class="mt-16"
:selected-list="selectedList"
@delete="handleRowDelete" />
</BkFormItem>
</template>
<template v-else>
<template v-if="isMysql">
<h5 class="cluster-authorize__bold cluster-authorize__label pb-16">
{{ t('权限规则') }}
</h5>
Expand Down Expand Up @@ -160,6 +129,38 @@
:empty-text="t('请选择访问DB')" />
</BkFormItem>
</template>
<template v-else>
<BkFormItem
class="cluster-authorize__bold"
:label="t('权限规则')"
property="mongo_users"
required>
<div class="permission-item">
<BkButton
class="cluster-authorize__button"
@click="handleShowAccoutRules">
<DbIcon
class="button-icon"
type="db-icon-add" />
{{ t('添加账号规则') }}
</BkButton>
<BkButton
v-if="selectedList.length > 0"
text
theme="primary"
@click="handleDeleteAll">
<DbIcon type="delete" />
<span class="ml-6">{{ t('全部清空') }}</span>
</BkButton>
</div>
<AccountRulesTable
v-if="selectedList.length > 0"
:account-type="accountType"
class="mt-16"
:selected-list="selectedList"
@delete="handleRowDelete" />
</BkFormItem>
</template>
</DbForm>
<template #footer>
<BkButton
Expand All @@ -176,24 +177,25 @@
</BkButton>
</template>
</BkSideslider>
<ClusterSelectorNew
v-if="accountType === AccountTypes.MONGODB"
v-model:is-show="clusterState.isShow"
:cluster-types="clusterTypes"
only-one-type
:selected="newClusterSelectorSelected"
:tab-list-config="tabListConfig"
@change="handleNewClusterChange" />
<MySqlClusterSelector
v-else
v-if="isMysql"
v-model:is-show="clusterState.isShow"
:cluster-types="clusterTypes"
only-one-type
:selected="clusterSelectorSelected"
:tab-list="tabList"
@change="handleClusterSelected" />
<ClusterSelectorNew
v-else
v-model:is-show="clusterState.isShow"
:cluster-types="clusterTypes"
only-one-type
:selected="newClusterSelectorSelected"
:tab-list-config="tabListConfig"
@change="handleNewClusterChange" />
<AccountRulesSelector
v-model:is-show="accoutRulesShow"
:account-type="accountType"
:selected-list="selectedList"
@change="handleAccountRulesChange" />
</template>
Expand All @@ -203,17 +205,19 @@
import MongodbModel from '@services/model/mongodb/mongodb';
import MongodbPermissonAccountModel from '@services/model/mongodb-permission/mongodb-permission-account';
import SqlserverPermissionAccountModel from '@services/model/sqlserver-permission/sqlserver-permission-account';
import { getPermissionRules, preCheckAuthorizeRules } from '@services/permission';
import { checkHost } from '@services/source/ipchooser';
import { getMongodbPermissionRules } from '@services/source/mongodbPermissionAccount';
import { preCheckMongodbAuthorizeRules } from '@services/source/mongodbPermissionAuthorize';
import { getSqlserverPermissionRules } from '@services/source/sqlserverPermissionAccount';
import { preCheckSqlserverAuthorizeRules } from '@services/source/sqlserverPermissionAuthorize';
import { createTicket } from '@services/source/ticket';
import { getWhitelist } from '@services/source/whitelist';
import type { AuthorizePreCheckData, PermissionRule } from '@services/types/permission';
import { useCopy, useInfo, useStickyFooter, useTicketMessage } from '@hooks';
import type { AccountTypesValues } from '@common/const';
import { AccountTypes, ClusterTypes, TicketTypes } from '@common/const';
import ClusterSelectorNew, { type TabConfig } from '@components/cluster-selector-new/Index.vue';
Expand All @@ -234,9 +238,10 @@
type ResourceItem = NonNullable<Props['selected']>[number] & { isMaster?: boolean };
type MysqlPreCheckResulst = ServiceReturnType<typeof preCheckAuthorizeRules>
type MongoPreCheckResulst = ServiceReturnType<typeof preCheckMongodbAuthorizeRules>
type SqlserverPreCheckResulst = ServiceReturnType<typeof preCheckSqlserverAuthorizeRules>
interface Props {
accountType: AccountTypesValues,
accountType: AccountTypes,
user?: string,
accessDbs?: string[],
selected?: {
Expand Down Expand Up @@ -281,6 +286,14 @@
name: t('分片集群'),
showPreviewResultTitle: true,
},
[ClusterTypes.SQLSERVER_SINGLE]: {
name: t('单节点集群'),
showPreviewResultTitle: true,
},
[ClusterTypes.SQLSERVER_HA]: {
name: t('主从集群'),
showPreviewResultTitle: true,
},
};
/**
Expand Down Expand Up @@ -314,7 +327,7 @@
/** 权限规则功能 */
const accountState = reactive({
isLoading: false,
rules: [] as PermissionRule[] | MongodbPermissonAccountModel[],
rules: [] as PermissionRule[] | MongodbPermissonAccountModel[] | SqlserverPermissionAccountModel[],
});
const clusterState = reactive({
Expand Down Expand Up @@ -344,6 +357,8 @@
],
});
const isMysql = computed(() => [AccountTypes.MYSQL, AccountTypes.TENDBCLUSTER].includes(props.accountType))
const collapseTableColumns = computed(() => {
const columns = [
{
Expand Down Expand Up @@ -419,7 +434,7 @@
tableProps,
} = clusterState;
selected[clusterType] = tableProps.data;
return selected as unknown as Record<string, MongodbModel[]>;
return selected as unknown as Record<string, (MongodbModel)[]>;
});
const tabListConfig = computed(() => props.clusterTypes.reduce((prevConfig, clusterTypeItem) => ({
Expand All @@ -431,6 +446,7 @@
[AccountTypes.MYSQL]: TicketTypes.MYSQL_AUTHORIZE_RULES,
[AccountTypes.TENDBCLUSTER]: TicketTypes.TENDBCLUSTER_AUTHORIZE_RULES,
[AccountTypes.MONGODB]: TicketTypes.MONGODB_AUTHORIZE,
[AccountTypes.SQLSERVER]: TicketTypes.SQLSERVER_AUTHORIZE_RULES
};
const bizId = window.PROJECT_CONFIG.BIZ_ID;
Expand Down Expand Up @@ -497,6 +513,7 @@
[AccountTypes.MYSQL]: getPermissionRules,
[AccountTypes.TENDBCLUSTER]: getPermissionRules,
[AccountTypes.MONGODB]: getMongodbPermissionRules,
[AccountTypes.SQLSERVER]: getSqlserverPermissionRules
};
apiMap[props.accountType]({
Expand All @@ -522,6 +539,8 @@
[ClusterTypes.TENDBCLUSTER]: 'Spider',
[ClusterTypes.MONGO_REPLICA_SET]: t('副本集'),
[ClusterTypes.MONGO_SHARED_CLUSTER]: t('分片集群'),
[ClusterTypes.SQLSERVER_SINGLE]: t('单节点'),
[ClusterTypes.SQLSERVER_HA]: t('主从'),
};
return clusterTextMap[clusterState.clusterType];
});
Expand Down Expand Up @@ -621,6 +640,7 @@
[AccountTypes.MYSQL]: 'PermissionRules',
[AccountTypes.TENDBCLUSTER]: 'spiderPermission',
[AccountTypes.MONGODB]: 'MongodbPermission',
[AccountTypes.SQLSERVER]: 'SqlServerPermissionRules'
};
const url = router.resolve({ name: routeMap[props.accountType] });
window.open(url.href, '_blank');
Expand All @@ -629,7 +649,10 @@
/**
* 创建授权单据
*/
const createAuthorizeTicket = (uid: string, data: MysqlPreCheckResulst['authorize_data'] | MongoPreCheckResulst['authorize_data']) => {
const createAuthorizeTicket = (
uid: string,
data: MysqlPreCheckResulst['authorize_data'] | MongoPreCheckResulst['authorize_data'] | SqlserverPreCheckResulst['authorize_data']
) => {
const params = {
bk_biz_id: bizId,
details: {
Expand Down Expand Up @@ -664,6 +687,7 @@
[AccountTypes.MYSQL]: preCheckAuthorizeRules,
[AccountTypes.TENDBCLUSTER]: preCheckAuthorizeRules,
[AccountTypes.MONGODB]: preCheckMongodbAuthorizeRules,
[AccountTypes.SQLSERVER]: preCheckSqlserverAuthorizeRules
};
const params = {
target_instances: formdata.target_instances,
Expand All @@ -677,6 +701,13 @@
access_dbs: selectedItem.rules.map(mapItem => mapItem.access_db),
})),
});
} else if (props.accountType === AccountTypes.SQLSERVER) {
Object.assign(params, {
sqlserver_users: selectedList.value.map(selectedItem => ({
user: selectedItem.account.user,
access_dbs: selectedItem.rules.map(mapItem => mapItem.access_db),
})),
});
} else {
Object.assign(params, {
access_dbs: formdata.access_dbs,
Expand Down
Loading

0 comments on commit ec2dd6b

Please sign in to comment.