Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

refactor: streamline sync functions for license, rate limit, and Microsoft Teams services

Victor Hugo dos Santos5292849c71d1
diff --git a/backend/src/ee/services/license/license-service.ts b/backend/src/ee/services/license/license-service.ts
index d3b7c36129..2d151e50d6 100644
--- a/backend/src/ee/services/license/license-service.ts
+++ b/backend/src/ee/services/license/license-service.ts
@@ -161,7 +161,7 @@ export const licenseServiceFactory = ({
return startLocalRefresh({
name: "self-hosted-license-sync",
intervalMs: 10 * 60 * 1000,
- task: () => syncSelfHostedFeatures()
+ task: () => syncSelfHostedFeatures(true)
});
}
};
diff --git a/backend/src/ee/services/rate-limit/rate-limit-service.ts b/backend/src/ee/services/rate-limit/rate-limit-service.ts
index ae0f024ed4..adfc3d2f9d 100644
--- a/backend/src/ee/services/rate-limit/rate-limit-service.ts
+++ b/backend/src/ee/services/rate-limit/rate-limit-service.ts
@@ -57,26 +57,30 @@ export const rateLimitServiceFactory = ({
return rateLimitDAL.updateById(DEFAULT_RATE_LIMIT_CONFIG_ID, updates);
};
+ const $syncRateLimitConfiguration = async () => {
+ const rateLimit = await getRateLimits();
+ if (rateLimit) {
+ const newRateLimitMaxConfiguration: typeof rateLimitMaxConfiguration = {
+ readLimit: rateLimit.readRateLimit,
+ publicEndpointLimit: rateLimit.publicEndpointLimit,
+ writeLimit: rateLimit.writeRateLimit,
+ secretsLimit: rateLimit.secretsRateLimit,
+ authRateLimit: rateLimit.authRateLimit,
+ inviteUserRateLimit: rateLimit.inviteUserRateLimit,
+ mfaRateLimit: rateLimit.mfaRateLimit,
+ identityCreationLimit: rateLimit.identityCreationLimit,
+ projectCreationLimit: rateLimit.projectCreationLimit
+ };
+
+ logger.info(newRateLimitMaxConfiguration, "syncRateLimitConfiguration: rate limit configuration");
+ Object.freeze(newRateLimitMaxConfiguration);
+ rateLimitMaxConfiguration = newRateLimitMaxConfiguration;
+ }
+ };
+
const syncRateLimitConfiguration: TRateLimitServiceFactory["syncRateLimitConfiguration"] = async () => {
try {
- const rateLimit = await getRateLimits();
- if (rateLimit) {
- const newRateLimitMaxConfiguration: typeof rateLimitMaxConfiguration = {
- readLimit: rateLimit.readRateLimit,
- publicEndpointLimit: rateLimit.publicEndpointLimit,
- writeLimit: rateLimit.writeRateLimit,
- secretsLimit: rateLimit.secretsRateLimit,
- authRateLimit: rateLimit.authRateLimit,
- inviteUserRateLimit: rateLimit.inviteUserRateLimit,
- mfaRateLimit: rateLimit.mfaRateLimit,
- identityCreationLimit: rateLimit.identityCreationLimit,
- projectCreationLimit: rateLimit.projectCreationLimit
- };
-
- logger.info(newRateLimitMaxConfiguration, "syncRateLimitConfiguration: rate limit configuration");
- Object.freeze(newRateLimitMaxConfiguration);
- rateLimitMaxConfiguration = newRateLimitMaxConfiguration;
- }
+ await $syncRateLimitConfiguration();
} catch (error) {
logger.error(error, "Error syncing rate limit configurations");
}
@@ -95,7 +99,7 @@ export const rateLimitServiceFactory = ({
return startLocalRefresh({
name: "rate-limit-config-sync",
intervalMs: 10 * 60 * 1000,
- task: syncRateLimitConfiguration
+ task: $syncRateLimitConfiguration
});
};
diff --git a/backend/src/services/microsoft-teams/microsoft-teams-service.ts b/backend/src/services/microsoft-teams/microsoft-teams-service.ts
index 6a790bca6b..20c565d865 100644
--- a/backend/src/services/microsoft-teams/microsoft-teams-service.ts
+++ b/backend/src/services/microsoft-teams/microsoft-teams-service.ts
@@ -123,45 +123,48 @@ export const microsoftTeamsServiceFactory = ({
}
};
+ // Throws, so the local refresh sees the failure; the startup sync in initializeBackgroundSync catches instead.
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;
- }
+ const serverCfg = await serverCfgDAL.findById(ADMIN_CONFIG_DB_UUID);
+ if (!serverCfg) {
+ throw new BadRequestError({
+ message: "Failed to get server configuration."
+ });
+ }
- lastKnownUpdatedAt = serverCfg.updatedAt;
+ if (lastKnownUpdatedAt.getTime() === serverCfg.updatedAt.getTime()) {
+ logger.info("No changes to Microsoft Teams integration configuration, skipping sync");
+ return;
+ }
- if (
- serverCfg.encryptedMicrosoftTeamsAppId &&
- serverCfg.encryptedMicrosoftTeamsClientSecret &&
- serverCfg.encryptedMicrosoftTeamsBotId
- ) {
- const decryptWithRoot = kmsService.decryptWithRootKey();
- const decryptedAppId = decryptWithRoot(serverCfg.encryptedMicrosoftTeamsAppId);
- const decryptedAppPassword = decryptWithRoot(serverCfg.encryptedMicrosoftTeamsClientSecret);
+ 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");
+ await initializeTeamsBot({
+ botAppId: decryptedAppId.toString(),
+ botAppPassword: decryptedAppPassword.toString()
+ });
}
+
+ // Recorded only once the bot is up: marking the config seen before a failed init would make every
+ // later run skip it as unchanged, so a failure would never be retried.
+ lastKnownUpdatedAt = serverCfg.updatedAt;
};
const initializeBackgroundSync = async () => {
logger.info("Setting up background sync process for Microsoft Teams workflow integration configuration");
// initial sync upon startup
- await $syncMicrosoftTeamsIntegrationConfiguration();
+ try {
+ await $syncMicrosoftTeamsIntegrationConfiguration();
+ } catch (err) {
+ logger.error(err, "Error syncing Microsoft Teams integration configuration");
+ }
return startLocalRefresh({
name: "microsoft-teams-config-sync",