Skip to content

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

chore: prepare fe access store (#19330)

ecmadaoe928411150e6
diff --git a/backend/api/v1/access_grant_service.go b/backend/api/v1/access_grant_service.go
index c1a7d5d90a..a9013160fd 100644
--- a/backend/api/v1/access_grant_service.go
+++ b/backend/api/v1/access_grant_service.go
@@ -184,6 +184,7 @@ func (s *AccessGrantService) CreateAccessGrant(ctx context.Context, request *con
Approval: &storepb.IssuePayloadApproval{
ApprovalFindingDone: false,
},
+ AccessGrantId: grant.ID,
},
})
if err != nil {
diff --git a/backend/api/v1/issue_hook.go b/backend/api/v1/issue_hook.go
index 0bb8c604f8..d87a9dc197 100644
--- a/backend/api/v1/issue_hook.go
+++ b/backend/api/v1/issue_hook.go
@@ -48,14 +48,11 @@ func postCreateIssue(
storepb.Issue_GRANT_REQUEST,
storepb.Issue_DATABASE_EXPORT:
- if issue.Type != storepb.Issue_ACCESS_GRANT {
- // TODO: approval flow for the ACCESS_GRANT issue
- if err := approval.FindAndApplyApprovalTemplate(ctx, stores, webhookManager, licenseService, issue); err != nil {
- slog.Error("failed to find approval template",
- slog.Int("issue_uid", issue.UID),
- slog.String("issue_title", issue.Title),
- log.BBError(err))
- }
+ if err := approval.FindAndApplyApprovalTemplate(ctx, stores, webhookManager, licenseService, issue); err != nil {
+ slog.Error("failed to find approval template",
+ slog.Int("issue_uid", issue.UID),
+ slog.String("issue_title", issue.Title),
+ log.BBError(err))
}
// Refresh issue to get updated approval payload.
diff --git a/backend/api/v1/issue_service_converter.go b/backend/api/v1/issue_service_converter.go
index d5620c36e9..ffa9f57d8a 100644
--- a/backend/api/v1/issue_service_converter.go
+++ b/backend/api/v1/issue_service_converter.go
@@ -97,6 +97,10 @@ func (*IssueService) convertToIssue(issue *store.IssueMessage) (*v1pb.Issue, err
Labels: issuePayload.Labels,
}
+ if issuePayload.AccessGrantId != "" {
+ issueV1.AccessGrant = common.FormatAccessGrant(issue.ProjectID, issuePayload.AccessGrantId)
+ }
+
if issue.PlanUID != nil {
issueV1.Plan = common.FormatPlan(issue.ProjectID, *issue.PlanUID)
}
@@ -177,6 +181,8 @@ func convertToIssueType(t storepb.Issue_Type) v1pb.Issue_Type {
return v1pb.Issue_GRANT_REQUEST
case storepb.Issue_DATABASE_EXPORT:
return v1pb.Issue_DATABASE_EXPORT
+ case storepb.Issue_ACCESS_GRANT:
+ return v1pb.Issue_ACCESS_GRANT
default:
return v1pb.Issue_TYPE_UNSPECIFIED
}
@@ -190,6 +196,8 @@ func convertToAPIIssueType(t v1pb.Issue_Type) (storepb.Issue_Type, error) {
return storepb.Issue_GRANT_REQUEST, nil
case v1pb.Issue_DATABASE_EXPORT:
return storepb.Issue_DATABASE_EXPORT, nil
+ case v1pb.Issue_ACCESS_GRANT:
+ return storepb.Issue_ACCESS_GRANT, nil
default:
return storepb.Issue_ISSUE_TYPE_UNSPECIFIED, errors.Errorf("invalid issue type %v", t)
}
diff --git a/backend/runner/approval/runner.go b/backend/runner/approval/runner.go
index 98e2768cbc..0b188e4b95 100644
--- a/backend/runner/approval/runner.go
+++ b/backend/runner/approval/runner.go
@@ -369,7 +369,6 @@ func buildFallbackCELVars(celVarsList []map[string]any) []map[string]any {
// Returns a list of CEL variable maps (one per task/component), done flag, and error.
// done=false means the caller should retry later (e.g., waiting for plan check runs).
func buildCELVariablesForIssue(ctx context.Context, stores *store.Store, issue *store.IssueMessage) ([]map[string]any, bool, error) {
- // TODO: do we need different approval flow for the ACCESS_GRANT issue?
switch issue.Type {
case storepb.Issue_GRANT_REQUEST:
return buildCELVariablesForGrantRequest(ctx, stores, issue)
@@ -377,6 +376,9 @@ func buildCELVariablesForIssue(ctx context.Context, stores *store.Store, issue *
return buildCELVariablesForDatabaseChange(ctx, stores, issue)
case storepb.Issue_DATABASE_EXPORT:
return buildCELVariablesForDataExport(ctx, stores, issue)
+ case storepb.Issue_ACCESS_GRANT:
+ // TODO: approval flow for the ACCESS_GRANT issue
+ return nil, true, nil
default:
return nil, false, errors.Errorf("unknown issue type %v", issue.Type)
}
@@ -803,6 +805,9 @@ func getApprovalSourceFromIssue(ctx context.Context, stores *store.Store, issue
return getApprovalSourceFromPlan(plan.Config), nil
case storepb.Issue_DATABASE_EXPORT:
return storepb.WorkspaceApprovalSetting_Rule_EXPORT_DATA, nil
+ case storepb.Issue_ACCESS_GRANT:
+ // TODO: the approval source type for access request
+ return storepb.WorkspaceApprovalSetting_Rule_SOURCE_UNSPECIFIED, nil
default:
return storepb.WorkspaceApprovalSetting_Rule_SOURCE_UNSPECIFIED, errors.Errorf("unknown issue type %v", issue.Type)
}
diff --git a/frontend/src/connect/index.ts b/frontend/src/connect/index.ts
index 90c3afe577..1f2307dac2 100644
--- a/frontend/src/connect/index.ts
+++ b/frontend/src/connect/index.ts
@@ -1,6 +1,7 @@
import { createClient } from "@connectrpc/connect";
import { createConnectTransport } from "@connectrpc/connect-web";
import { createRegistry } from "@bufbuild/protobuf";
+import { AccessGrantService } from "@/types/proto-es/v1/access_grant_service_pb";
import { ActuatorService } from "@/types/proto-es/v1/actuator_service_pb";
import {
AuditDataSchema,
@@ -62,6 +63,11 @@ const transport = createConnectTransport({
},
});
+export const accessGrantServiceClientConnect = createClient(
+ AccessGrantService,
+ transport
+);
+
export const actuatorServiceClientConnect = createClient(
ActuatorService,
transport
diff --git a/frontend/src/store/modules/accessGrant.ts b/frontend/src/store/modules/accessGrant.ts
new file mode 100644
index 0000000000..9293bcd476
--- /dev/null
+++ b/frontend/src/store/modules/accessGrant.ts
@@ -0,0 +1,102 @@
+import { create } from "@bufbuild/protobuf";
+import { defineStore } from "pinia";
+import { accessGrantServiceClientConnect } from "@/connect";
+import type { AccessGrant } from "@/types/proto-es/v1/access_grant_service_pb";
+import {
+ AccessGrant_Status,
+ CreateAccessGrantRequestSchema,
+ SearchMyAccessGrantsRequestSchema,
+} from "@/types/proto-es/v1/access_grant_service_pb";
+
+export interface AccessFilter {
+ name?: string;
+ statement?: string;
+ creator?: string;
+ status?: AccessGrant_Status;
+ issue?: string;
+ createdTsAfter?: number;
+ createdTsBefore?: number;
+ expireTsAfter?: number;
+ expireTsBefore?: number;
+}
+
+const getListAccessFilter = (filter: AccessFilter | undefined): string => {
+ if (!filter) return "";
+ const parts: string[] = [];
+
+ if (filter.name) {
+ parts.push(`name == "${filter.name}"`);
+ }
+ if (
+ filter.status !== undefined &&
+ filter.status !== AccessGrant_Status.STATUS_UNSPECIFIED
+ ) {
+ parts.push(`status == "${AccessGrant_Status[filter.status]}"`);
+ }
+ if (filter.statement) {
+ parts.push(`query == "${filter.statement}"`);
+ }
+ if (filter.creator) {
+ parts.push(`creator == "${filter.creator}"`);
+ }
+ if (filter.issue) {
+ parts.push(`issue == "${filter.issue}"`);
+ }
+ if (filter.createdTsAfter !== undefined) {
+ parts.push(
+ `create_time >= "${new Date(filter.createdTsAfter).toISOString()}"`
+ );
+ }
+ if (filter.createdTsBefore !== undefined) {
+ parts.push(
+ `create_time <= "${new Date(filter.createdTsBefore).toISOString()}"`
+ );
+ }
+ if (filter.expireTsAfter !== undefined) {
+ parts.push(
+ `expire_time >= "${new Date(filter.expireTsAfter).toISOString()}"`
+ );
+ }
+ if (filter.expireTsBefore !== undefined) {
+ parts.push(
+ `expire_time <= "${new Date(filter.expireTsBefore).toISOString()}"`
+ );
+ }
+
+ return parts.join(" && ");
+};
+
+export const useAccessGrantStore = defineStore("accessGrant", () => {
+ const searchMyAccessGrants = async (
+ parent: string,
+ filter?: AccessFilter,
+ pageSize?: number,
+ pageToken?: string
+ ) => {
+ return await accessGrantServiceClientConnect.searchMyAccessGrants(
+ create(SearchMyAccessGrantsRequestSchema, {
+ parent,
+ filter: getListAccessFilter(filter),
+ pageSize: pageSize ?? 0,
+ pageToken: pageToken ?? "",
+ })
+ );
+ };
+
+ const createAccessGrant = async (
+ parent: string,
+ accessGrant: AccessGrant
+ ) => {
+ return await accessGrantServiceClientConnect.createAccessGrant(
+ create(CreateAccessGrantRequestSchema, {
+ parent,
+ accessGrant,
+ })
+ );
+ };
+
+ return {
+ searchMyAccessGrants,
+ createAccessGrant,
+ };
+});
diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.ts
index 588d1875f0..9b915ea2bc 100644
--- a/frontend/src/store/modules/index.ts
+++ b/frontend/src/store/modules/index.ts
@@ -1,3 +1,4 @@
+export * from "./accessGrant";
export * from "./v1/auth";
export * from "./help";
export * from "./notification";