Repository navigation
refactor(cmd): shared OpenFromEnv DB bootstrap; fix rekey runbook path - #1063
Conversation
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)
|
Warning Review limit reached
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai help |
ChatThere are 3 ways to chat with CodeRabbit:
CodeRabbit commands
Other keywords and placeholders
CodeRabbit configuration file (
|
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, callNewConnection,defer-close the resolver. This replicated both the code and an implicit
contract (resolver safe to close after
NewConnectionreturns because passwordresolution is synchronous).
Additionally
cmd/rekey/main.gohad two inconsistent runbook references:the package doc pointed at
cmd/rekey/README.md(which exists) while thefatal 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: newdatabase.OpenFromEnv(ctx)helperthat owns the resolver lifecycle once and is the canonical bootstrap for
cmd entrypoints that only need a DB connection.
cmd/cleanup-lambda/main.go: removeinitDBhelper; calldatabase.OpenFromEnv.cmd/lambda/clear-rate-limit/main.go: remove inline bootstrap block; calldatabase.OpenFromEnv.cmd/rekey/main.go: fix fatal message runbook path fromdocs/runbooks/rekey-from-zero-key.mdtocmd/rekey/README.md.Note:
cmd/rekeyintentionally keeps its own resolver wiring because it needsthe resolver before opening the DB (to call
credentials.LoadKey). The newhelper is documented to cover only the simpler single-purpose case.
Verification
go build ./...-- successgo vet ./internal/database/... ./cmd/cleanup-lambda/... ./cmd/lambda/... ./cmd/rekey/...-- no issuesgo test ./internal/database/... ./cmd/rekey/... -timeout 90s-- 176 passedOpenFromEnverror paths (missing config, unreachable DB); live DB connection path is covered by existing integration tests in CIcmd/rekey/README.mdconfirmed present in the repo