Skip to content

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

add deprecation warning

Matheus Nogueirab1afd00c2791
diff --git a/backend/src/lib/config/env.ts b/backend/src/lib/config/env.ts
index b1a37f8a13..3f0cf39961 100644
--- a/backend/src/lib/config/env.ts
+++ b/backend/src/lib/config/env.ts
@@ -9,7 +9,7 @@ import { TSuperAdminDALFactory } from "@app/services/super-admin/super-admin-dal
import { BadRequestError } from "../errors";
import { removeTrailingSlash } from "../fn";
-import { CustomLogger } from "../logger/logger";
+import { CustomLogger, logger } from "../logger/logger";
import { ms } from "../ms";
import { zpStr } from "../zod";
@@ -66,13 +66,16 @@ export const runModesSchema = zpStr(z.string().optional())
export const SECRET_SCANNING_SCAN_OVERHEAD = ms("5m");
const zodTimeoutMs = ({
+ envVar,
description,
defaultValue,
legacyMsEnvVar
}: {
+ envVar: string;
description: string;
defaultValue: string;
- legacyMsEnvVar: string;
+ // only for a timeout that predates this helper; a new one has no deprecated spelling to honour
+ legacyMsEnvVar?: string;
}) =>
zpStr(
z
@@ -80,7 +83,12 @@ const zodTimeoutMs = ({
.optional()
.describe(description)
.transform((val, ctx) => {
- const legacyValue = process.env[legacyMsEnvVar]?.trim() || undefined;
+ const legacyValue = legacyMsEnvVar ? process.env[legacyMsEnvVar]?.trim() || undefined : undefined;
+ // the singleton logger is undefined on the first parse, which happens during telemetry setup
+ if (legacyValue) {
+ (logger ?? console).warn(`${legacyMsEnvVar} is deprecated, use ${envVar} instead`);
+ }
+
const raw = val ?? legacyValue ?? defaultValue;
const duration = ms(raw);
@@ -88,9 +96,9 @@ const zodTimeoutMs = ({
ctx.addIssue({
code: z.ZodIssueCode.custom,
message:
- val === undefined
+ raw === legacyValue
? `Invalid value "${raw}" in ${legacyMsEnvVar}. Expected a positive number of milliseconds.`
- : `Invalid duration "${raw}". Expected a positive duration string such as "30s", "10m" or "6h".`
+ : `Invalid duration "${raw}" in ${envVar}. Expected a positive duration string such as "30s", "10m" or "6h".`
});
return z.NEVER;
}
@@ -101,16 +109,19 @@ const zodTimeoutMs = ({
export const secretScanningTimeoutsSchema = z.object({
SECRET_SCANNING_SCAN_TIMEOUT: zodTimeoutMs({
+ envVar: "SECRET_SCANNING_SCAN_TIMEOUT",
description: "Wall-clock ceiling for a single `infisical scan` invocation before its process group is killed",
defaultValue: "10m",
legacyMsEnvVar: "SECRET_SCANNING_SCAN_TIMEOUT_MS"
}),
SECRET_SCANNING_CLONE_TIMEOUT: zodTimeoutMs({
+ envVar: "SECRET_SCANNING_CLONE_TIMEOUT",
description: "Wall-clock ceiling for a single `git clone` invocation before its process group is killed",
defaultValue: "10m",
legacyMsEnvVar: "SECRET_SCANNING_CLONE_TIMEOUT_MS"
}),
SECRET_SCANNING_STUCK_SCAN_TIMEOUT: zodTimeoutMs({
+ envVar: "SECRET_SCANNING_STUCK_SCAN_TIMEOUT",
description:
"A scan left in the `scanning` state for longer than this is marked failed by the reaper. Must exceed clone + scan timeouts combined.",
defaultValue: "1h",
diff --git a/backend/src/lib/config/secret-scanning-timeouts.test.ts b/backend/src/lib/config/secret-scanning-timeouts.test.ts
index 3ad7acc43c..8173e76ca6 100644
--- a/backend/src/lib/config/secret-scanning-timeouts.test.ts
+++ b/backend/src/lib/config/secret-scanning-timeouts.test.ts
@@ -1,4 +1,4 @@
-import { afterEach, describe, expect, test, vi } from "vitest";
+import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
import { secretScanningTimeoutsSchema, validateSecretScanningTimeouts } from "./env";
@@ -48,7 +48,7 @@ describe("secret scanning timeouts", () => {
test("rejects a duration it cannot parse", () => {
expect(issuesFor(parse({ SECRET_SCANNING_SCAN_TIMEOUT: "banana" }), "SECRET_SCANNING_SCAN_TIMEOUT")).toEqual([
- 'Invalid duration "banana". Expected a positive duration string such as "30s", "10m" or "6h".'
+ 'Invalid duration "banana" in SECRET_SCANNING_SCAN_TIMEOUT. Expected a positive duration string such as "30s", "10m" or "6h".'
]);
});
@@ -139,3 +139,54 @@ describe("secret scanning timeouts", () => {
});
});
});
+
+describe("deprecation warning", () => {
+ // unit tests never call initLogger, so the warning lands on console
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
+
+ // the spy is installed at collection time, so it carries calls from the tests above
+ beforeEach(() => {
+ warn.mockClear();
+ });
+
+ test("stays quiet when no legacy variable is set", () => {
+ parse({});
+
+ expect(warn).not.toHaveBeenCalled();
+ });
+
+ test("names the legacy variable and its replacement", () => {
+ vi.stubEnv("SECRET_SCANNING_SCAN_TIMEOUT_MS", "600000");
+
+ parse({});
+
+ expect(warn).toHaveBeenCalledWith(
+ "SECRET_SCANNING_SCAN_TIMEOUT_MS is deprecated, use SECRET_SCANNING_SCAN_TIMEOUT instead"
+ );
+ });
+
+ test("warns for each legacy variable that is set", () => {
+ vi.stubEnv("SECRET_SCANNING_SCAN_TIMEOUT_MS", "600000");
+ vi.stubEnv("SECRET_SCANNING_CLONE_TIMEOUT_MS", "600000");
+
+ parse({});
+
+ expect(warn).toHaveBeenCalledTimes(2);
+ });
+
+ test("ignores a blank legacy variable", () => {
+ vi.stubEnv("SECRET_SCANNING_CLONE_TIMEOUT_MS", " ");
+
+ parse({});
+
+ expect(warn).not.toHaveBeenCalled();
+ });
+
+ test("warns even when the replacement is set, because the legacy value is then dead weight", () => {
+ vi.stubEnv("SECRET_SCANNING_STUCK_SCAN_TIMEOUT_MS", "3600000");
+
+ parse({ SECRET_SCANNING_STUCK_SCAN_TIMEOUT: "2h" });
+
+ expect(warn).toHaveBeenCalledTimes(1);
+ });
+});