Skip to content

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

chore: update filter for access api (#19328)

ecmadao8f762f2934a1
diff --git a/backend/api/mcp/gen/openapi.yaml b/backend/api/mcp/gen/openapi.yaml
index 2e3ec9dbcd..f57eae5494 100644
--- a/backend/api/mcp/gen/openapi.yaml
+++ b/backend/api/mcp/gen/openapi.yaml
@@ -11892,13 +11892,22 @@ components:
title: filter
description: |-
Filter expression using AIP-160 syntax.
- Supported fields: name, creator, status, issue, expire_time, create_time
+ Supported fields:
+ - name: the fullname in "projects/{project}/accessGrants/{access_grant}" format, support "==" operator.
+ - creator: the creator name in "users/{email}" format, support "==" operator.
+ - status: the access status, support "==" and "in" operator.
+ - issue: the access issue fullname, support "==" operator.
+ - expire_time: the access expire time in "2006-01-02T15:04:05Z07:00" format, support ">=", ">", "<=" and "<" operator.
+ - create_time: the access creation time in "2006-01-02T15:04:05Z07:00" format, support ">=", ">", "<=" and "<" operator.
+ - query: the access query, support "==" and ".contains(xx)" operator
+
Examples:
- - 'creator = "users/[email protected]"'
- - 'status = "ACTIVE"'
- - 'creator = "users/[email protected]" AND status = "ACTIVE"'
- - 'issue = "projects/x/issues/123"'
- - 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"'
+ - creator == "users/[email protected]"
+ - status == "ACTIVE"
+ - status in ["ACTIVE", "PENDING"]
+ - creator == "users/[email protected]" && status == "ACTIVE"
+ - issue == "projects/x/issues/123"
+ - status == "ACTIVE" && expire_time > "2024-02-01T00:00:00Z"
title: ListAccessGrantsRequest
additionalProperties: false
bytebase.v1.ListAccessGrantsResponse:
diff --git a/backend/generated-go/v1/access_grant_service.pb.go b/backend/generated-go/v1/access_grant_service.pb.go
index 05f2347b38..5703312c92 100644
--- a/backend/generated-go/v1/access_grant_service.pb.go
+++ b/backend/generated-go/v1/access_grant_service.pb.go
@@ -314,13 +314,22 @@ type ListAccessGrantsRequest struct {
// A page token from a previous ListAccessGrants call.
PageToken string `protobuf:"bytes,3,opt,name=page_token,json=pageToken,proto3" json:"page_token,omitempty"`
// Filter expression using AIP-160 syntax.
- // Supported fields: name, creator, status, issue, expire_time, create_time
+ // Supported fields:
+ // - name: the fullname in "projects/{project}/accessGrants/{access_grant}" format, support "==" operator.
+ // - creator: the creator name in "users/{email}" format, support "==" operator.
+ // - status: the access status, support "==" and "in" operator.
+ // - issue: the access issue fullname, support "==" operator.
+ // - expire_time: the access expire time in "2006-01-02T15:04:05Z07:00" format, support ">=", ">", "<=" and "<" operator.
+ // - create_time: the access creation time in "2006-01-02T15:04:05Z07:00" format, support ">=", ">", "<=" and "<" operator.
+ // - query: the access query, support "==" and ".contains(xx)" operator
+ //
// Examples:
- // - 'creator = "users/[email protected]"'
- // - 'status = "ACTIVE"'
- // - 'creator = "users/[email protected]" AND status = "ACTIVE"'
- // - 'issue = "projects/x/issues/123"'
- // - 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"'
+ // - creator == "users/[email protected]"
+ // - status == "ACTIVE"
+ // - status in ["ACTIVE", "PENDING"]
+ // - creator == "users/[email protected]" && status == "ACTIVE"
+ // - issue == "projects/x/issues/123"
+ // - status == "ACTIVE" && expire_time > "2024-02-01T00:00:00Z"
Filter string `protobuf:"bytes,4,opt,name=filter,proto3" json:"filter,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
diff --git a/backend/store/access_grant.go b/backend/store/access_grant.go
index d4b7bbc566..5a408a5368 100644
--- a/backend/store/access_grant.go
+++ b/backend/store/access_grant.go
@@ -8,6 +8,7 @@ import (
"github.com/google/cel-go/cel"
celast "github.com/google/cel-go/common/ast"
celoperators "github.com/google/cel-go/common/operators"
+ celoverloads "github.com/google/cel-go/common/overloads"
"github.com/google/uuid"
"github.com/pkg/errors"
"google.golang.org/protobuf/encoding/protojson"
@@ -289,11 +290,65 @@ func GetListAccessGrantFilter(filter string) (*qb.Query, error) {
return nil, errors.Errorf("status value must be a string")
}
return qb.Q().Space("access_grant.status = ?", statusStr), nil
+ case "query":
+ queryStr, ok := value.(string)
+ if !ok {
+ return nil, errors.Errorf("query value must be a string")
+ }
+ return qb.Q().Space("access_grant.payload->>'query' = ?", queryStr), nil
case "issue":
- return nil, errors.Errorf("filtering by issue is not supported yet")
+ issueStr, ok := value.(string)
+ if !ok {
+ return nil, errors.Errorf("issue value must be a string")
+ }
+ _, issueUID, err := common.GetProjectIDIssueUID(issueStr)
+ if err != nil {
+ return nil, errors.Wrapf(err, "invalid issue name %q", issueStr)
+ }
+ return qb.Q().Space("(access_grant.payload->>'issueId')::bigint = ?", issueUID), nil
default:
return nil, errors.Errorf("unsupported variable %q", variable)
}
+ case celoverloads.Matches:
+ call := expr.AsCall()
+ target := call.Target()
+ if target.Kind() != celast.IdentKind {
+ return nil, errors.Errorf("contains target must be an identifier")
+ }
+ variable := target.AsIdent()
+ if variable != "query" {
+ return nil, errors.Errorf("contains is not supported on field %q", variable)
+ }
+ args := call.Args()
+ if len(args) != 1 || args[0].Kind() != celast.LiteralKind {
+ return nil, errors.Errorf("contains requires a single string literal argument")
+ }
+ value, ok := args[0].AsLiteral().Value().(string)
+ if !ok {
+ return nil, errors.Errorf("contains argument must be a string")
+ }
+ return qb.Q().Space("access_grant.payload->>'query' ILIKE ?", "%"+value+"%"), nil
+ case celoperators.In:
+ variable, value := getVariableAndValueFromExpr(expr)
+ if variable != "status" {
+ return nil, errors.Errorf("unsupported variable %q for \"in\" operator", variable)
+ }
+ rawList, ok := value.([]any)
+ if !ok {
+ return nil, errors.Errorf("invalid list value %q for %v", value, variable)
+ }
+ if len(rawList) == 0 {
+ return nil, errors.Errorf("empty list value for filter %v", variable)
+ }
+ var statuses []string
+ for _, raw := range rawList {
+ s, ok := raw.(string)
+ if !ok {
+ return nil, errors.Errorf("status value must be a string")
+ }
+ statuses = append(statuses, s)
+ }
+ return qb.Q().Space("access_grant.status = ANY(?)", statuses), nil
case celoperators.GreaterEquals, celoperators.LessEquals, celoperators.Greater, celoperators.Less:
variable, rawValue := getVariableAndValueFromExpr(expr)
value, ok := rawValue.(string)
diff --git a/frontend/src/types/proto-es/v1/access_grant_service_pb.d.ts b/frontend/src/types/proto-es/v1/access_grant_service_pb.d.ts
index 535140948f..75e22090c8 100644
--- a/frontend/src/types/proto-es/v1/access_grant_service_pb.d.ts
+++ b/frontend/src/types/proto-es/v1/access_grant_service_pb.d.ts
@@ -202,13 +202,22 @@ export declare type ListAccessGrantsRequest = Message<"bytebase.v1.ListAccessGra
/**
* Filter expression using AIP-160 syntax.
- * Supported fields: name, creator, status, issue, expire_time, create_time
+ * Supported fields:
+ * - name: the fullname in "projects/{project}/accessGrants/{access_grant}" format, support "==" operator.
+ * - creator: the creator name in "users/{email}" format, support "==" operator.
+ * - status: the access status, support "==" and "in" operator.
+ * - issue: the access issue fullname, support "==" operator.
+ * - expire_time: the access expire time in "2006-01-02T15:04:05Z07:00" format, support ">=", ">", "<=" and "<" operator.
+ * - create_time: the access creation time in "2006-01-02T15:04:05Z07:00" format, support ">=", ">", "<=" and "<" operator.
+ * - query: the access query, support "==" and ".contains(xx)" operator
+ *
* Examples:
- * - 'creator = "users/[email protected]"'
- * - 'status = "ACTIVE"'
- * - 'creator = "users/[email protected]" AND status = "ACTIVE"'
- * - 'issue = "projects/x/issues/123"'
- * - 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"'
+ * - creator == "users/[email protected]"
+ * - status == "ACTIVE"
+ * - status in ["ACTIVE", "PENDING"]
+ * - creator == "users/[email protected]" && status == "ACTIVE"
+ * - issue == "projects/x/issues/123"
+ * - status == "ACTIVE" && expire_time > "2024-02-01T00:00:00Z"
*
* @generated from field: string filter = 4;
*/
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index 0a2066e754..e9eb25535b 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -7204,25 +7204,43 @@ paths:
in: query
description: |-
Filter expression using AIP-160 syntax.
- Supported fields: name, creator, status, issue, expire_time, create_time
+ Supported fields:
+ - name: the fullname in "projects/{project}/accessGrants/{access_grant}" format, support "==" operator.
+ - creator: the creator name in "users/{email}" format, support "==" operator.
+ - status: the access status, support "==" and "in" operator.
+ - issue: the access issue fullname, support "==" operator.
+ - expire_time: the access expire time in "2006-01-02T15:04:05Z07:00" format, support ">=", ">", "<=" and "<" operator.
+ - create_time: the access creation time in "2006-01-02T15:04:05Z07:00" format, support ">=", ">", "<=" and "<" operator.
+ - query: the access query, support "==" and ".contains(xx)" operator
+
Examples:
- - 'creator = "users/[email protected]"'
- - 'status = "ACTIVE"'
- - 'creator = "users/[email protected]" AND status = "ACTIVE"'
- - 'issue = "projects/x/issues/123"'
- - 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"'
+ - creator == "users/[email protected]"
+ - status == "ACTIVE"
+ - status in ["ACTIVE", "PENDING"]
+ - creator == "users/[email protected]" && status == "ACTIVE"
+ - issue == "projects/x/issues/123"
+ - status == "ACTIVE" && expire_time > "2024-02-01T00:00:00Z"
schema:
type: string
title: filter
description: |-
Filter expression using AIP-160 syntax.
- Supported fields: name, creator, status, issue, expire_time, create_time
+ Supported fields:
+ - name: the fullname in "projects/{project}/accessGrants/{access_grant}" format, support "==" operator.
+ - creator: the creator name in "users/{email}" format, support "==" operator.
+ - status: the access status, support "==" and "in" operator.
+ - issue: the access issue fullname, support "==" operator.
+ - expire_time: the access expire time in "2006-01-02T15:04:05Z07:00" format, support ">=", ">", "<=" and "<" operator.
+ - create_time: the access creation time in "2006-01-02T15:04:05Z07:00" format, support ">=", ">", "<=" and "<" operator.
+ - query: the access query, support "==" and ".contains(xx)" operator
+
Examples:
- - 'creator = "users/[email protected]"'
- - 'status = "ACTIVE"'
- - 'creator = "users/[email protected]" AND status = "ACTIVE"'
- - 'issue = "projects/x/issues/123"'
- - 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"'
+ - creator == "users/[email protected]"
+ - status == "ACTIVE"
+ - status in ["ACTIVE", "PENDING"]
+ - creator == "users/[email protected]" && status == "ACTIVE"
+ - issue == "projects/x/issues/123"
+ - status == "ACTIVE" && expire_time > "2024-02-01T00:00:00Z"
responses:
"200":
description: Success
@@ -21087,13 +21105,22 @@ components:
title: filter
description: |-
Filter expression using AIP-160 syntax.
- Supported fields: name, creator, status, issue, expire_time, create_time
+ Supported fields:
+ - name: the fullname in "projects/{project}/accessGrants/{access_grant}" format, support "==" operator.
+ - creator: the creator name in "users/{email}" format, support "==" operator.
+ - status: the access status, support "==" and "in" operator.
+ - issue: the access issue fullname, support "==" operator.
+ - expire_time: the access expire time in "2006-01-02T15:04:05Z07:00" format, support ">=", ">", "<=" and "<" operator.
+ - create_time: the access creation time in "2006-01-02T15:04:05Z07:00" format, support ">=", ">", "<=" and "<" operator.
+ - query: the access query, support "==" and ".contains(xx)" operator
+
Examples:
- - 'creator = "users/[email protected]"'
- - 'status = "ACTIVE"'
- - 'creator = "users/[email protected]" AND status = "ACTIVE"'
- - 'issue = "projects/x/issues/123"'
- - 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"'
+ - creator == "users/[email protected]"
+ - status == "ACTIVE"
+ - status in ["ACTIVE", "PENDING"]
+ - creator == "users/[email protected]" && status == "ACTIVE"
+ - issue == "projects/x/issues/123"
+ - status == "ACTIVE" && expire_time > "2024-02-01T00:00:00Z"
title: ListAccessGrantsRequest
required:
- parent
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index a4335b49da..6a8c367ebd 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -836,7 +836,9 @@ Authorization method for RPC calls.
| parent | [string](#string) | | The parent project of the access grants. Format: projects/{project} |
| page_size | [int32](#int32) | | The maximum number of access grants to return. |
| page_token | [string](#string) | | A page token from a previous ListAccessGrants call. |
-| filter | [string](#string) | | Filter expression using AIP-160 syntax. Supported fields: name, creator, status, issue, expire_time, create_time Examples: - &#39;creator = &#34;users/[email protected]&#34;&#39; - &#39;status = &#34;ACTIVE&#34;&#39; - &#39;creator = &#34;users/[email protected]&#34; AND status = &#34;ACTIVE&#34;&#39; - &#39;issue = &#34;projects/x/issues/123&#34;&#39; - &#39;status = &#34;ACTIVE&#34; AND expire_time &gt; &#34;2024-02-01T00:00:00Z&#34;&#39; |
+| filter | [string](#string) | | Filter expression using AIP-160 syntax. Supported fields: - name: the fullname in &#34;projects/{project}/accessGrants/{access_grant}&#34; format, support &#34;==&#34; operator. - creator: the creator name in &#34;users/{email}&#34; format, support &#34;==&#34; operator. - status: the access status, support &#34;==&#34; and &#34;in&#34; operator. - issue: the access issue fullname, support &#34;==&#34; operator. - expire_time: the access expire time in &#34;2006-01-02T15:04:05Z07:00&#34; format, support &#34;&gt;=&#34;, &#34;&gt;&#34;, &#34;&lt;=&#34; and &#34;&lt;&#34; operator. - create_time: the access creation time in &#34;2006-01-02T15:04:05Z07:00&#34; format, support &#34;&gt;=&#34;, &#34;&gt;&#34;, &#34;&lt;=&#34; and &#34;&lt;&#34; operator. - query: the access query, support &#34;==&#34; and &#34;.contains(xx)&#34; operator
+
+Examples: - creator == &#34;users/[email protected]&#34; - status == &#34;ACTIVE&#34; - status in [&#34;ACTIVE&#34;, &#34;PENDING&#34;] - creator == &#34;users/[email protected]&#34; &amp;&amp; status == &#34;ACTIVE&#34; - issue == &#34;projects/x/issues/123&#34; - status == &#34;ACTIVE&#34; &amp;&amp; expire_time &gt; &#34;2024-02-01T00:00:00Z&#34; |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index 109cedfc52..8834693dd8 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -3176,13 +3176,22 @@ Format: projects/{project} </p></td>
<td><a href="#string">string</a></td>
<td></td>
<td><p>Filter expression using AIP-160 syntax.
-Supported fields: name, creator, status, issue, expire_time, create_time
+Supported fields:
+- name: the fullname in &#34;projects/{project}/accessGrants/{access_grant}&#34; format, support &#34;==&#34; operator.
+- creator: the creator name in &#34;users/{email}&#34; format, support &#34;==&#34; operator.
+- status: the access status, support &#34;==&#34; and &#34;in&#34; operator.
+- issue: the access issue fullname, support &#34;==&#34; operator.
+- expire_time: the access expire time in &#34;2006-01-02T15:04:05Z07:00&#34; format, support &#34;&gt;=&#34;, &#34;&gt;&#34;, &#34;&lt;=&#34; and &#34;&lt;&#34; operator.
+- create_time: the access creation time in &#34;2006-01-02T15:04:05Z07:00&#34; format, support &#34;&gt;=&#34;, &#34;&gt;&#34;, &#34;&lt;=&#34; and &#34;&lt;&#34; operator.
+- query: the access query, support &#34;==&#34; and &#34;.contains(xx)&#34; operator
+
Examples:
- - &#39;creator = &#34;users/[email protected]&#34;&#39;
- - &#39;status = &#34;ACTIVE&#34;&#39;
- - &#39;creator = &#34;users/[email protected]&#34; AND status = &#34;ACTIVE&#34;&#39;
- - &#39;issue = &#34;projects/x/issues/123&#34;&#39;
- - &#39;status = &#34;ACTIVE&#34; AND expire_time &gt; &#34;2024-02-01T00:00:00Z&#34;&#39; </p></td>
+- creator == &#34;users/[email protected]&#34;
+- status == &#34;ACTIVE&#34;
+- status in [&#34;ACTIVE&#34;, &#34;PENDING&#34;]
+- creator == &#34;users/[email protected]&#34; &amp;&amp; status == &#34;ACTIVE&#34;
+- issue == &#34;projects/x/issues/123&#34;
+- status == &#34;ACTIVE&#34; &amp;&amp; expire_time &gt; &#34;2024-02-01T00:00:00Z&#34; </p></td>
</tr>
</tbody>
diff --git a/proto/v1/v1/access_grant_service.proto b/proto/v1/v1/access_grant_service.proto
index f55ce2bc75..5bf789b3cb 100644
--- a/proto/v1/v1/access_grant_service.proto
+++ b/proto/v1/v1/access_grant_service.proto
@@ -166,13 +166,22 @@ message ListAccessGrantsRequest {
string page_token = 3;
// Filter expression using AIP-160 syntax.
- // Supported fields: name, creator, status, issue, expire_time, create_time
+ // Supported fields:
+ // - name: the fullname in "projects/{project}/accessGrants/{access_grant}" format, support "==" operator.
+ // - creator: the creator name in "users/{email}" format, support "==" operator.
+ // - status: the access status, support "==" and "in" operator.
+ // - issue: the access issue fullname, support "==" operator.
+ // - expire_time: the access expire time in "2006-01-02T15:04:05Z07:00" format, support ">=", ">", "<=" and "<" operator.
+ // - create_time: the access creation time in "2006-01-02T15:04:05Z07:00" format, support ">=", ">", "<=" and "<" operator.
+ // - query: the access query, support "==" and ".contains(xx)" operator
+ //
// Examples:
- // - 'creator = "users/[email protected]"'
- // - 'status = "ACTIVE"'
- // - 'creator = "users/[email protected]" AND status = "ACTIVE"'
- // - 'issue = "projects/x/issues/123"'
- // - 'status = "ACTIVE" AND expire_time > "2024-02-01T00:00:00Z"'
+ // - creator == "users/[email protected]"
+ // - status == "ACTIVE"
+ // - status in ["ACTIVE", "PENDING"]
+ // - creator == "users/[email protected]" && status == "ACTIVE"
+ // - issue == "projects/x/issues/123"
+ // - status == "ACTIVE" && expire_time > "2024-02-01T00:00:00Z"
string filter = 4;
}