Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: fe connect rpc: migrate audit log services (#16598)
p0ny66e0adb84f4b
diff --git a/frontend/src/components/AuditLog/AuditLogDataTable.vue b/frontend/src/components/AuditLog/AuditLogDataTable.vueindex 61683ac0b5..0f61469d7c 100644--- a/frontend/src/components/AuditLog/AuditLogDataTable.vue+++ b/frontend/src/components/AuditLog/AuditLogDataTable.vue@@ -10,6 +10,7 @@</template><script lang="tsx" setup>+import { fromBinary } from "@bufbuild/protobuf";import dayjs from "dayjs";import { NDataTable, type DataTableColumn } from "naive-ui";import { computed } from "vue";@@ -17,9 +18,10 @@ import { useI18n } from "vue-i18n";import BBAvatar from "@/bbkit/BBAvatar.vue";import { useProjectV1Store, useUserStore } from "@/store";import { projectNamePrefix } from "@/store/modules/v1/common";-import { getDateForPbTimestamp } from "@/types";-import { AuditData, type AuditLog } from "@/types/proto/v1/audit_log_service";-import { Setting } from "@/types/proto/v1/setting_service";+import { getDateForPbTimestampProtoEs } from "@/types";+import type { AuditLog } from "@/types/proto-es/v1/audit_log_service_pb";+import { AuditDataSchema } from "@/types/proto-es/v1/audit_log_service_pb";+import { SettingSchema } from "@/types/proto-es/v1/setting_service_pb";import { extractProjectResourceName } from "@/utils";import JSONStringView from "./JSONStringView.vue";@@ -51,7 +53,7 @@ const columnList = computed((): AuditDataTableColumn[] => {title: t("audit-log.table.created-ts"),width: 240,render: (auditLog) =>- dayjs(getDateForPbTimestamp(auditLog.createTime)).format(+ dayjs(getDateForPbTimestampProtoEs(auditLog.createTime)).format("YYYY-MM-DD HH:mm:ss Z"),},@@ -168,9 +170,9 @@ const columnList = computed((): AuditDataTableColumn[] => {function getServiceDataValue(typeUrl: string, value: Uint8Array): any {switch (typeUrl) {case "type.googleapis.com/bytebase.v1.AuditData":- return AuditData.decode(value);+ return fromBinary(AuditDataSchema, value);case "type.googleapis.com/bytebase.v1.Setting":- return Setting.decode(value);+ return fromBinary(SettingSchema, value);default:return null;}diff --git a/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue b/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vueindex d7ea17331c..1dcec9da5a 100644--- a/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue+++ b/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue@@ -30,7 +30,7 @@ import { ProjectV1Name } from "@/components/v2";import { ALL_METHODS_WITH_AUDIT } from "@/grpcweb/methods";import { useCurrentUserV1, useProjectV1Store, useUserStore } from "@/store";import { SYSTEM_BOT_USER_NAME } from "@/types";-import { AuditLog_Severity } from "@/types/proto/v1/audit_log_service";+import { AuditLog_Severity } from "@/types/proto-es/v1/audit_log_service_pb";import { UserType } from "@/types/proto/v1/user_service";import {getDefaultPagination,@@ -159,13 +159,13 @@ const scopeOptions = computed((): ScopeOption[] => {id: "level",title: t("audit-log.advanced-search.scope.level.title"),description: t("audit-log.advanced-search.scope.level.description"),- options: Object.values(AuditLog_Severity).map((severity) => {- return {+ options: Object.keys(AuditLog_Severity).filter((v) => isNaN(Number(v))).map((severity) => {+ return {value: severity,keywords: [severity],render: () => "",- };- }),+ };+ }),},];return scopes;diff --git a/frontend/src/components/AuditLog/AuditLogSearch/utils.ts b/frontend/src/components/AuditLog/AuditLogSearch/utils.tsindex a701216b10..682c0d1fde 100644--- a/frontend/src/components/AuditLog/AuditLogSearch/utils.ts+++ b/frontend/src/components/AuditLog/AuditLogSearch/utils.ts@@ -1,6 +1,6 @@import { projectNamePrefix } from "@/store/modules/v1/common";import type { SearchAuditLogsParams } from "@/types";-import { AuditLog_Severity } from "@/types/proto/v1/audit_log_service";+import { AuditLog_Severity } from "@/types/proto-es/v1/audit_log_service_pb";import { getTsRangeFromSearchParams, type SearchParams } from "@/utils";export const buildSearchAuditLogParams = (diff --git a/frontend/src/components/DataExportButton.vue b/frontend/src/components/DataExportButton.vueindex de241a5da9..a964d9e1c8 100644--- a/frontend/src/components/DataExportButton.vue+++ b/frontend/src/components/DataExportButton.vue@@ -138,11 +138,16 @@ import { computed, reactive, ref, watch } from "vue";import { BBModal, BBTextField } from "@/bbkit";import { t } from "@/plugins/i18n";import { pushNotification } from "@/store";-import { ExportFormat, exportFormatToJSON } from "@/types/proto/v1/common";+import { ExportFormat } from "@/types/proto-es/v1/common_pb";import { isNullOrUndefined } from "@/utils";import MaxRowCountSelect from "./GrantRequestPanel/MaxRowCountSelect.vue";import { Drawer, DrawerContent, ErrorTipsButton } from "./v2";+// Helper function to convert ExportFormat to string+function exportFormatToJSON(format: ExportFormat): string {+ return ExportFormat[format];+}+interface LocalState {isRequesting: boolean;showDrawer: boolean;diff --git a/frontend/src/grpcweb/index.ts b/frontend/src/grpcweb/index.tsindex 0a6b41f2d2..abc9569180 100644--- a/frontend/src/grpcweb/index.ts+++ b/frontend/src/grpcweb/index.ts@@ -8,8 +8,8 @@ import {WebsocketTransport,} from "nice-grpc-web";import { ActuatorService } from "@/types/proto-es/v1/actuator_service_pb";+import { AuditLogService } from "@/types/proto-es/v1/audit_log_service_pb";import { AuthService } from "@/types/proto-es/v1/auth_service_pb";-import { AuditLogServiceDefinition } from "@/types/proto/v1/audit_log_service";import { CelServiceDefinition } from "@/types/proto/v1/cel_service";import { ChangelistServiceDefinition } from "@/types/proto/v1/changelist_service";import { DatabaseCatalogServiceDefinition } from "@/types/proto/v1/database_catalog_service";@@ -180,10 +180,6 @@ export const changelistServiceClient = clientFactory.create(channel);-export const auditLogServiceClient = clientFactory.create(- AuditLogServiceDefinition,- channel-);export const groupServiceClient = clientFactory.create(GroupServiceDefinition,@@ -237,3 +233,8 @@ export const actuatorServiceClientConnect = createClient();export const authServiceClientConnect = createClient(AuthService, transport);++export const auditLogServiceClientConnect = createClient(+ AuditLogService,+ transport+);diff --git a/frontend/src/store/modules/v1/auditLog.ts b/frontend/src/store/modules/v1/auditLog.tsindex 8b9d031b50..b3adbe42c2 100644--- a/frontend/src/store/modules/v1/auditLog.ts+++ b/frontend/src/store/modules/v1/auditLog.ts@@ -2,9 +2,14 @@ import dayjs from "dayjs";import utc from "dayjs/plugin/utc";import type { BinaryLike } from "node:crypto";import { defineStore } from "pinia";-import { auditLogServiceClient } from "@/grpcweb";+import { create } from "@bufbuild/protobuf";+import { auditLogServiceClientConnect } from "@/grpcweb";import type { SearchAuditLogsParams } from "@/types";-import type { ExportFormat } from "@/types/proto/v1/common";+import {+ ExportAuditLogsRequestSchema,+ SearchAuditLogsRequestSchema,+} from "@/types/proto-es/v1/audit_log_service_pb";+import { type ExportFormat } from "@/types/proto-es/v1/common_pb";import { userNamePrefix } from "./common";dayjs.extend(utc);@@ -35,13 +40,14 @@ const buildFilter = (search: SearchAuditLogsParams): string => {export const useAuditLogStore = defineStore("audit_log", () => {const fetchAuditLogs = async (search: SearchAuditLogsParams) => {- const resp = await auditLogServiceClient.searchAuditLogs({+ const request = create(SearchAuditLogsRequestSchema, {parent: search.parent,filter: buildFilter(search),orderBy: search.order ? `create_time ${search.order}` : undefined,pageSize: search.pageSize,pageToken: search.pageToken,});+ const resp = await auditLogServiceClientConnect.searchAuditLogs(request);return resp;};@@ -59,7 +65,7 @@ export const useAuditLogStore = defineStore("audit_log", () => {content: BinaryLike | Blob;nextPageToken: string;}> => {- return await auditLogServiceClient.exportAuditLogs({+ const request = create(ExportAuditLogsRequestSchema, {parent: search.parent,filter: buildFilter(search),orderBy: search.order ? `create_time ${search.order}` : undefined,@@ -67,6 +73,7 @@ export const useAuditLogStore = defineStore("audit_log", () => {pageSize,pageToken,});+ return await auditLogServiceClientConnect.exportAuditLogs(request);};return {diff --git a/frontend/src/types/auditLog.ts b/frontend/src/types/auditLog.tsindex f494a74671..35de56edd3 100644--- a/frontend/src/types/auditLog.ts+++ b/frontend/src/types/auditLog.ts@@ -1,4 +1,4 @@-import { AuditLog_Severity } from "./proto/v1/audit_log_service";+import { AuditLog_Severity } from "./proto-es/v1/audit_log_service_pb";export interface SearchAuditLogsParams {parent?: string;diff --git a/frontend/src/types/timestamp.ts b/frontend/src/types/timestamp.tsindex 4c763a0232..3e535014fc 100644--- a/frontend/src/types/timestamp.ts+++ b/frontend/src/types/timestamp.ts@@ -1,4 +1,5 @@import { Timestamp } from "./proto/google/protobuf/timestamp";+import type { Timestamp as TimestampProtoEs } from "@bufbuild/protobuf/wkt";export const getTimeForPbTimestamp = (timestamp?: Timestamp,@@ -18,3 +19,23 @@ export const getDateForPbTimestamp = (}return new Date(getTimeForPbTimestamp(timestamp));};++// Helper functions for proto-es timestamps (which use bigint for seconds)+export const getTimeForPbTimestampProtoEs = (+ timestamp?: TimestampProtoEs,+ defaultValue = Date.now()+): number => {+ if (!timestamp) {+ return defaultValue;+ }+ return Number(timestamp.seconds) * 1000 + timestamp.nanos / 1000000;+};++export const getDateForPbTimestampProtoEs = (+ timestamp?: TimestampProtoEs+): Date | undefined => {+ if (!timestamp) {+ return undefined;+ }+ return new Date(getTimeForPbTimestampProtoEs(timestamp));+};diff --git a/frontend/src/views/SettingWorkspaceAuditLog.vue b/frontend/src/views/SettingWorkspaceAuditLog.vueindex 8455374248..82862e1830 100644--- a/frontend/src/views/SettingWorkspaceAuditLog.vue+++ b/frontend/src/views/SettingWorkspaceAuditLog.vue@@ -60,8 +60,8 @@ import {} from "@/store";import { projectNamePrefix } from "@/store/modules/v1/common";import { type SearchAuditLogsParams } from "@/types";-import type { AuditLog } from "@/types/proto/v1/audit_log_service";-import { ExportFormat } from "@/types/proto/v1/common";+import type { AuditLog } from "@/types/proto-es/v1/audit_log_service_pb";+import { ExportFormat } from "@/types/proto-es/v1/common_pb";import { PlanFeature } from "@/types/proto/v1/subscription_service";import { type SearchParams, extractProjectResourceName } from "@/utils";diff --git a/frontend/src/views/project/ProjectAuditLogDashboard.vue b/frontend/src/views/project/ProjectAuditLogDashboard.vueindex 73efc4d311..eecb4aa6c4 100644--- a/frontend/src/views/project/ProjectAuditLogDashboard.vue+++ b/frontend/src/views/project/ProjectAuditLogDashboard.vue@@ -56,8 +56,8 @@ import { FeatureAttention } from "@/components/FeatureGuard";import PagedTable from "@/components/v2/Model/PagedTable.vue";import { featureToRef, useAuditLogStore, useUserStore } from "@/store";import { type SearchAuditLogsParams } from "@/types";-import type { AuditLog } from "@/types/proto/v1/audit_log_service";-import { ExportFormat } from "@/types/proto/v1/common";+import type { AuditLog } from "@/types/proto-es/v1/audit_log_service_pb";+import { ExportFormat } from "@/types/proto-es/v1/common_pb";import { PlanFeature } from "@/types/proto/v1/subscription_service";import type { SearchParams, SearchScope } from "@/utils";diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vueindex 6bd73635be..e081d59ce6 100644--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue@@ -234,7 +234,8 @@ import {isValidDatabaseName,isValidInstanceName,} from "@/types";-import { Engine, ExportFormat } from "@/types/proto/v1/common";+import { Engine, ExportFormat as ExportFormatOld } from "@/types/proto/v1/common";+import { ExportFormat } from "@/types/proto-es/v1/common_pb";import { PolicyType } from "@/types/proto/v1/org_policy_service";import { DatabaseChangeMode } from "@/types/proto/v1/setting_service";import type {@@ -260,6 +261,13 @@ import ErrorView from "./ErrorView";import SelectionCopyTooltips from "./SelectionCopyTooltips.vue";import { useSQLResultViewContext } from "./context";+// Temporary conversion function until SQL store is migrated+const convertExportFormat = (format: ExportFormat): ExportFormatOld => {+ // Convert proto-es enum to string, then back to old enum+ const formatString = ExportFormat[format];+ return ExportFormatOld[formatString as keyof typeof ExportFormatOld] ?? ExportFormatOld.FORMAT_UNSPECIFIED;+};+type LocalState = {search: string;vertical: boolean;@@ -479,7 +487,7 @@ const handleExportBtnClick = async ({const content = await useSQLStore().exportData({name: props.database.name,dataSourceId: props.params.connection.dataSourceId ?? "",- format: options.format,+ format: convertExportFormat(options.format),statement,limit,admin,diff --git a/frontend/src/views/sql-editor/EditorPanel/ResultPanel/BatchQuerySelect.vue b/frontend/src/views/sql-editor/EditorPanel/ResultPanel/BatchQuerySelect.vueindex eb2b0572c7..1a3c1be3d7 100644--- a/frontend/src/views/sql-editor/EditorPanel/ResultPanel/BatchQuerySelect.vue+++ b/frontend/src/views/sql-editor/EditorPanel/ResultPanel/BatchQuerySelect.vue@@ -124,9 +124,17 @@ import {useSQLStore,} from "@/store";import type { ComposedDatabase, SQLEditorDatabaseQueryContext } from "@/types";-import { ExportFormat } from "@/types/proto/v1/common";+import { ExportFormat as ExportFormatOld } from "@/types/proto/v1/common";+import { ExportFormat } from "@/types/proto-es/v1/common_pb";import { hexToRgb } from "@/utils";+// Temporary conversion function until SQL store is migrated+const convertExportFormat = (format: ExportFormat): ExportFormatOld => {+ // Convert proto-es enum to string, then back to old enum+ const formatString = ExportFormat[format];+ return ExportFormatOld[formatString as keyof typeof ExportFormatOld] ?? ExportFormatOld.FORMAT_UNSPECIFIED;+};+const MAX_EXPORT = 20;type BatchQueryItem = {@@ -274,7 +282,7 @@ const handleExportBtnClick = async ({const content = await sqlStore.exportData({name: databaseName,dataSourceId: context.params.connection.dataSourceId ?? "",- format: options.format,+ format: convertExportFormat(options.format),statement: context.params.statement,limit: options.limit,admin: tabStore.currentTab?.mode === "ADMIN",