mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-19 16:01:44 +00:00
62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { TPamAccountServiceFactory } from "@app/ee/services/pam-account/pam-account-service";
|
|
import { getConfig } from "@app/lib/config/env";
|
|
import { logger } from "@app/lib/logger";
|
|
import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";
|
|
|
|
type TPamAccountRotationServiceFactoryDep = {
|
|
queueService: TQueueServiceFactory;
|
|
pamAccountService: Pick<TPamAccountServiceFactory, "rotateAllDueAccounts">;
|
|
};
|
|
|
|
export type TPamAccountRotationServiceFactory = ReturnType<typeof pamAccountRotationServiceFactory>;
|
|
|
|
export const pamAccountRotationServiceFactory = ({
|
|
queueService,
|
|
pamAccountService
|
|
}: TPamAccountRotationServiceFactoryDep) => {
|
|
const appCfg = getConfig();
|
|
|
|
const init = async () => {
|
|
if (appCfg.isSecondaryInstance) {
|
|
return;
|
|
}
|
|
|
|
await queueService.stopRepeatableJob(
|
|
QueueName.PamAccountRotation,
|
|
QueueJobs.PamAccountRotation,
|
|
{ pattern: "0 * * * *", utc: true },
|
|
QueueName.PamAccountRotation // job id
|
|
);
|
|
|
|
await queueService.startPg<QueueName.PamAccountRotation>(
|
|
QueueJobs.PamAccountRotation,
|
|
async () => {
|
|
try {
|
|
logger.info(`${QueueName.PamAccountRotation}: pam account rotation task started`);
|
|
await pamAccountService.rotateAllDueAccounts();
|
|
logger.info(`${QueueName.PamAccountRotation}: pam account rotation task completed`);
|
|
} catch (error) {
|
|
logger.error(error, `${QueueName.PamAccountRotation}: pam account rotation failed`);
|
|
throw error;
|
|
}
|
|
},
|
|
{
|
|
batchSize: 1,
|
|
workerCount: 1,
|
|
pollingIntervalSeconds: 5 * 60
|
|
}
|
|
);
|
|
|
|
await queueService.schedulePg(
|
|
QueueJobs.PamAccountRotation,
|
|
"0 * * * *", // Schedule to run every hour
|
|
undefined,
|
|
{ tz: "UTC" }
|
|
);
|
|
};
|
|
|
|
return {
|
|
init
|
|
};
|
|
};
|