Validate cloud postgres list --filter keys and values - #626
Open
sdairs wants to merge 1 commit into
Open
Conversation
sdairs
force-pushed
the
fix/603-postgres-filter-validation
branch
from
August 28, 2026 14:46
1825be7 to
c99ecc8
Compare
sdairs
force-pushed
the
fix/603-postgres-filter-validation
branch
from
August 28, 2026 19:42
c99ecc8 to
30c98b8
Compare
sdairs
force-pushed
the
fix/603-postgres-filter-validation
branch
from
September 1, 2026 15:05
30c98b8 to
cf970f3
Compare
`cloud postgres list --filter` fell through a catch-all `_ => true`, so any
key outside {state, region, name, provider} — including `isPrimary`, which is
shown as the `Primary` column — silently returned the whole unfiltered list
with exit 0. An empty value and a filter with no `=` were ignored the same way,
and the `state`/`provider` predicates compared `format!("{:?}", ..)` Debug
forms against the wire value, so an `Unknown(..)` state matched nothing.
`--filter` now parses at clap time into a closed `PostgresListFilter` enum via
a `value_parser`, so an unknown key, a missing `=`, an empty value or a
non-boolean `isPrimary` is a usage error (exit 2) that lists the valid keys and
issues no API request. `isPrimary` joins the supported keys, `state` and
`provider` compare against the serde wire value (`Display`), and an absent
response field still matches no filter value.
`cloud service list --filter` is unaffected: it forwards server-side
resource-tag filters (`tag:env=production`) to the API as query parameters and
shares none of this code.
Tests: clap parse coverage for the accepted forms and each rejection (asserting
ErrorKind::ValueValidation and exit code 2), inline `apply_filter` tests for
wire-value comparison, absent fields and multi-filter conjunction, and wiremock
subprocess tests that pin exit 2 with no API call for invalid filters and the
client-side filtering results for valid ones.
Fixes #603
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
sdairs
force-pushed
the
fix/603-postgres-filter-validation
branch
from
September 1, 2026 20:36
cf970f3 to
388200a
Compare
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.
Fixes #603.
Stacked PR: base is
feat/615-postgres-delete-force, notmain.What was broken
cloud postgres list --filtermatched keys with a catch-all_ => true, so any key outside{state, region, name, provider}— includingisPrimary, which the listing shows as thePrimarycolumn — silently returned the whole unfiltered list with exit 0. A filter with an empty value (state=) or no=at all was ignored the same way. Thestateandproviderpredicates also comparedformat!("{:?}", ..)Debug forms against the wire value, so anUnknown(..)state could never match.What changed
--filteris parsed at clap time by avalue_parserinto a closedPostgresListFilterenum. An unknown key, a missing=, an empty/whitespace-only value, or a non-booleanisPrimaryis now a usage error (exit 2) whose message lists the valid keys — and no API request is issued.isPrimaryis a supported key (true/false, plus theyes/nothePrimarycolumn renders).stateandproviderare compared against the serde wire value viaDisplay, case-insensitively, so multi-word states andUnknown(..)values match correctly.region/namematch exactly; keys themselves are case-insensitive.cloud service list --filteris not affected: it forwards server-side resource-tag filters (tag:env=production) to the API as query parameters and shares none of this code, so client-side key validation there would wrongly reject valid server-side syntax.Tests
yes/no), and one test per rejection assertingErrorKind::ValueValidationandexit_code() == 2.apply_filtertests: wire-value comparison forstate/provider(includingRestoring_backupandUnknown(..)), absent fields matching nothing, multi-filter conjunction, and the empty-filter passthrough.tests/cli_request_shape_test.rs: subprocess + wiremock tests pinning exit 2 with anexpect(0)mock for invalid filters (no API call, no stdout), and the client-side filtering results forisPrimary,state=restoring_backup,regionand a non-matchingname.Verified with
cargo fmt --all,cargo clippy --workspace --all-targets -- -D warnings, andcargo test -p clickhousectl(all green). Theclickhouse-cloud-apicrate is untouched.🤖 Generated with Claude Code