Skip to content

Commit

Permalink
Small modifications to secret versioning/snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
dangtony98 committed Dec 25, 2022
1 parent 890aff8 commit f37fc9c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/src/controllers/secretController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export const getSecretVersions = async (req: Request, res: Response) => {
.limit(limit);

} catch (err) {
Sentry.setUser({ email: req.serviceToken.user.email });
Sentry.setUser({ email: req.user.email });
Sentry.captureException(err);
return res.status(400).send({
message: 'Failed to get secret versions'
Expand Down
35 changes: 34 additions & 1 deletion backend/src/controllers/workspaceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
Integration,
IntegrationAuth,
IUser,
ServiceToken
ServiceToken,
SecretSnapshot
} from '../models';
import {
createWorkspace as create,
Expand Down Expand Up @@ -334,4 +335,36 @@ export const getWorkspaceServiceTokens = async (
return res.status(200).send({
serviceTokens
});
}

/**
* Return secret snapshots for workspace with id [workspaceId]
* @param req
* @param res
*/
export const getWorkspaceSecretSnapshots = async (req: Request, res: Response) => {
let secretSnapshots;
try {
const { workspaceId } = req.params;

const offset: number = parseInt(req.query.offset as string);
const limit: number = parseInt(req.query.limit as string);

secretSnapshots = await SecretSnapshot.find({
workspace: workspaceId
})
.skip(offset)
.limit(limit);

} catch (err) {
Sentry.setUser({ email: req.user.email });
Sentry.captureException(err);
return res.status(400).send({
message: 'Failed to get secret snapshots'
});
}

return res.status(200).send({
secretSnapshots
});
}
16 changes: 15 additions & 1 deletion backend/src/routes/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express from 'express';
const router = express.Router();
import { body, param } from 'express-validator';
import { body, param, query } from 'express-validator';
import {
requireAuth,
requireWorkspaceAuth,
Expand Down Expand Up @@ -130,4 +130,18 @@ router.get(
workspaceController.getWorkspaceServiceTokens
);

router.get(
'/:workspaceId/secret-snapshots',
requireAuth,
requireWorkspaceAuth({
acceptedRoles: [ADMIN, MEMBER],
acceptedStatuses: [GRANTED]
}),
param('workspaceId').exists().trim(),
query('offset').exists().isInt(),
query('limit').exists().isInt(),
validateRequest,
workspaceController.getWorkspaceSecretSnapshots
);

export default router;

0 comments on commit f37fc9c

Please sign in to comment.