mirror of
https://github.com/Infisical/infisical.git
synced 2025-03-31 22:09:57 +00:00
feat(infisical-pg): fixed secret deletion not getting triggered
This commit is contained in:
@ -18,6 +18,7 @@ export const mockQueue = (): TQueueServiceFactory => {
|
||||
},
|
||||
listen: async (name, event) => {
|
||||
events[name] = event;
|
||||
}
|
||||
},
|
||||
stopRepeatableJobByJobId: async () => true
|
||||
};
|
||||
};
|
||||
|
@ -15,7 +15,11 @@ import { TSecretVersionDalFactory } from "@app/services/secret/secret-version-da
|
||||
|
||||
import { TSecretRotationDalFactory } from "../secret-rotation-dal";
|
||||
import { rotationTemplates } from "../templates";
|
||||
import { TProviderFunctionTypes, TSecretRotationProviderTemplate } from "../templates/types";
|
||||
import {
|
||||
TDbProviderClients,
|
||||
TProviderFunctionTypes,
|
||||
TSecretRotationProviderTemplate
|
||||
} from "../templates/types";
|
||||
import {
|
||||
getDbSetQuery,
|
||||
secretRotationDbFn,
|
||||
@ -79,8 +83,21 @@ export const secretRotationQueueFactory = ({
|
||||
);
|
||||
};
|
||||
|
||||
const removeFromQueue = async (rotationId: string) =>
|
||||
queue.stopRepeatableJob(QueueName.SecretRotation, rotationId);
|
||||
const removeFromQueue = async (rotationId: string, interval: number) => {
|
||||
const appCfg = getConfig();
|
||||
await queue.stopRepeatableJob(
|
||||
QueueName.SecretRotation,
|
||||
QueueJobs.SecretRotation,
|
||||
{
|
||||
// on prod it this will be in days, in development this will be second
|
||||
every:
|
||||
appCfg.NODE_ENV === "development"
|
||||
? secondsToMillis(interval)
|
||||
: daysToMillisecond(interval)
|
||||
},
|
||||
rotationId
|
||||
);
|
||||
};
|
||||
|
||||
queue.start(QueueName.SecretRotation, async (job) => {
|
||||
const { rotationId } = job.data;
|
||||
@ -155,7 +172,10 @@ export const secretRotationQueueFactory = ({
|
||||
database,
|
||||
port,
|
||||
ca: ca as string,
|
||||
client: provider.template.client
|
||||
client:
|
||||
provider.template.client === TDbProviderClients.MySql
|
||||
? "mysql2"
|
||||
: provider.template.client
|
||||
} as TSecretRotationDbFn;
|
||||
// set function
|
||||
await secretRotationDbFn({
|
||||
@ -244,12 +264,12 @@ export const secretRotationQueueFactory = ({
|
||||
tx
|
||||
);
|
||||
});
|
||||
logger.info("Finished logging: rotation id: ", rotationId);
|
||||
logger.info("Finished rotating: rotation id: ", rotationId);
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
if (error instanceof DisableRotationErrors) {
|
||||
if (job.id) {
|
||||
queue.stopRepeatableJob(QueueName.SecretRotation, job.id);
|
||||
queue.stopRepeatableJobByJobId(QueueName.SecretRotation, job.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ export const secretRotationServiceFactory = ({
|
||||
ProjectPermissionActions.Edit,
|
||||
ProjectPermissionSub.SecretRotation
|
||||
);
|
||||
await secretRotationQueue.removeFromQueue(doc.id);
|
||||
await secretRotationQueue.removeFromQueue(doc.id, doc.interval);
|
||||
await secretRotationQueue.addToQueue(doc.id, doc.interval);
|
||||
return doc;
|
||||
};
|
||||
@ -215,7 +215,7 @@ export const secretRotationServiceFactory = ({
|
||||
);
|
||||
const deletedDoc = await secretRotationDal.transaction(async (tx) => {
|
||||
const strat = await secretRotationDal.deleteById(rotationId, tx);
|
||||
await secretRotationQueue.removeFromQueue(strat.id);
|
||||
await secretRotationQueue.removeFromQueue(strat.id, strat.interval);
|
||||
return strat;
|
||||
});
|
||||
return { ...doc, ...deletedDoc };
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Job, JobsOptions, Queue, Worker, WorkerListener } from "bullmq";
|
||||
import { Job, JobsOptions, Queue, RepeatOptions, Worker, WorkerListener } from "bullmq";
|
||||
import Redis from "ioredis";
|
||||
|
||||
import { TCreateAuditLogDTO } from "@app/ee/services/audit-log/audit-log-types";
|
||||
@ -103,7 +103,17 @@ export const queueServiceFactory = (redisUrl: string) => {
|
||||
await q.add(job, data, opts);
|
||||
};
|
||||
|
||||
const stopRepeatableJob = async <T extends QueueName>(name: T, jobId: string) => {
|
||||
const stopRepeatableJob = async <T extends QueueName>(
|
||||
name: T,
|
||||
job: TQueueJobTypes[T]["name"],
|
||||
repeatOpt: RepeatOptions,
|
||||
jobId?: string
|
||||
) => {
|
||||
const q = queueContainer[name];
|
||||
return q.removeRepeatable(job, repeatOpt, jobId);
|
||||
};
|
||||
|
||||
const stopRepeatableJobByJobId = async <T extends QueueName>(name: T, jobId: string) => {
|
||||
const q = queueContainer[name];
|
||||
const job = await q.getJob(jobId);
|
||||
if (!job) return true;
|
||||
@ -115,5 +125,5 @@ export const queueServiceFactory = (redisUrl: string) => {
|
||||
await Promise.all(Object.values(workerContainer).map((worker) => worker.close()));
|
||||
};
|
||||
|
||||
return { start, listen, queue, shutdown, stopRepeatableJob };
|
||||
return { start, listen, queue, shutdown, stopRepeatableJob, stopRepeatableJobByJobId };
|
||||
};
|
||||
|
Reference in New Issue
Block a user