Skip to content

refactor(cmd): shared OpenFromEnv DB bootstrap; fix rekey runbook path - #1063

Merged
cristim merged 3 commits into
feat/multicloud-web-frontendfrom
refactor/cmd-db-bootstrap
Jun 7, 2026
Merged

cristim merged 3 commits into
feat/multicloud-web-frontendfrom
refactor/cmd-db-bootstrap

Conversation

@cristim

@cristim cristim commented Jun 7, 2026

Copy link
Copy Markdown
Member

Summary

Closes #1050 (findings 04-L1, 04-L3, 04-D2)

Three cmd/ entrypoints each hand-rolled the same DB bootstrap pattern:
load config, optionally build a secrets.Resolver, call NewConnection,
defer-close the resolver. This replicated both the code and an implicit
contract (resolver safe to close after NewConnection returns because password
resolution is synchronous).

Additionally cmd/rekey/main.go had two inconsistent runbook references:
the package doc pointed at cmd/rekey/README.md (which exists) while the
fatal error message pointed at docs/runbooks/rekey-from-zero-key.md
(which does not exist), sending operators to a dead link during incidents.

Changes

  • internal/database/open_from_env.go: new database.OpenFromEnv(ctx) helper
    that owns the resolver lifecycle once and is the canonical bootstrap for
    cmd entrypoints that only need a DB connection.
  • cmd/cleanup-lambda/main.go: remove initDB helper; call database.OpenFromEnv.
  • cmd/lambda/clear-rate-limit/main.go: remove inline bootstrap block; call
    database.OpenFromEnv.
  • cmd/rekey/main.go: fix fatal message runbook path from
    docs/runbooks/rekey-from-zero-key.md to cmd/rekey/README.md.

Note: cmd/rekey intentionally keeps its own resolver wiring because it needs
the resolver before opening the DB (to call credentials.LoadKey). The new
helper is documented to cover only the simpler single-purpose case.

Verification

  • go build ./... -- success
  • go vet ./internal/database/... ./cmd/cleanup-lambda/... ./cmd/lambda/... ./cmd/rekey/... -- no issues
  • go test ./internal/database/... ./cmd/rekey/... -timeout 90s -- 176 passed
  • New unit tests cover OpenFromEnv error paths (missing config, unreachable DB); live DB connection path is covered by existing integration tests in CI
  • Runbook file cmd/rekey/README.md confirmed present in the repo

cristim added 3 commits June 7, 2026 04:14
Extract database.OpenFromEnv(ctx) to centralize the three-step
resolver+DB bootstrap pattern replicated across cmd/cleanup-lambda,
cmd/lambda/clear-rate-limit, and cmd/rekey.

The helper loads DB config from env, conditionally builds a
secrets.Resolver when DB_PASSWORD_SECRET is set, and closes it after
NewConnection returns (NewConnection resolves the password
synchronously so the resolver is not needed post-connect).

Callers that need the resolver for other purposes (e.g. cmd/rekey
calls credentials.LoadKey before opening DB) wire the resolver
themselves and call NewConnection directly.

Refs #1050 (04-L1, 04-D2)
…ate-limit

Replace the hand-rolled initDB helper in cmd/cleanup-lambda and the
inline bootstrap block in cmd/lambda/clear-rate-limit with the new
database.OpenFromEnv helper, removing ~47 lines of duplicated
resolver-lifecycle logic.

Refs #1050 (04-L1, 04-D2)
The fatal "refusing to run" message pointed at
docs/runbooks/rekey-from-zero-key.md (which does not exist); the
package doc correctly points at cmd/rekey/README.md (which does).
Update the fatal message to match so operators in an incident reach
a live runbook.

Closes #1050 (04-L3)
@cristim cristim added triaged Item has been triaged priority/p3 Polish / idea / may never ship severity/low Minor harm urgency/this-quarter Within the quarter impact/internal Team-internal only effort/s Hours type/chore Maintenance / non-user-visible labels Jun 7, 2026
@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@cristim, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 14 minutes and 12 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 80166b63-4641-480e-8bf0-9d648f205a92

📥 Commits

Reviewing files that changed from the base of the PR and between cbdc4be and 4a571c4.

📒 Files selected for processing (5)
  • cmd/cleanup-lambda/main.go
  • cmd/lambda/clear-rate-limit/main.go
  • cmd/rekey/main.go
  • internal/database/open_from_env.go
  • internal/database/open_from_env_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/cmd-db-bootstrap

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

@cristim

cristim commented Jun 7, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim

cristim commented Jun 7, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai help

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

CodeRabbit commands

These commands are invoked using PR/Issue comments.

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai rate limit to show your current review rate limit status.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai evaluate custom pre-merge check --instructions <custom-checks-instructions> --name <custom-checks-title> [--mode <error|warning>] to validate the custom pre-merge checks instructions. Defaults to error when --mode is omitted.
  • @coderabbitai ignore pre-merge checks to override pre-merge checks and get an approval on PR.
  • @coderabbitai run pre-merge checks to run pre-merge checks on the pull request.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai emit path instructions to emit generated path-specific review instructions for this repository.
  • @coderabbitai resolve merge conflict to automatically resolve merge conflicts.
  • @coderabbitai autofix to automatically fix issues identified in unresolved review comments.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai generate configuration to create a PR that adds the current resolved configuration as .coderabbit.yaml (or show it if already present).
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit configuration file (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, support, documentation and community

  • Visit our status page to check the current availability of CodeRabbit.
  • Create a ticket on our support page for assistance with any issues or questions.
  • Visit our documentation site for detailed information on how to use CodeRabbit.
  • Join our Discord community to connect with other users and get help from the community.
  • Follow us on X/Twitter for updates and announcements.

@cristim
cristim merged commit 5ba8448 into feat/multicloud-web-frontend Jun 7, 2026
4 checks passed
@cristim
cristim deleted the refactor/cmd-db-bootstrap branch July 27, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/s Hours impact/internal Team-internal only priority/p3 Polish / idea / may never ship severity/low Minor harm triaged Item has been triaged type/chore Maintenance / non-user-visible urgency/this-quarter Within the quarter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant