Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: support redirect to the resource in the audit log (#17728)
ecmadaofb32df2129a1
diff --git a/frontend/src/components/AuditLog/AuditLogDataTable.vue b/frontend/src/components/AuditLog/AuditLogDataTable.vueindex b7c210ed53..ff75fb8b42 100644--- a/frontend/src/components/AuditLog/AuditLogDataTable.vue+++ b/frontend/src/components/AuditLog/AuditLogDataTable.vue@@ -13,12 +13,17 @@import { file_google_rpc_error_details } from "@buf/googleapis_googleapis.bufbuild_es/google/rpc/error_details_pb";import { createRegistry, fromBinary, toJsonString } from "@bufbuild/protobuf";import dayjs from "dayjs";-import { NDataTable, type DataTableColumn } from "naive-ui";+import { ExternalLinkIcon } from "lucide-vue-next";+import { NButton, NDataTable, type DataTableColumn } from "naive-ui";import { computed } from "vue";import { useI18n } from "vue-i18n";import BBAvatar from "@/bbkit/BBAvatar.vue";import { useProjectV1Store, useUserStore } from "@/store";-import { projectNamePrefix } from "@/store/modules/v1/common";+import {+ projectNamePrefix,+ rolloutNamePrefix,+ getProjectIdRolloutUidStageUid,+} from "@/store/modules/v1/common";import { getDateForPbTimestampProtoEs } from "@/types";import { StatusSchema } from "@/types/proto-es/google/rpc/status_pb";import type { AuditLog } from "@/types/proto-es/v1/audit_log_service_pb";@@ -26,8 +31,18 @@ import {AuditDataSchema,AuditLog_Severity,} from "@/types/proto-es/v1/audit_log_service_pb";+import { IssueService, type Issue } from "@/types/proto-es/v1/issue_service_pb";import { file_v1_plan_service } from "@/types/proto-es/v1/plan_service_pb";+import { PlanService, type Plan } from "@/types/proto-es/v1/plan_service_pb";+import {+ RolloutService,+ type Rollout,+} from "@/types/proto-es/v1/rollout_service_pb";import { SettingSchema } from "@/types/proto-es/v1/setting_service_pb";+import {+ SQLService,+ type ExportRequest,+} from "@/types/proto-es/v1/sql_service_pb";import { humanizeDurationV1 } from "@/utils";import { extractProjectResourceName } from "@/utils";import JSONStringView from "./JSONStringView.vue";@@ -196,11 +211,32 @@ const columnList = computed((): AuditDataTableColumn[] => {);},},+ {+ key: "view",+ width: 60,+ title: t("common.view"),+ render: (auditLog) => {+ let link = getViewLink(auditLog);+ if (!link) {+ return null;+ }+ if (!link.startsWith("/")) {+ link = `/${link}`;+ }+ return (+ <a href={link} target="_blank">+ <NButton size="small" text type="primary">+ <ExternalLinkIcon class={"w-4"} />+ </NButton>+ </a>+ );+ },+ },] as AuditDataTableColumn[]).filter((column) => !column.hide);});-function getServiceDataValue(typeUrl: string, value: Uint8Array): any {+const getServiceDataValue = (typeUrl: string, value: Uint8Array): any => {switch (typeUrl) {case "type.googleapis.com/bytebase.v1.AuditData":return fromBinary(AuditDataSchema, value);@@ -209,5 +245,43 @@ function getServiceDataValue(typeUrl: string, value: Uint8Array): any {default:return null;}-}+};++const getViewLink = (auditLog: AuditLog): string | null => {+ let parsedRequest: any;+ let parsedResponse: any;+ try {+ parsedRequest = JSON.parse(auditLog.request || "{}");+ parsedResponse = JSON.parse(auditLog.response || "{}");+ } catch {+ return null;+ }+ if (Boolean(parsedRequest["validateOnly"])) {+ return null;+ }++ const sections = auditLog.method.split("/").filter((i) => i);+ switch (sections[0]) {+ case RolloutService.typeName:+ return (parsedResponse as Rollout).name;+ case PlanService.typeName:+ return (parsedResponse as Plan).name;+ case IssueService.typeName:+ return (parsedResponse as Issue).name;+ case SQLService.typeName:+ if (sections[1] !== "Export") {+ return null;+ }+ const name = (parsedRequest as ExportRequest).name;+ if (!name) {+ return null;+ }+ const [projectId, rolloutId, _] = getProjectIdRolloutUidStageUid(name);+ if (!projectId || !rolloutId) {+ return null;+ }+ return `${projectNamePrefix}${projectId}/${rolloutNamePrefix}${rolloutId}`;+ }+ return null;+};</script>diff --git a/frontend/src/components/AuditLog/JSONStringView.vue b/frontend/src/components/AuditLog/JSONStringView.vueindex 3e0bc94a06..f8ea189d20 100644--- a/frontend/src/components/AuditLog/JSONStringView.vue+++ b/frontend/src/components/AuditLog/JSONStringView.vue@@ -44,6 +44,10 @@ const props = defineProps<{const showModal = ref(false);const formattedJSONString = computed(() => {- return JSON.stringify(JSON.parse(props.jsonString), null, 2);+ try {+ return JSON.stringify(JSON.parse(props.jsonString), null, 2);+ } catch {+ return "-";+ }});</script>diff --git a/frontend/src/store/modules/v1/common.ts b/frontend/src/store/modules/v1/common.tsindex 36b0567d20..c4111280b2 100644--- a/frontend/src/store/modules/v1/common.ts+++ b/frontend/src/store/modules/v1/common.ts@@ -84,6 +84,15 @@ export const getProjectNamePlanIdPlanCheckRunId = (name: string): string[] => {return [tokens[0], tokens[1], tokens[2]];};+export const getProjectIdRolloutUidStageUid = (name: string): string[] => {+ const tokens = getNameParentTokens(name, [+ projectNamePrefix,+ rolloutNamePrefix,+ stageNamePrefix,+ ]);+ return [tokens[0], tokens[1], tokens[2]];+};+export const getProjectIdRolloutUidStageUidTaskUid = (name: string): string[] => {