Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: built-in semantic types (#14904)

ecmadaof3addc0ba664
diff --git a/frontend/src/components/SensitiveData/SemanticTypesView.vue b/frontend/src/components/SensitiveData/SemanticTypesView.vue
index 18afb16a73..1593183119 100644
--- a/frontend/src/components/SensitiveData/SemanticTypesView.vue
+++ b/frontend/src/components/SensitiveData/SemanticTypesView.vue
@@ -186,12 +186,24 @@ const onCancel = (index: number) => {
};
const onTemplateApply = async (template: SemanticTypeSetting_SemanticType) => {
+ if (state.semanticItemList.find((item) => item.item.id === template.id)) {
+ pushNotification({
+ module: "bytebase",
+ style: "INFO",
+ title: t(
+ "settings.sensitive-data.semantic-types.template.duplicate-warning",
+ {
+ title: template.title,
+ }
+ ),
+ });
+ return;
+ }
const semanticItem: SemanticItem = {
dirty: false,
mode: "NORMAL",
item: SemanticTypeSetting_SemanticType.fromPartial({
...template,
- id: uuidv4(),
}),
};
state.semanticItemList.push(semanticItem);
diff --git a/frontend/src/components/SensitiveData/components/SemanticTemplateDrawer.vue b/frontend/src/components/SensitiveData/components/SemanticTemplateDrawer.vue
index b135f09c53..88b2e020f1 100644
--- a/frontend/src/components/SensitiveData/components/SemanticTemplateDrawer.vue
+++ b/frontend/src/components/SensitiveData/components/SemanticTemplateDrawer.vue
@@ -4,7 +4,12 @@
:title="$t('settings.sensitive-data.semantic-types.add-from-template')"
class="max-w-[100vw]"
>
- <div class="w-[42rem]">
+ <div class="w-[42rem] space-y-4">
+ <p class="textinfolabel">
+ {{
+ $t("settings.sensitive-data.semantic-types.template.description")
+ }}
+ </p>
<SemanticTypesTable
:readonly="true"
:row-clickable="true"
diff --git a/frontend/src/components/SensitiveData/components/SemanticTypesTable.vue b/frontend/src/components/SensitiveData/components/SemanticTypesTable.vue
index 6a94d78f15..44841eee84 100644
--- a/frontend/src/components/SensitiveData/components/SemanticTypesTable.vue
+++ b/frontend/src/components/SensitiveData/components/SemanticTypesTable.vue
@@ -19,8 +19,14 @@
</template>
<script lang="tsx" setup>
-import { CheckIcon, PencilIcon, TrashIcon, Undo2Icon } from "lucide-vue-next";
-import { NPopconfirm, NInput, NDataTable } from "naive-ui";
+import {
+ CheckIcon,
+ PencilIcon,
+ TrashIcon,
+ Undo2Icon,
+ InfoIcon,
+} from "lucide-vue-next";
+import { NPopconfirm, NInput, NDataTable, NTooltip } from "naive-ui";
import type { DataTableColumn } from "naive-ui";
import { computed, reactive } from "vue";
import { useI18n } from "vue-i18n";
@@ -76,6 +82,14 @@ const onDrawerDismiss = () => {
state.showAlgorithmDrawer = false;
};
+const isBuiltinSemanticType = (item: SemanticTypeSetting_SemanticType) => {
+ return item.id.startsWith("bb.");
+};
+
+const isReadonly = (item: SemanticTypeSetting_SemanticType) => {
+ return props.readonly || isBuiltinSemanticType(item);
+};
+
const onAlgorithmUpsert = async (maskingAlgorithm: Algorithm) => {
if (state.pendingEditSemanticIndex === undefined) {
return;
@@ -151,14 +165,36 @@ const columnList = computed(() => {
render: (item, row) => {
return (
<div class="flex items-center space-x-1">
- <h3>
- {getMaskingType(item.item.algorithm)
- ? t(
- `settings.sensitive-data.algorithms.${getMaskingType(item.item.algorithm)?.toLowerCase()}.self`
- )
- : t("settings.sensitive-data.algorithms.default")}
- </h3>
- {!props.readonly && (
+ {isBuiltinSemanticType(item.item) ? (
+ <h3>
+ {t(
+ `settings.sensitive-data.semantic-types.template.${item.item.id.split(".").join("-")}.algorithm.title`
+ )}
+ </h3>
+ ) : (
+ <h3>
+ {getMaskingType(item.item.algorithm)
+ ? t(
+ `settings.sensitive-data.algorithms.${getMaskingType(item.item.algorithm)?.toLowerCase()}.self`
+ )
+ : t("settings.sensitive-data.algorithms.default")}
+ </h3>
+ )}
+ {isBuiltinSemanticType(item.item) && (
+ <NTooltip>
+ {{
+ trigger: () => <InfoIcon class="w-4" />,
+ default: () => (
+ <div class="whitespace-pre-line">
+ {t(
+ `settings.sensitive-data.semantic-types.template.${item.item.id.split(".").join("-")}.algorithm.description`
+ )}
+ </div>
+ ),
+ }}
+ </NTooltip>
+ )}
+ {!isReadonly(item.item) && (
<MiniActionButton
onClick={() => {
state.pendingEditAlgorithm = getMaskingType(item.item.algorithm)
@@ -183,6 +219,27 @@ const columnList = computed(() => {
title: t("common.edit"),
width: "minmax(min-content, auto)",
render: (item, row) => {
+ if (isBuiltinSemanticType(item.item)) {
+ return (
+ <NPopconfirm onPositiveClick={() => emit("remove", row)}>
+ {{
+ trigger: () => {
+ return (
+ <MiniActionButton>
+ <TrashIcon class="w-4 h-4" />
+ </MiniActionButton>
+ );
+ },
+ default: () => (
+ <div class="whitespace-nowrap">
+ {t("settings.sensitive-data.semantic-types.table.delete")}
+ </div>
+ ),
+ }}
+ </NPopconfirm>
+ );
+ }
+
return (
<div>
{item.mode === "EDIT" && (
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index a8e699b2bd..e9f3d95461 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -839,6 +839,24 @@
"delete": "Delete this semantic type?"
},
"template": {
+ "description": "You can apply built-in semantic types from the template. Built-in template cannot be changed.",
+ "duplicate-warning": "Semantic type \"{title}\" already exists",
+ "bb-default": {
+ "title": "Default",
+ "description": "Default type with full masking",
+ "algorithm": {
+ "title": "Full mask",
+ "description": "All values will be masked as \"******\""
+ }
+ },
+ "bb-default-partial": {
+ "title": "Default Partial",
+ "description": "Default partial type with partial masking",
+ "algorithm": {
+ "title": "Range mask",
+ "description": "Only keep the raw data in the middle, and cover the beginning and end with \"**\".\nFor example, \"address\" will be masked as \"**dre**\"."
+ }
+ },
"address": {
"title": "Address",
"description": ""
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index d083ef744d..ccbfd30b46 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -839,6 +839,24 @@
"delete": "¿Eliminar este tipo semántico?"
},
"template": {
+ "description": "Puede aplicar tipos semánticos integrados desde la plantilla. La plantilla integrada no se puede modificar.",
+ "duplicate-warning": "El tipo semántico \"{title}\" ya existe",
+ "bb-default": {
+ "title": "Por defecto",
+ "description": "Tipo predeterminado con enmascaramiento completo",
+ "algorithm": {
+ "title": "Máscara completa",
+ "description": "Todos los valores se enmascararán como \"******\""
+ }
+ },
+ "bb-default-partial": {
+ "title": "Predeterminado Parcial",
+ "description": "Tipo parcial predeterminado con enmascaramiento parcial",
+ "algorithm": {
+ "title": "Máscara de rango",
+ "description": "Solo se conservan los datos sin procesar en el medio y se tapa el principio y el final con \"**\".\nPor ejemplo, \"dirección\" se enmascarará como \"**dre**\"."
+ }
+ },
"address": {
"title": "La dirección",
"description": ""
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 7ecfda4174..86ce8d7e37 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -839,6 +839,24 @@
"delete": "このセマンティック タイプを削除しますか?"
},
"template": {
+ "description": "テンプレートから組み込みのセマンティック タイプを適用できます。組み込みテンプレートは変更できません。",
+ "duplicate-warning": "セマンティック タイプ \"{title}\" は既に存在します",
+ "bb-default": {
+ "title": "デフォルト",
+ "description": "完全なマスク付きのデフォルトタイプ",
+ "algorithm": {
+ "title": "フルマスク",
+ "description": "すべての値は「******」としてマスクされます"
+ }
+ },
+ "bb-default-partial": {
+ "title": "デフォルト 部分的",
+ "description": "部分マスク付きのデフォルトの部分タイプ",
+ "algorithm": {
+ "title": "範囲マスク",
+ "description": "中央の生データのみを保持し、先頭と末尾を「**」で覆います。\nたとえば、「address」は「**dre**」としてマスクされます。"
+ }
+ },
"address": {
"title": "中国の詳細な住所",
"description": ""
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 4e9b44eca9..b27efc36da 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -839,6 +839,24 @@
"delete": "删除这个语义类型?"
},
"template": {
+ "description": "您可以从模板中应用内置语义类型。内置模板无法更改。",
+ "duplicate-warning": "语义类型“{title}”已存在",
+ "bb-default": {
+ "title": "全遮掩",
+ "description": "遮掩全部数据",
+ "algorithm": {
+ "title": "全遮掩",
+ "description": "所有值都将被屏蔽为“******”"
+ }
+ },
+ "bb-default-partial": {
+ "title": "半遮掩",
+ "description": "遮掩部分数据",
+ "algorithm": {
+ "title": "范围遮掩",
+ "description": "只保留中间的原始数据,并用“**”覆盖开头和结尾。\n例如,“address”将被屏蔽为“**dre**”。"
+ }
+ },
"address": {
"title": "中文详细地址",
"description": ""
@@ -3907,4 +3925,4 @@
"last-visit": "上次访问",
"changelog-for-version": "{version} 的更新日志"
}
-}
\ No newline at end of file
+}
diff --git a/frontend/src/types/semantic-types.yaml b/frontend/src/types/semantic-types.yaml
index a51e327f23..7cbb83abdc 100644
--- a/frontend/src/types/semantic-types.yaml
+++ b/frontend/src/types/semantic-types.yaml
@@ -1,10 +1,2 @@
-- id: address
-- id: secret_key
-- id: card_number
-- id: email
-- id: id_number
-- id: ipv4_address
-- id: license_plate_number
-- id: mac_address
-- id: password
-- id: phone
+- id: bb.default
+- id: bb.default-partial
\ No newline at end of file
diff --git a/frontend/src/types/semanticTypes.ts b/frontend/src/types/semanticTypes.ts
index 95affb909f..55e82f476e 100644
--- a/frontend/src/types/semanticTypes.ts
+++ b/frontend/src/types/semanticTypes.ts
@@ -1,6 +1,8 @@
-import { v4 as uuidv4 } from "uuid";
import { t } from "@/plugins/i18n";
-import { SemanticTypeSetting_SemanticType, Algorithm } from "@/types/proto/v1/setting_service";
+import {
+ SemanticTypeSetting_SemanticType,
+ Algorithm,
+} from "@/types/proto/v1/setting_service";
import buildInSemanticTypes from "./semantic-types.yaml";
interface BuildInSemantic {
@@ -9,16 +11,15 @@ interface BuildInSemantic {
}
export const getSemanticTemplateList = () => {
- return (buildInSemanticTypes as BuildInSemantic[]).map((buildInSemantic) =>
- SemanticTypeSetting_SemanticType.fromPartial({
- id: uuidv4(),
- title: t(
- `settings.sensitive-data.semantic-types.template.${buildInSemantic.id}.title`
- ),
+ return (buildInSemanticTypes as BuildInSemantic[]).map((buildInSemantic) => {
+ const key = buildInSemantic.id.split(".").join("-");
+ return SemanticTypeSetting_SemanticType.fromPartial({
+ id: buildInSemantic.id,
+ title: t(`settings.sensitive-data.semantic-types.template.${key}.title`),
description: t(
- `settings.sensitive-data.semantic-types.template.${buildInSemantic.id}.description`
+ `settings.sensitive-data.semantic-types.template.${key}.description`
),
algorithm: buildInSemantic.algorithm,
- })
- );
+ });
+ });
};