Repository navigation
feat(accounts): find accounts by upstream API key from the account search - #239
Merged
Merged
Conversation
…arch The account page's search box now also finds the accounts that use a given upstream API key: the whole key, exact, compared with credentials.api_key only, combined with the active folder and filters like the name search. The key itself is not sent. The page hashes the trimmed search text and first asks whether any account has that key, with the digest term "sha256:<hex>" as the search value of a one-row list request. If one does, every request of the page (list, auto-refresh, facets, upstream billing rates, export, select-all, bulk-by-filter) carries the digest term instead of the text. Otherwise the text is sent as before and matches names only. Backend: service.AccountSearchPredicate is the one search condition of both account query builders. A digest term matches accounts whose api_key is a JSON string that, trimmed of space, tab, CR and LF, hashes to it; any other value is the name search it was. Frontend: the text is resolved before the first load, a lookup in flight is joined rather than restarted, a failed lookup puts the search box back to the applied search instead of sending the text, and a name search is looked up again on manual refresh and after the page adds or changes accounts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The account page could only search by account name. To find which accounts use a given upstream API key (duplicates, a key reported as leaked or exhausted, a key about to be added) the owner had to open accounts one by one, and the key is not shown in the list.
Change
What the admin sees. The existing search box also finds accounts by upstream API key; the placeholder reads "搜索名称或 API Key" / "Search name or API key". Nothing else is added to the page.
credentials.api_keyonly. That one field holds the upstream key of every API-key style account on every platform.The key is not sent. The page hashes the trimmed search text (SHA-256, WebCrypto) and first asks whether any account has that key, using the digest term
sha256:<64 hex>as thesearchvalue of a one-row list request.crypto.subtle(plain HTTP) the page keeps the name-only search.Backend.
service.AccountSearchPredicateis now the one search condition of both account query builders (accountListFilteredQuery,accountConsoleQuery), so list, facets, export and bulk-by-filter agree.api_keyis a JSON string that, trimmed of space, tab, CR and LF, hashes to it. It never matches names.Frontend state.
Verification
go build ./...,go vet -tags=integration ./internal/repository/, and the predicate unit test, which asserts the generated PostgreSQL and its bound argument for a digest term and that nine near-miss inputs stay name searches.vue-tsc --noEmit, eslint on the touched files, and the nineAccountsView.*.spec.tsfiles plus the util spec (81 tests, run twice). The new cases record the search value of each list request and cover: name text, key text, restored text, failed lookup, re-lookup after create and after import, and a filter change during a refresh's lookup.Not run locally: the two integration cases (
TestListWithFilters_SearchByAPIKeyDigest,TestAccountTaxonomyConsoleSearchByAPIKeyDigestIntegration) need Docker, so the new SQL meets a real PostgreSQL for the first time in this PR's CI. No full suites, no real model calls.🤖 Generated with Claude Code