Skip to content

Commit 4807f87

Browse files
fix: include username in api key search query results (#580)
## Summary Fix missing `username` field in API key search response by adding it to the postgres search query. [RHOAIENG-54410](https://redhat.atlassian.net/browse/RHOAIENG-54410) ## Description - The postgres `Search` query was missing `username` in its `SELECT` clause and `rows.Scan` call. - Since the `ApiKey` struct tags `username` with `json:"username,omitempty"`, the field was silently omitted from the JSON response rather than producing an error. ## How it was tested - Built and deployed the patched image (`quay.io/chkulkar/maas-api:test-api-key-username`) to a live cluster. - Verified `POST /v1/api-keys/search` now returns the `username` field for each record. - All existing unit tests pass (`go test ./internal/api_keys/...`). - output: ``` { "object": "list", "data": [ { "id": "21053ea1-bd57-4598-a13c-f6e7a344b343", "name": "validation-key", "description": "Key for validation", "username": "kube:admin", "creationDate": "2026-03-20T22:25:29Z", "expirationDate": "2026-03-20T23:25:29Z", "status": "active", "ephemeral": false }, { "id": "133f1ce9-d3b5-4725-89cb-0abaae5cdb9e", "name": "validation-key", "description": "Key for validation", "username": "kube:admin", "creationDate": "2026-03-20T22:23:52Z", "expirationDate": "2026-03-20T23:23:52Z", "status": "active", "ephemeral": false }, { "id": "da041095-e2cb-4fda-88f4-5a38726c2f20", "name": "validation-key", "description": "Key for validation", "username": "kube:admin", "creationDate": "2026-03-20T22:22:37Z", "expirationDate": "2026-03-20T23:22:37Z", "status": "active", "ephemeral": false } ], "has_more": false } ``` ## Merge criteria: <!--- This PR will be merged by any repository approver when it meets all the points in the checklist --> <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> - [ ] The commits are squashed in a cohesive manner and have meaningful messages. - [ ] Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious). - [ ] The developer has manually tested the changes and verified that the changes work <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed API key search to properly populate and return username information in results. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Chinmay Kulkarni <chkulkar@redhat.com>
1 parent f23b0b9 commit 4807f87

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

maas-api/internal/api_keys/store_postgres.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func (s *PostgresStore) Search(
241241

242242
//nolint:gosec // Dynamic ORDER BY is safe - sort.By/Order validated against allowlist in handler
243243
query := fmt.Sprintf(`
244-
SELECT id, name, description, created_at, expires_at, status, last_used_at, ephemeral
244+
SELECT id, name, description, username, created_at, expires_at, status, last_used_at, ephemeral
245245
FROM api_keys
246246
%s
247247
%s
@@ -267,6 +267,7 @@ func (s *PostgresStore) Search(
267267
&key.ID,
268268
&key.Name,
269269
&description,
270+
&key.Username,
270271
&createdAt,
271272
&expiresAt,
272273
&key.Status,

0 commit comments

Comments
 (0)