feat: add static api key middleware for dev stats (CM-1055)#3933
Conversation
|
|
189109c to
f7b8cc5
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a new “DevStats” public API surface by adding a static API key authentication middleware and mounting a new /v1/dev-stats router with a placeholder endpoint.
Changes:
- Added
devStats.apiKeyconfiguration wiring viaCROWD_DEV_STATS_API_KEY. - Implemented
staticApiKeyMiddlewareand mounted the DevStats router at/v1/dev-stats. - Added a placeholder
POST /v1/dev-stats/affiliationsendpoint for initial connectivity testing.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| backend/src/conf/index.ts | Exposes DEV_STATS_CONFIG from node-config. |
| backend/src/conf/configTypes.ts | Adds DevStatsConfiguration type. |
| backend/src/api/public/v1/dev-stats/index.ts | Introduces DevStats router with a placeholder POST /affiliations. |
| backend/src/api/public/middlewares/staticApiKeyMiddleware.ts | Adds static API key auth middleware and sets req.actor. |
| backend/src/api/public/index.ts | Mounts DevStats router behind the static API key middleware. |
| backend/config/default.json | Adds devStats config block. |
| backend/config/custom-environment-variables.json | Maps devStats.apiKey to CROWD_DEV_STATS_API_KEY. |
| backend/.env.dist.local | Adds local env template entry for CROWD_DEV_STATS_API_KEY. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
9797104 to
e5cc1dd
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
3b2fbea to
80f6b61
Compare

Summary
Sets up the foundation for the DevStats public API:
CROWD_DEV_STATS_API_KEYstatic API key authentication middleware/v1/dev-statswith a temporary placeholder endpoint for testingTest plan
POST /api/v1/dev-stats/affiliationswithout a key → 401Note
Medium Risk
Introduces a new API-key authentication path for public endpoints and a new
apiKeysdatabase table; mistakes in auth/header handling or scope assignment could unintentionally grant/deny access.Overview
Adds a new public
/v1/dev-statsAPI surface protected by astaticApiKeyMiddleware(Bearer token → SHA-256 hash lookup), separate from the existing Auth0-protected/v1routes.Introduces a minimal
dev-statsrouter with rate limiting and a placeholderPOST /affiliationsendpoint gated by the newREAD_AFFILIATIONSscope.Adds persistence for API keys via a new
apiKeystable and data-access helpers (findApiKeyByHash,touchApiKeyLastUsed), and exports the new DAL module.Written by Cursor Bugbot for commit 80f6b61. This will update automatically on new commits. Configure here.