misc: added flag to disable rate limit updates via API

This commit is contained in:
Sheen Capadngan
2024-06-13 18:37:29 +08:00
parent d0ffb94bc7
commit 20fea1e25f
3 changed files with 13 additions and 1 deletions

View File

@@ -67,3 +67,5 @@ CLIENT_SECRET_GITLAB_LOGIN=
CAPTCHA_SECRET=
NEXT_PUBLIC_CAPTCHA_SITE_KEY=
ALLOW_RATELIMIT_UPDATES=

View File

@@ -123,7 +123,8 @@ const envSchema = z
.optional(),
INFISICAL_CLOUD: zodStrBool.default("false"),
MAINTENANCE_MODE: zodStrBool.default("false"),
CAPTCHA_SECRET: zpStr(z.string().optional())
CAPTCHA_SECRET: zpStr(z.string().optional()),
ALLOW_RATELIMIT_UPDATES: zodStrBool.default("false")
})
.transform((data) => ({
...data,

View File

@@ -1,5 +1,7 @@
import { CronJob } from "cron";
import { getConfig } from "@app/lib/config/env";
import { ForbiddenRequestError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
import { rateLimitMaxConfiguration } from "@app/server/config/rateLimiter";
@@ -22,6 +24,13 @@ export const rateLimitServiceFactory = ({ rateLimitDAL }: TRateLimitServiceFacto
};
const updateRateLimit = async (updates: TRateLimitUpdateDTO): Promise<TRateLimit> => {
const appCfg = getConfig();
if (!appCfg.ALLOW_RATELIMIT_UPDATES) {
throw new ForbiddenRequestError({
name: "Rate limit Updates Disabled",
message: "Changes to rate limits are disabled"
});
}
return rateLimitDAL.updateById("00000000-0000-0000-0000-000000000000", updates);
};