feat: add GET /email-template endpoint keyed on API key#175
feat: add GET /email-template endpoint keyed on API key#175dobby-coder[bot] wants to merge 1 commit into
Conversation
Add an endpoint that returns the email template pg-pkg has linked to the caller's API key (issue #54, requirement 10 of postguard#81). The key is validated through the existing `ApiKey` request guard, so the same `Authorization: Bearer PG-…` flow the upload endpoints use applies here. - Extend the pg-pkg `/v2/api-key/validate` response and `ApiKey` guard to carry an optional `email_template`. - `GET /email-template` returns 200 + template for a valid key, 401 for a missing/invalid key, 404 when the key is valid but has no template, and 503 when pg-pkg is unreachable during validation. - Branch mapping extracted into a pure `resolve_email_template` helper for unit testing; full route also covered end-to-end through the real guard against a mock pg-pkg. - Document the endpoint and a bearer security scheme in api-description.yaml. Closes #54 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
🔍 Rules Dobby 2 — consolidated review (per-rule compliance check + Review Dobby 2 findings)
Posted as COMMENT because GitHub blocks a self-authored bot from
APPROVE/REQUEST_CHANGES. Treat this as a sign-off, gated on the documented maintainer contract call below — not as withholding.
Code is clean and ready on its own merits. CI is green — cargo fmt --check, clippy --all-targets -D warnings, and cargo test --all-targets all pass (127 tests, 8 new). The new email_template route is registered in build_rocket, both new Error variants (Unauthorized, NotFound) are handled in the Responder, and the endpoint correctly rejects with 401 rather than degrading to the default tier like the upload flow. Tests cover the pure resolve_email_template helper and the full route end-to-end through the real ApiKey guard against a mock pg-pkg — both the authorized path and the missing/invalid-key paths. PR title is conventional; no duplicate PRs.
On the one carried finding (cross-repo contract): the endpoint depends on an email_template field from pg-pkg's /v2/api-key/validate. I verified this against the live state: encryption4all/postguard#86 is open with no PR, and its issue body lists deliverables but does not yet pin down the JSON field name. So against real pg-pkg today the endpoint returns 404 for every valid key, and email_template is an unverified guess at #86's eventual schema. This is already correctly handled in the PR: the "Note for review (kept as draft)" section documents the dependency, the field is read with #[serde(default)] so it degrades gracefully, and the PR is deliberately held as draft pending a maintainer call on the contract. That is the right disposition — it's a coordination decision, not a code defect, and nothing the bot can resolve until #86 ships.
No changes requested from the bot side. When encryption4all/postguard#86 lands, confirm the field name matches email_template before flipping this to ready.
Parent: encryption4all/postguard#81. Closes #54.
What
Adds
GET /email-template, which returns the email template pg-pkg has linked to the caller's API key. The key is validated through the existingApiKeyrequest guard (the sameAuthorization: Bearer PG-…flow the upload endpoints use), so no new auth path is introduced.Implements requirement 10 of encryption4all/postguard#81 (Cryptify: email template retrieval endpoint). Sibling work on the PKG side is encryption4all/postguard#86.
Behaviour
200+{ tenant_id, email_template }401404503How
/v2/api-key/validateresponse and theApiKeyguard now carry an optionalemail_template, populated when the key validates.resolve_email_templatehelper so every outcome is unit-testable without HTTP./v2/api-key/validateround-trip).api-description.yamldocuments the route and aapiKeyBearersecurity scheme.Tests
cargo fmt --all -- --check,cargo clippy --all-targets -- -D warnings, andcargo test --all-targetsall pass locally (127 tests, 8 new):Note for review (kept as draft)
This assumes pg-pkg's
/v2/api-key/validatewill return the linked template in anemail_templatefield. That field is part of the parallel PKG work (postguard#86) and is read with#[serde(default)], so this stays backward-compatible until the PKG side ships. Flagging the contract for a maintainer call before marking ready.Closes #54