mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-03 07:26:00 +00:00
fix(workflow-integrations): microsoft teams scaling issues
This commit is contained in:
@@ -1784,6 +1784,10 @@ export const registerRoutes = async (
|
|||||||
if (licenseSyncJob) {
|
if (licenseSyncJob) {
|
||||||
cronJobs.push(licenseSyncJob);
|
cronJobs.push(licenseSyncJob);
|
||||||
}
|
}
|
||||||
|
const microsoftTeamsSyncJob = await microsoftTeamsService.initializeBackgroundSync();
|
||||||
|
if (microsoftTeamsSyncJob) {
|
||||||
|
cronJobs.push(microsoftTeamsSyncJob);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
server.decorate<FastifyZodProvider["store"]>("store", {
|
server.decorate<FastifyZodProvider["store"]>("store", {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
Request,
|
Request,
|
||||||
Response
|
Response
|
||||||
} from "botbuilder";
|
} from "botbuilder";
|
||||||
|
import { CronJob } from "cron";
|
||||||
import { FastifyReply, FastifyRequest } from "fastify";
|
import { FastifyReply, FastifyRequest } from "fastify";
|
||||||
|
|
||||||
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
|
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
|
||||||
@@ -86,8 +87,17 @@ export const microsoftTeamsServiceFactory = ({
|
|||||||
}: TMicrosoftTeamsServiceFactoryDep) => {
|
}: TMicrosoftTeamsServiceFactoryDep) => {
|
||||||
let teamsBot: TeamsBot | null = null;
|
let teamsBot: TeamsBot | null = null;
|
||||||
let adapter: CloudAdapter | null = null;
|
let adapter: CloudAdapter | null = null;
|
||||||
|
let lastKnownUpdatedAt = new Date();
|
||||||
|
|
||||||
const initializeTeamsBot = async ({ botAppId, botAppPassword }: { botAppId: string; botAppPassword: string }) => {
|
const initializeTeamsBot = async ({
|
||||||
|
botAppId,
|
||||||
|
botAppPassword,
|
||||||
|
lastUpdatedAt
|
||||||
|
}: {
|
||||||
|
botAppId: string;
|
||||||
|
botAppPassword: string;
|
||||||
|
lastUpdatedAt?: Date;
|
||||||
|
}) => {
|
||||||
logger.info("Initializing Microsoft Teams bot");
|
logger.info("Initializing Microsoft Teams bot");
|
||||||
teamsBot = new TeamsBot({
|
teamsBot = new TeamsBot({
|
||||||
botAppId,
|
botAppId,
|
||||||
@@ -106,6 +116,57 @@ export const microsoftTeamsServiceFactory = ({
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (lastUpdatedAt) {
|
||||||
|
lastKnownUpdatedAt = lastUpdatedAt;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const $syncMicrosoftTeamsIntegrationConfiguration = async () => {
|
||||||
|
try {
|
||||||
|
const serverCfg = await serverCfgDAL.findById(ADMIN_CONFIG_DB_UUID);
|
||||||
|
if (!serverCfg) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: "Failed to get server configuration."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastKnownUpdatedAt.getTime() === serverCfg.updatedAt.getTime()) {
|
||||||
|
logger.info("No changes to Microsoft Teams integration configuration, skipping sync");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastKnownUpdatedAt = serverCfg.updatedAt;
|
||||||
|
|
||||||
|
if (
|
||||||
|
serverCfg.encryptedMicrosoftTeamsAppId &&
|
||||||
|
serverCfg.encryptedMicrosoftTeamsClientSecret &&
|
||||||
|
serverCfg.encryptedMicrosoftTeamsBotId
|
||||||
|
) {
|
||||||
|
const decryptWithRoot = kmsService.decryptWithRootKey();
|
||||||
|
const decryptedAppId = decryptWithRoot(serverCfg.encryptedMicrosoftTeamsAppId);
|
||||||
|
const decryptedAppPassword = decryptWithRoot(serverCfg.encryptedMicrosoftTeamsClientSecret);
|
||||||
|
|
||||||
|
await initializeTeamsBot({
|
||||||
|
botAppId: decryptedAppId.toString(),
|
||||||
|
botAppPassword: decryptedAppPassword.toString()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(err, "Error syncing Microsoft Teams integration configuration");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const initializeBackgroundSync = async () => {
|
||||||
|
logger.info("Setting up background sync process for Microsoft Teams workflow integration configuration");
|
||||||
|
// initial sync upon startup
|
||||||
|
await $syncMicrosoftTeamsIntegrationConfiguration();
|
||||||
|
|
||||||
|
// sync rate limits configuration every 5 minutes
|
||||||
|
const job = new CronJob("*/5 * * * *", $syncMicrosoftTeamsIntegrationConfiguration);
|
||||||
|
job.start();
|
||||||
|
|
||||||
|
return job;
|
||||||
};
|
};
|
||||||
|
|
||||||
const start = async () => {
|
const start = async () => {
|
||||||
@@ -703,6 +764,7 @@ export const microsoftTeamsServiceFactory = ({
|
|||||||
getTeams,
|
getTeams,
|
||||||
handleMessageEndpoint,
|
handleMessageEndpoint,
|
||||||
start,
|
start,
|
||||||
|
initializeBackgroundSync,
|
||||||
sendNotification,
|
sendNotification,
|
||||||
checkInstallationStatus,
|
checkInstallationStatus,
|
||||||
getClientId
|
getClientId
|
||||||
|
|||||||
@@ -246,7 +246,8 @@ export const superAdminServiceFactory = ({
|
|||||||
|
|
||||||
await microsoftTeamsService.initializeTeamsBot({
|
await microsoftTeamsService.initializeTeamsBot({
|
||||||
botAppId: decryptedAppId.toString(),
|
botAppId: decryptedAppId.toString(),
|
||||||
botAppPassword: decryptedAppPassword.toString()
|
botAppPassword: decryptedAppPassword.toString(),
|
||||||
|
lastUpdatedAt: updatedServerCfg.updatedAt
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export const MicrosoftTeamsIntegrationForm = ({ adminIntegrationsConfig }: Props
|
|||||||
});
|
});
|
||||||
|
|
||||||
createNotification({
|
createNotification({
|
||||||
text: "Updated admin Microsoft Teams configuration",
|
text: "Updated admin Microsoft Teams configuration. It can take up to 5 minutes to take effect.",
|
||||||
type: "success"
|
type: "success"
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user