Skip to content

feat(policy): Add sort support listregisteredresources api#3312

Merged
dsm20 merged 7 commits intomainfrom
add-sort-support-listregisteredresources-api
Apr 20, 2026
Merged

feat(policy): Add sort support listregisteredresources api#3312
dsm20 merged 7 commits intomainfrom
add-sort-support-listregisteredresources-api

Conversation

@dsm20
Copy link
Copy Markdown
Contributor

@dsm20 dsm20 commented Apr 16, 2026

Proposed Changes

Resolves DSPX-2691

Changes

Protoservice/policy/registeredresources/registered_resources.proto

  • SortRegisteredResourcesType enum (UNSPECIFIED, NAME, CREATED_AT, UPDATED_AT)
  • RegisteredResourcesSort message (field + direction)
  • repeated RegisteredResourcesSort sort = 11 on ListRegisteredResourcesRequest with max_items = 1 constraint
  • Regenerated protos and docs

SQLservice/policy/db/queries/registered_resources.sql

  • CASE WHEN sort blocks in listRegisteredResources query for 3 fields (6 blocks total)
  • Fallback r.created_at DESC

Goservice/policy/db/utils.go + service/policy/db/registered_resources.go

  • GetRegisteredResourcesSortParams(): maps enum to SQL-compatible field/direction strings
  • ListRegisteredResources handler wired to call mapper and pass params to sqlc query
  • No new constants needed — sortFieldName, sortFieldCreatedAt, sortFieldUpdatedAt already exist

Tests

  • 11 unit tests for the enum mapper helper (nil, empty, unspecified, each field + direction, unspecified direction default)
  • 7 integration tests (name ASC/DESC, created_at ASC/DESC, updated_at ASC/DESC, unspecified fallback) using createSortTestRegisteredResources and createNamedSortTestRegisteredResources suite helpers
  • Protovalidate sort constraint test (TestListRegisteredResourcesRequest_Sort)

Notes

Checklist

  • I have added or updated unit tests
  • I have added or updated integration tests (if appropriate)
  • I have added or updated documentation

Testing Instructions

Summary by CodeRabbit

Release Notes

  • New Features

    • Added sorting functionality to registered resources lists. Sort by name, creation date, or update date in ascending or descending order. Defaults to creation date (descending) when not specified.
  • Documentation

    • Updated API documentation with new sorting options and default ordering behavior.
  • Tests

    • Added integration and unit tests covering all sorting configurations.

dsm20 added 7 commits April 16, 2026 00:09
and proto validation
tests max items constraint against no sort, one item sort, and 2 item sort
order by -> case when for sorting fields + sqlc regen
maps enum to SQL field, as well as the cases for empty or nill sorts.
sort unspecified falls back to default as per usual
nill sort, empty slice, nill element, unspecified, then every field
combination asc/desc
go query function gets sortField and sortDirection, which are returned
by GetRegisteredResourcesSortParams (the helper)
includes funcs for all ASC/DESC tests, default fallback, with 2 helpers
for creating name and time based tests respectively + a deletion func
for deferred cleanup during tests
@dsm20 dsm20 requested review from a team as code owners April 16, 2026 15:49
@dsm20 dsm20 marked this pull request as draft April 16, 2026 15:49
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

📝 Walkthrough

Walkthrough

This PR adds sorting functionality to the ListRegisteredResources API by introducing sort-related proto message and enum types, updating SQL queries with dynamic ORDER BY logic based on sort parameters, wiring sort parameters through the database layer, and adding comprehensive tests and documentation.

Changes

Cohort / File(s) Summary
Proto Definitions
service/policy/registeredresources/registered_resources.proto, service/policy/registeredresources/registered_resources_test.go
Added SortRegisteredResourcesType enum and RegisteredResourcesSort message; extended ListRegisteredResourcesRequest with optional sort field (max 1 item); added proto validation tests for sort constraints.
Database Query Layer
service/policy/db/queries/registered_resources.sql, service/policy/db/registered_resources.sql.go
Updated listRegisteredResources query to use dynamic CASE-based ORDER BY logic parameterized by sort_field and sort_direction, with fallback to created_at DESC; regenerated param struct with new SortField and SortDirection fields.
Database Utilities
service/policy/db/utils.go, service/policy/db/utils_test.go
Added GetRegisteredResourcesSortParams helper to convert sort messages into SQL-compatible field/direction strings; included comprehensive unit tests covering nil/empty/unspecified cases and valid field mappings.
Service Implementation
service/policy/db/registered_resources.go
Wired GetRegisteredResourcesSortParams to extract sort parameters from request and pass them to the query layer.
API Documentation
docs/grpc/index.html, docs/openapi/policy/registeredresources/registered_resources.openapi.yaml, docs/openapi/policy/kasregistry/key_access_server_registry.openapi.yaml, docs/openapi/policy/obligations/obligations.openapi.yaml
Added new sort-related schemas and updated request definitions in OpenAPI specs; added SortDirection description clarifying default ordering semantics across list APIs; extended HTML documentation table of contents.
Integration Tests
service/integration/registered_resources_test.go
Added test suite covering ListRegisteredResources sorting by name/created_at/updated_at in both directions, with helper methods for creating deterministic test resources; included test for unspecified sort field fallback behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • c-r33d
  • alkalescent

Poem

🐰 A sorted hop, a careful bound,
Fields aligned, direction found,
By name and time, ascending, too,
Default descending when sort's not due,
The query hops with CASE so bright! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(policy): Add sort support listregisteredresources api' directly describes the main change—adding sort support to the ListRegisteredResources API—and aligns with the PR's core objective.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-sort-support-listregisteredresources-api

Warning

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added comp:db DB component comp:policy Policy Configuration ( attributes, subject mappings, resource mappings, kas registry) docs Documentation size/m labels Apr 16, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the ListRegisteredResources API by introducing robust sorting capabilities. Users can now specify sorting preferences for registered resources based on their name, creation timestamp, or last update timestamp, in both ascending and descending orders. This change improves the flexibility and usability of data retrieval, aligning with similar sorting features implemented in other list APIs.

Highlights

  • API Enhancement: Added strongly-typed sort support to the ListRegisteredResources RPC, allowing sorting by name, created_at, and updated_at with ASC/DESC directions.
  • Schema Definition: Introduced SortRegisteredResourcesType enum and RegisteredResourcesSort message in the protobuf definition for RegisteredResources.
  • Database Integration: Modified the SQL query for listRegisteredResources to dynamically apply sorting based on input parameters, including a backward-compatible fallback to created_at DESC.
  • Go Logic: Implemented GetRegisteredResourcesSortParams to map protobuf sort enums to SQL field/direction strings and integrated it into the ListRegisteredResources handler.
  • Comprehensive Testing: Added extensive unit tests for the sort parameter mapping utility and integration tests covering various sorting scenarios, including default fallback and max_items constraint validation.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Ignored Files
  • Ignored by pattern: docs/openapi/**/* (3)
    • docs/openapi/policy/kasregistry/key_access_server_registry.openapi.yaml
    • docs/openapi/policy/obligations/obligations.openapi.yaml
    • docs/openapi/policy/registeredresources/registered_resources.openapi.yaml
  • Ignored by pattern: protocol/**/* (1)
    • protocol/go/policy/registeredresources/registered_resources.pb.go
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.


A list of things, a growing stream, To sort them right, a coding dream. By name or date, ascending, down, Order found, throughout the town.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Copy Markdown
Contributor

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 173.684468ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 86.085107ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 422.497778ms
Throughput 236.69 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 42.365609878s
Average Latency 421.833216ms
Throughput 118.02 requests/second

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces sorting capabilities to the ListRegisteredResources API, allowing results to be ordered by name, creation time, or update time in both ascending and descending directions. The changes include updates to the protobuf definitions, database queries using dynamic CASE statements, and utility functions for parameter mapping, along with new integration and unit tests. Feedback suggests evaluating the performance impact of the dynamic sorting implementation on large datasets and improving the robustness of enum mapping by handling unexpected values more explicitly.

Comment thread service/policy/db/queries/registered_resources.sql
Comment thread service/policy/db/utils.go
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Govulncheck found vulnerabilities ⚠️

The following modules have known vulnerabilities:

  • examples
  • sdk
  • service
  • lib/fixtures
  • tests-bdd

See the workflow run for details.

@dsm20 dsm20 marked this pull request as ready for review April 16, 2026 16:16
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/openapi/policy/kasregistry/key_access_server_registry.openapi.yaml`:
- Around line 583-589: The shared enum policy.SortDirection currently contains
endpoint-specific semantics about UNSPECIFIED handling; remove the
endpoint-level behavior text (the notes about UNSPECIFIED being treated as ASC
or defaulting to endpoint request message ordering) from the
policy.SortDirection description and leave it as a neutral enum description
(e.g., "Sorting direction shared across list APIs."). Then, for each concrete
List*Request.sort field (where SORT_DIRECTION_UNSPECIFIED is relevant), add the
appropriate endpoint-specific note about fallback/default ordering and how
SORT_DIRECTION_UNSPECIFIED is interpreted for that request. Ensure references to
the enum value (SORT_DIRECTION_UNSPECIFIED / policy.SortDirection) remain but do
not assert global behavior in the enum schema.

In `@docs/openapi/policy/obligations/obligations.openapi.yaml`:
- Around line 554-560: Remove the endpoint-specific behavior text ("When a sort
field is provided, UNSPECIFIED is treated as ASC" and the request-level fallback
sentence) from the central enum schema policy.SortDirection in
obligations.openapi.yaml; this enum should be neutral and only describe the enum
values. Instead, move/restore any notes about UNSPECIFIED-to-ASC behavior and
default/fallback ordering into the specific List*Request.sort field
documentation for each endpoint that actually implements that semantics (e.g.,
the various ListPoliciesRequest.sort or ListObligationsRequest.sort fields),
ensuring each request's docs explain its default ordering and how UNSPECIFIED is
treated.

In `@docs/openapi/policy/registeredresources/registered_resources.openapi.yaml`:
- Around line 442-455: The shared enum policy.SortDirection currently documents
endpoint-specific behavior ("When a sort field is provided, UNSPECIFIED is
treated as ASC"); remove that clause from the policy.SortDirection description
and keep only generic docs for the enum values, then add the specific
interpretation note to each request's per-endpoint sort field (e.g.,
ListRegisteredResourcesRequest.sort) where the behavior applies; update the
description text for ListRegisteredResourcesRequest.sort to state how
SORT_DIRECTION_UNSPECIFIED is treated for that particular endpoint and ensure no
other endpoint-level semantics remain in the central policy.SortDirection
schema.

In `@service/policy/db/queries/registered_resources.sql`:
- Around line 132-139: The ORDER BY using CASE on `@sort_field/`@sort_direction is
unstable when multiple rows share the same sort key and created_at, causing
pagination duplicates/skips; to fix, append a deterministic tie-breaker such as
r.id ASC to the end of the ORDER BY (after the existing r.created_at DESC) so
queries like the one using r.name/r.created_at/r.updated_at with CASE clauses
always have a unique final sort column; update the ORDER BY clause that
references `@sort_field`, `@sort_direction` and r.created_at to include r.id ASC as
the last ordering term.

In `@service/policy/registeredresources/registered_resources.proto`:
- Around line 122-125: Document that when RegisteredResourcesSort.direction =
SORT_DIRECTION_UNSPECIFIED it should be treated as ASC for this request; update
the comment for the request's sort field (or the
RegisteredResourcesSort.direction field) in registered_resources.proto to
explicitly state the UNSPECIFIED->ASC fallback so the endpoint remains
self-describing (reference symbols: RegisteredResourcesSort,
RegisteredResourcesSort.direction, SORT_DIRECTION_UNSPECIFIED, repeated
RegisteredResourcesSort sort = 11).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5aa9ebb8-be69-47f9-a4ed-2ec80c616090

📥 Commits

Reviewing files that changed from the base of the PR and between 9221cac and 9bee5b1.

⛔ Files ignored due to path filters (1)
  • protocol/go/policy/registeredresources/registered_resources.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (12)
  • docs/grpc/index.html
  • docs/openapi/policy/kasregistry/key_access_server_registry.openapi.yaml
  • docs/openapi/policy/obligations/obligations.openapi.yaml
  • docs/openapi/policy/registeredresources/registered_resources.openapi.yaml
  • service/integration/registered_resources_test.go
  • service/policy/db/queries/registered_resources.sql
  • service/policy/db/registered_resources.go
  • service/policy/db/registered_resources.sql.go
  • service/policy/db/utils.go
  • service/policy/db/utils_test.go
  • service/policy/registeredresources/registered_resources.proto
  • service/policy/registeredresources/registered_resources_test.go

Comment thread docs/openapi/policy/obligations/obligations.openapi.yaml
Comment thread service/policy/db/queries/registered_resources.sql
Comment thread service/policy/registeredresources/registered_resources.proto
Comment thread service/policy/db/queries/registered_resources.sql
@dsm20 dsm20 added this pull request to the merge queue Apr 20, 2026
Merged via the queue into main with commit 91a3ff3 Apr 20, 2026
42 checks passed
@dsm20 dsm20 deleted the add-sort-support-listregisteredresources-api branch April 20, 2026 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:db DB component comp:policy Policy Configuration ( attributes, subject mappings, resource mappings, kas registry) docs Documentation size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants