-
Notifications
You must be signed in to change notification settings - Fork 989
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify secret snapshots to point to secret versions
- Loading branch information
1 parent
9d0e269
commit c7c5a94
Showing
14 changed files
with
229 additions
and
149 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import * as stripeController from './stripeController'; | ||
import * as secretController from './secretController'; | ||
import * as secretSnapshotController from './secretSnapshotController'; | ||
import * as workspaceController from './workspaceController'; | ||
import * as actionController from './actionController'; | ||
|
||
export { | ||
stripeController, | ||
secretController, | ||
secretSnapshotController, | ||
workspaceController, | ||
actionController | ||
} |
This file contains 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,27 @@ | ||
import { Request, Response } from 'express'; | ||
import * as Sentry from '@sentry/node'; | ||
import { SecretSnapshot } from '../../models'; | ||
|
||
export const getSecretSnapshot = async (req: Request, res: Response) => { | ||
let secretSnapshot; | ||
try { | ||
const { secretSnapshotId } = req.params; | ||
|
||
secretSnapshot = await SecretSnapshot | ||
.findById(secretSnapshotId) | ||
.populate('secretVersions'); | ||
|
||
if (!secretSnapshot) throw new Error('Failed to find secret snapshot'); | ||
|
||
} catch (err) { | ||
Sentry.setUser({ email: req.user.email }); | ||
Sentry.captureException(err); | ||
return res.status(400).send({ | ||
message: 'Failed to get secret snapshot' | ||
}); | ||
} | ||
|
||
return res.status(200).send({ | ||
secretSnapshot | ||
}); | ||
} |
This file contains 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
This file contains 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,7 @@ | ||
import requireLicenseAuth from './requireLicenseAuth'; | ||
import requireSecretSnapshotAuth from './requireSecretSnapshotAuth'; | ||
|
||
export { | ||
requireLicenseAuth, | ||
requireSecretSnapshotAuth | ||
} |
This file contains 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,50 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { UnauthorizedRequestError, SecretSnapshotNotFoundError } from '../../utils/errors'; | ||
import { SecretSnapshot } from '../models'; | ||
import { | ||
validateMembership | ||
} from '../../helpers/membership'; | ||
|
||
/** | ||
* Validate if user on request has proper membership for secret snapshot | ||
* @param {Object} obj | ||
* @param {String[]} obj.acceptedRoles - accepted workspace roles | ||
* @param {String[]} obj.acceptedStatuses - accepted workspace statuses | ||
* @param {String[]} obj.location - location of [workspaceId] on request (e.g. params, body) for parsing | ||
*/ | ||
const requireSecretSnapshotAuth = ({ | ||
acceptedRoles, | ||
acceptedStatuses | ||
}: { | ||
acceptedRoles: string[]; | ||
acceptedStatuses: string[]; | ||
}) => { | ||
return async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const { secretSnapshotId } = req.params; | ||
|
||
const secretSnapshot = await SecretSnapshot.findById(secretSnapshotId); | ||
|
||
if (!secretSnapshot) { | ||
return next(SecretSnapshotNotFoundError({ | ||
message: 'Failed to find secret snapshot' | ||
})); | ||
} | ||
|
||
await validateMembership({ | ||
userId: req.user._id.toString(), | ||
workspaceId: secretSnapshot.workspace.toString(), | ||
acceptedRoles, | ||
acceptedStatuses | ||
}); | ||
|
||
req.secretSnapshot = secretSnapshot as any; | ||
|
||
next(); | ||
} catch (err) { | ||
return next(UnauthorizedRequestError({ message: 'Unable to authenticate secret snapshot' })); | ||
} | ||
} | ||
} | ||
|
||
export default requireSecretSnapshotAuth; |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import secret from './secret'; | ||
import secretSnapshot from './secretSnapshot'; | ||
import workspace from './workspace'; | ||
import action from './action'; | ||
|
||
export { | ||
secret, | ||
secretSnapshot, | ||
workspace, | ||
action | ||
} |
This file contains 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
This file contains 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,26 @@ | ||
import express from 'express'; | ||
const router = express.Router(); | ||
import { | ||
requireSecretSnapshotAuth | ||
} from '../../middleware'; | ||
import { | ||
requireAuth, | ||
validateRequest | ||
} from '../../../middleware'; | ||
import { param } from 'express-validator'; | ||
import { ADMIN, MEMBER, GRANTED } from '../../../variables'; | ||
import { secretSnapshotController } from '../../controllers/v1'; | ||
|
||
router.get( | ||
'/:secretSnapshotId', | ||
requireAuth, | ||
requireSecretSnapshotAuth({ | ||
acceptedRoles: [ADMIN, MEMBER], | ||
acceptedStatuses: [GRANTED] | ||
}), | ||
param('secretSnapshotId').exists().trim(), | ||
validateRequest, | ||
secretSnapshotController.getSecretSnapshot | ||
); | ||
|
||
export default router; |
Oops, something went wrong.