-
Notifications
You must be signed in to change notification settings - Fork 731
feat: refactor all apis in new path (CM-1236) #4221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0776c76
feat: refactor all apis in new path
ulemons 03f7b55
feat: add comments
ulemons 714355b
fix: refactor yaml and adds comments
ulemons fd39e04
fix: lint
ulemons 616cb1c
fix: allign specs, add endpoins
ulemons 0a42480
fix: scatter limit
ulemons f85e45b
fix: lint
ulemons File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { Router } from 'express' | ||
|
|
||
| import { createRateLimiter } from '@/api/apiRateLimiter' | ||
| import { safeWrap } from '@/middlewares/errorMiddleware' | ||
|
|
||
| // TODO: restore once scopes are added to Auth0 staging tenant | ||
| // import { requireScopes } from '@/api/public/middlewares/requireScopes' | ||
| // import { SCOPES } from '@/security/scopes' | ||
| import { activityFeedHandler } from '../ossprey/activityFeed' | ||
| import { metricsHandler } from '../ossprey/metrics' | ||
| import { packageListHandler } from '../ossprey/packageList' | ||
| import { packageScatterHandler } from '../ossprey/packageScatter' | ||
| import { batchGetStewardship } from '../packages/batchGetStewardship' | ||
| import { getPackage } from '../packages/getPackage' | ||
| import { getPackageAdvisories } from '../packages/getPackageAdvisories' | ||
| import { getPackageHistory } from '../packages/getPackageHistory' | ||
| import { getPackagesMetrics } from '../packages/getPackagesMetrics' | ||
| import { assignStewardHandler } from '../stewardships/assignSteward' | ||
| import { escalateHandler } from '../stewardships/escalate' | ||
| import { openStewardship } from '../stewardships/openStewardship' | ||
| import { updateStatusHandler } from '../stewardships/updateStatus' | ||
|
|
||
| const rateLimiter = createRateLimiter({ max: 60, windowMs: 60 * 1000 }) | ||
|
|
||
| export function akritesRouter(): Router { | ||
| const router = Router() | ||
|
|
||
| router.get('/metrics', safeWrap(metricsHandler)) | ||
| // /packages/scatter registered before router.use('/packages', ...) so Express evaluates this | ||
| // explicit route first; without this ordering the sub-router would receive the request first | ||
| // and call next() on no match, adding unnecessary overhead. | ||
| router.get('/packages/scatter', rateLimiter, safeWrap(packageScatterHandler)) | ||
| router.get('/packages', rateLimiter, safeWrap(packageListHandler)) | ||
| router.get('/activity', safeWrap(activityFeedHandler)) | ||
|
|
||
| // --- packages --- | ||
| router.post( | ||
| /^\/packages:batch-stewardship\/?$/, | ||
| rateLimiter, | ||
| // TODO: restore once read:packages + read:stewardships are added to Auth0 staging tenant | ||
| // requireScopes([SCOPES.READ_PACKAGES, SCOPES.READ_STEWARDSHIPS], 'any'), | ||
| safeWrap(batchGetStewardship), | ||
| ) | ||
| const packagesSubRouter = Router() | ||
| packagesSubRouter.use(rateLimiter) | ||
| packagesSubRouter.get( | ||
|
ulemons marked this conversation as resolved.
|
||
| '/metrics', | ||
| // TODO: restore once read:packages + read:stewardships are added to Auth0 staging tenant | ||
| // requireScopes([SCOPES.READ_PACKAGES, SCOPES.READ_STEWARDSHIPS], 'any'), | ||
| safeWrap(getPackagesMetrics), | ||
| ) | ||
| packagesSubRouter.get( | ||
| '/detail', | ||
| // TODO: restore once read:packages + read:stewardships are added to Auth0 staging tenant | ||
| // requireScopes([SCOPES.READ_PACKAGES, SCOPES.READ_STEWARDSHIPS], 'any'), | ||
| safeWrap(getPackage), | ||
| ) | ||
| packagesSubRouter.get( | ||
| '/advisories', | ||
| // TODO: restore once read:packages + read:stewardships are added to Auth0 staging tenant | ||
| // requireScopes([SCOPES.READ_PACKAGES, SCOPES.READ_STEWARDSHIPS], 'any'), | ||
| safeWrap(getPackageAdvisories), | ||
| ) | ||
| packagesSubRouter.get( | ||
| '/history', | ||
| // TODO: restore once read:packages + read:stewardships are added to Auth0 staging tenant | ||
| // requireScopes([SCOPES.READ_PACKAGES, SCOPES.READ_STEWARDSHIPS], 'any'), | ||
| safeWrap(getPackageHistory), | ||
| ) | ||
| router.use('/packages', packagesSubRouter) | ||
|
cursor[bot] marked this conversation as resolved.
ulemons marked this conversation as resolved.
|
||
|
|
||
| // --- stewardships --- | ||
| const stewardshipsSubRouter = Router() | ||
| stewardshipsSubRouter.use(rateLimiter) | ||
|
ulemons marked this conversation as resolved.
|
||
| stewardshipsSubRouter.post( | ||
| '/open', | ||
| // TODO: restore once write:stewardships is added to Auth0 staging tenant | ||
| // requireScopes([SCOPES.WRITE_STEWARDSHIPS]), | ||
| safeWrap(openStewardship), | ||
| ) | ||
| stewardshipsSubRouter.post( | ||
| '/:id/assign', | ||
| // TODO: restore once write:stewardships is added to Auth0 staging tenant | ||
| // requireScopes([SCOPES.WRITE_STEWARDSHIPS]), | ||
| safeWrap(assignStewardHandler), | ||
| ) | ||
| stewardshipsSubRouter.post( | ||
| '/:id/escalate', | ||
| // TODO: restore once write:stewardships is added to Auth0 staging tenant | ||
| // requireScopes([SCOPES.WRITE_STEWARDSHIPS]), | ||
| safeWrap(escalateHandler), | ||
| ) | ||
| stewardshipsSubRouter.patch( | ||
| '/:id/status', | ||
| // TODO: restore once write:stewardships is added to Auth0 staging tenant | ||
| // requireScopes([SCOPES.WRITE_STEWARDSHIPS]), | ||
| safeWrap(updateStatusHandler), | ||
| ) | ||
| router.use('/stewardships', stewardshipsSubRouter) | ||
|
|
||
| return router | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.