mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 20:26:44 +00:00
Patch undefined req.secrets
This commit is contained in:
@@ -43,17 +43,6 @@ export const batchSecrets = async (req: Request, res: Response) => {
|
|||||||
requests: BatchSecretRequest[];
|
requests: BatchSecretRequest[];
|
||||||
}= req.body;
|
}= req.body;
|
||||||
|
|
||||||
// construct object containing all secrets
|
|
||||||
const listedSecretsObj: {
|
|
||||||
[key: string]: {
|
|
||||||
version: number;
|
|
||||||
type: string;
|
|
||||||
}
|
|
||||||
} = req.secrets.reduce((obj: any, secret: ISecret) => ({
|
|
||||||
...obj,
|
|
||||||
[secret._id.toString()]: secret
|
|
||||||
}), {});
|
|
||||||
|
|
||||||
const createSecrets: BatchSecret[] = [];
|
const createSecrets: BatchSecret[] = [];
|
||||||
const updateSecrets: BatchSecret[] = [];
|
const updateSecrets: BatchSecret[] = [];
|
||||||
const deleteSecrets: Types.ObjectId[] = [];
|
const deleteSecrets: Types.ObjectId[] = [];
|
||||||
@@ -123,7 +112,20 @@ export const batchSecrets = async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
// handle update secrets
|
// handle update secrets
|
||||||
let updatedSecrets: ISecret[] = [];
|
let updatedSecrets: ISecret[] = [];
|
||||||
if (updateSecrets.length > 0) {
|
if (updateSecrets.length > 0 && req.secrets) {
|
||||||
|
// construct object containing all secrets
|
||||||
|
let listedSecretsObj: {
|
||||||
|
[key: string]: {
|
||||||
|
version: number;
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
} = {};
|
||||||
|
|
||||||
|
listedSecretsObj = req.secrets.reduce((obj: any, secret: ISecret) => ({
|
||||||
|
...obj,
|
||||||
|
[secret._id.toString()]: secret
|
||||||
|
}), {});
|
||||||
|
|
||||||
const updateOperations = updateSecrets.map((u) => ({
|
const updateOperations = updateSecrets.map((u) => ({
|
||||||
updateOne: {
|
updateOne: {
|
||||||
filter: { _id: new Types.ObjectId(u._id) },
|
filter: { _id: new Types.ObjectId(u._id) },
|
||||||
@@ -168,6 +170,14 @@ export const batchSecrets = async (req: Request, res: Response) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const updateAction = await EELogService.createAction({
|
||||||
|
name: ACTION_UPDATE_SECRETS,
|
||||||
|
userId: req.user._id,
|
||||||
|
workspaceId: new Types.ObjectId(workspaceId),
|
||||||
|
secretIds: updatedSecrets.map((u) => u._id)
|
||||||
|
}) as IAction;
|
||||||
|
actions.push(updateAction);
|
||||||
|
|
||||||
if (postHogClient) {
|
if (postHogClient) {
|
||||||
postHogClient.capture({
|
postHogClient.capture({
|
||||||
event: 'secrets modified',
|
event: 'secrets modified',
|
||||||
@@ -218,7 +228,7 @@ export const batchSecrets = async (req: Request, res: Response) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actions.length > 1) {
|
if (actions.length > 0) {
|
||||||
// (EE) create (audit) log
|
// (EE) create (audit) log
|
||||||
await EELogService.createLog({
|
await EELogService.createLog({
|
||||||
userId: req.user._id.toString(),
|
userId: req.user._id.toString(),
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import {
|
|||||||
SECRET_PERSONAL,
|
SECRET_PERSONAL,
|
||||||
SECRET_SHARED
|
SECRET_SHARED
|
||||||
} from '../../variables';
|
} from '../../variables';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
BatchSecretRequest
|
BatchSecretRequest
|
||||||
} from '../../types/secret';
|
} from '../../types/secret';
|
||||||
|
|||||||
Reference in New Issue
Block a user