Added secret reminder handler on updates

This commit is contained in:
Daniel Hougaard
2023-10-24 05:15:40 +04:00
parent 93a1725da6
commit 80ce695355
@@ -32,6 +32,7 @@ import {
} from "../../ee/services/SecretApprovalService"; } from "../../ee/services/SecretApprovalService";
import { CommitType } from "../../ee/models/secretApprovalRequest"; import { CommitType } from "../../ee/models/secretApprovalRequest";
import { IRole } from "../../ee/models/role"; import { IRole } from "../../ee/models/role";
import { createReminder, deleteReminder } from "../../helpers/reminder";
const checkSecretsPermission = async ({ const checkSecretsPermission = async ({
authData, authData,
@@ -361,7 +362,14 @@ export const createSecretRaw = async (req: Request, res: Response) => {
export const updateSecretByNameRaw = async (req: Request, res: Response) => { export const updateSecretByNameRaw = async (req: Request, res: Response) => {
const { const {
params: { secretName }, params: { secretName },
body: { secretValue, environment, secretPath, type, workspaceId, skipMultilineEncoding } body: {
secretValue,
environment,
secretPath,
type,
workspaceId,
skipMultilineEncoding,
}
} = await validateRequest(reqValidator.UpdateSecretByNameRawV3, req); } = await validateRequest(reqValidator.UpdateSecretByNameRawV3, req);
await checkSecretsPermission({ await checkSecretsPermission({
@@ -686,7 +694,9 @@ export const updateSecretByName = async (req: Request, res: Response) => {
secretKeyIV, secretKeyIV,
secretKeyTag, secretKeyTag,
secretKeyCiphertext, secretKeyCiphertext,
skipMultilineEncoding skipMultilineEncoding,
secretReminderCron,
secretReminderNote,
}, },
params: { secretName } params: { secretName }
} = await validateRequest(reqValidator.UpdateSecretByNameV3, req); } = await validateRequest(reqValidator.UpdateSecretByNameV3, req);
@@ -706,6 +716,9 @@ export const updateSecretByName = async (req: Request, res: Response) => {
if (membership && type !== "personal") { if (membership && type !== "personal") {
const secretApprovalPolicy = await getSecretPolicyOfBoard(workspaceId, environment, secretPath); const secretApprovalPolicy = await getSecretPolicyOfBoard(workspaceId, environment, secretPath);
if (secretApprovalPolicy) { if (secretApprovalPolicy) {
// ? QUESTION
// ? Here we could also expand upon the reminders feature, by adding it to the approval process.
const secretApprovalRequest = await generateSecretApprovalRequest({ const secretApprovalRequest = await generateSecretApprovalRequest({
workspaceId, workspaceId,
environment, environment,
@@ -737,6 +750,32 @@ export const updateSecretByName = async (req: Request, res: Response) => {
} }
} }
if(type !== "personal") {
const existingSecret = await SecretService.getSecret({
secretName,
workspaceId: new Types.ObjectId(workspaceId),
environment,
type,
secretPath,
authData: req.authData
});
if((secretReminderCron && existingSecret.secretReminderCron !== secretReminderCron) || (secretReminderNote && existingSecret.secretReminderNote !== secretReminderNote)) {
await createReminder(existingSecret, {
_id: existingSecret._id,
secretReminderCron,
secretReminderNote,
workspace: existingSecret.workspace,
})
} else if(secretReminderCron === null && secretReminderNote === null && existingSecret.secretReminderCron) {
await deleteReminder({
_id: existingSecret._id,
secretReminderCron: existingSecret.secretReminderCron,
})
}
}
const secret = await SecretService.updateSecret({ const secret = await SecretService.updateSecret({
secretName, secretName,
workspaceId: new Types.ObjectId(workspaceId), workspaceId: new Types.ObjectId(workspaceId),
@@ -747,6 +786,8 @@ export const updateSecretByName = async (req: Request, res: Response) => {
newSecretName, newSecretName,
secretValueCiphertext, secretValueCiphertext,
secretValueIV, secretValueIV,
secretReminderCron,
secretReminderNote,
secretValueTag, secretValueTag,
secretPath, secretPath,
tags, tags,