mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 05:26:25 +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) => {
|
listen: async (name, event) => {
|
||||||
events[name] = event;
|
events[name] = event;
|
||||||
}
|
},
|
||||||
|
stopRepeatableJobByJobId: async () => true
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
+26
-6
@@ -15,7 +15,11 @@ import { TSecretVersionDalFactory } from "@app/services/secret/secret-version-da
|
|||||||
|
|
||||||
import { TSecretRotationDalFactory } from "../secret-rotation-dal";
|
import { TSecretRotationDalFactory } from "../secret-rotation-dal";
|
||||||
import { rotationTemplates } from "../templates";
|
import { rotationTemplates } from "../templates";
|
||||||
import { TProviderFunctionTypes, TSecretRotationProviderTemplate } from "../templates/types";
|
import {
|
||||||
|
TDbProviderClients,
|
||||||
|
TProviderFunctionTypes,
|
||||||
|
TSecretRotationProviderTemplate
|
||||||
|
} from "../templates/types";
|
||||||
import {
|
import {
|
||||||
getDbSetQuery,
|
getDbSetQuery,
|
||||||
secretRotationDbFn,
|
secretRotationDbFn,
|
||||||
@@ -79,8 +83,21 @@ export const secretRotationQueueFactory = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeFromQueue = async (rotationId: string) =>
|
const removeFromQueue = async (rotationId: string, interval: number) => {
|
||||||
queue.stopRepeatableJob(QueueName.SecretRotation, rotationId);
|
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) => {
|
queue.start(QueueName.SecretRotation, async (job) => {
|
||||||
const { rotationId } = job.data;
|
const { rotationId } = job.data;
|
||||||
@@ -155,7 +172,10 @@ export const secretRotationQueueFactory = ({
|
|||||||
database,
|
database,
|
||||||
port,
|
port,
|
||||||
ca: ca as string,
|
ca: ca as string,
|
||||||
client: provider.template.client
|
client:
|
||||||
|
provider.template.client === TDbProviderClients.MySql
|
||||||
|
? "mysql2"
|
||||||
|
: provider.template.client
|
||||||
} as TSecretRotationDbFn;
|
} as TSecretRotationDbFn;
|
||||||
// set function
|
// set function
|
||||||
await secretRotationDbFn({
|
await secretRotationDbFn({
|
||||||
@@ -244,12 +264,12 @@ export const secretRotationQueueFactory = ({
|
|||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
logger.info("Finished logging: rotation id: ", rotationId);
|
logger.info("Finished rotating: rotation id: ", rotationId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
if (error instanceof DisableRotationErrors) {
|
if (error instanceof DisableRotationErrors) {
|
||||||
if (job.id) {
|
if (job.id) {
|
||||||
queue.stopRepeatableJob(QueueName.SecretRotation, job.id);
|
queue.stopRepeatableJobByJobId(QueueName.SecretRotation, job.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ export const secretRotationServiceFactory = ({
|
|||||||
ProjectPermissionActions.Edit,
|
ProjectPermissionActions.Edit,
|
||||||
ProjectPermissionSub.SecretRotation
|
ProjectPermissionSub.SecretRotation
|
||||||
);
|
);
|
||||||
await secretRotationQueue.removeFromQueue(doc.id);
|
await secretRotationQueue.removeFromQueue(doc.id, doc.interval);
|
||||||
await secretRotationQueue.addToQueue(doc.id, doc.interval);
|
await secretRotationQueue.addToQueue(doc.id, doc.interval);
|
||||||
return doc;
|
return doc;
|
||||||
};
|
};
|
||||||
@@ -215,7 +215,7 @@ export const secretRotationServiceFactory = ({
|
|||||||
);
|
);
|
||||||
const deletedDoc = await secretRotationDal.transaction(async (tx) => {
|
const deletedDoc = await secretRotationDal.transaction(async (tx) => {
|
||||||
const strat = await secretRotationDal.deleteById(rotationId, tx);
|
const strat = await secretRotationDal.deleteById(rotationId, tx);
|
||||||
await secretRotationQueue.removeFromQueue(strat.id);
|
await secretRotationQueue.removeFromQueue(strat.id, strat.interval);
|
||||||
return strat;
|
return strat;
|
||||||
});
|
});
|
||||||
return { ...doc, ...deletedDoc };
|
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 Redis from "ioredis";
|
||||||
|
|
||||||
import { TCreateAuditLogDTO } from "@app/ee/services/audit-log/audit-log-types";
|
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);
|
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 q = queueContainer[name];
|
||||||
const job = await q.getJob(jobId);
|
const job = await q.getJob(jobId);
|
||||||
if (!job) return true;
|
if (!job) return true;
|
||||||
@@ -115,5 +125,5 @@ export const queueServiceFactory = (redisUrl: string) => {
|
|||||||
await Promise.all(Object.values(workerContainer).map((worker) => worker.close()));
|
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