Skip to content

Delete auto-provisioned query keys with services - #370

Open
sdairs wants to merge 4 commits into
issue-334-cloud-error-renderingfrom
issue-332-delete-query-key
Open

Delete auto-provisioned query keys with services#370
sdairs wants to merge 4 commits into
issue-334-cloud-error-renderingfrom
issue-332-delete-query-key

Conversation

@sdairs

@sdairs sdairs commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Closes #332

Summary

  • Persist the management API key UUID alongside per-service Query API credentials.
  • Delete only that exact stored key before deleting the service, with idempotent 404 handling and retry-safe cleanup failures.
  • Keep legacy credential records readable and avoid unsafe name-based key deletion.

Tests

  • cargo fmt --all --check
  • cargo test -p clickhousectl -p clickhouse-cloud-api
  • cargo clippy -p clickhousectl -p clickhouse-cloud-api --all-targets -- -D warnings

@sdairs
sdairs requested review from iskakaushik and rndD as code owners August 5, 2026 13:14
@sdairs
sdairs temporarily deployed to cloud-integration August 5, 2026 13:14 — with GitHub Actions Inactive
@sdairs sdairs changed the title Delete auto-provisioned query keys with services (#332) Delete auto-provisioned query keys with services Aug 5, 2026
Comment thread crates/clickhousectl/src/cloud/commands.rs
Comment thread crates/clickhousectl/src/cloud/commands.rs
Comment thread crates/clickhousectl/src/cloud/commands.rs Outdated
@sdairs
sdairs force-pushed the issue-332-delete-query-key branch from 168ad26 to 72ebbc5 Compare August 5, 2026 13:42
@sdairs
sdairs had a problem deploying to cloud-integration August 5, 2026 13:42 — with GitHub Actions Failure
Comment thread crates/clickhousectl/src/cloud/client.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves clickhousectl cloud service delete by ensuring auto-provisioned per-service Query API keys are cleaned up in ClickHouse Cloud (when the exact management key UUID is known), preventing orphaned keys while keeping legacy credential records usable.

Changes:

  • Persist the management API key UUID (api_key_id) alongside per-service Query API credentials in .clickhouse/credentials.json.
  • On cloud service delete, delete the stored Query API key (by exact UUID, with 404 treated as idempotent) before deleting the service, and keep cleanup retry-safe on failure.
  • Add request-shape coverage to verify delete ordering and idempotent behavior; update README documentation accordingly.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
README.md Documents that per-service query credentials now include the management API key ID, and explains safe cleanup behavior during service deletion.
crates/clickhousectl/tests/cli_request_shape_test.rs Adds wiremock-based tests asserting key deletion happens before service deletion and that 404s are handled idempotently.
crates/clickhousectl/src/cloud/service_query.rs Stores the management API key UUID into the persisted ServiceQueryKey record when auto-provisioning query access.
crates/clickhousectl/src/cloud/credentials.rs Extends ServiceQueryKey with optional api_key_id while preserving backward-compatible deserialization/serialization.
crates/clickhousectl/src/cloud/commands.rs Implements pre-delete cleanup of the exact stored Query API key and adjusts service delete flow/output for absent resources.
crates/clickhousectl/src/cloud/client.rs Adds *_if_exists wrappers for service/key deletes (and service get) with 404-as-None semantics for idempotency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/clickhousectl/src/cloud/commands.rs Outdated
@sdairs
sdairs had a problem deploying to cloud-integration August 5, 2026 17:49 — with GitHub Actions Failure

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 30a1b77. Configure here.

Comment thread crates/clickhousectl/src/cloud/commands.rs
@sdairs
sdairs had a problem deploying to cloud-integration August 5, 2026 17:59 — with GitHub Actions Failure
Comment thread crates/clickhousectl/src/cloud/commands.rs Outdated
@sdairs
sdairs had a problem deploying to cloud-integration August 5, 2026 18:08 — with GitHub Actions Failure
@sdairs
sdairs force-pushed the issue-332-delete-query-key branch from 402fd51 to 2618e3f Compare August 5, 2026 18:28
@sdairs
sdairs had a problem deploying to cloud-integration August 5, 2026 18:28 — with GitHub Actions Failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

service delete leaves the auto-provisioned query API key orphaned in the org

2 participants