Skip to content

Commit 345da55

Browse files
committed
removeBlacklistedVariables moved to a separate file
1 parent 0d5905e commit 345da55

File tree

3 files changed

+42
-40
lines changed

3 files changed

+42
-40
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { type EnvironmentVariable } from "./environmentVariables/repository";
2+
3+
type VariableRule =
4+
| { type: "exact"; key: string }
5+
| { type: "prefix"; prefix: string }
6+
| { type: "whitelist"; key: string };
7+
8+
const blacklistedVariables: VariableRule[] = [
9+
{ type: "exact", key: "TRIGGER_SECRET_KEY" },
10+
{ type: "exact", key: "TRIGGER_API_URL" },
11+
{ type: "prefix", prefix: "OTEL_" },
12+
{ type: "whitelist", key: "OTEL_LOG_LEVEL" },
13+
];
14+
15+
export function removeBlacklistedVariables(
16+
variables: EnvironmentVariable[]
17+
): EnvironmentVariable[] {
18+
return variables.filter((v) => {
19+
const whitelisted = blacklistedVariables.find(
20+
(bv) => bv.type === "whitelist" && bv.key === v.key
21+
);
22+
if (whitelisted) {
23+
return true;
24+
}
25+
26+
const exact = blacklistedVariables.find((bv) => bv.type === "exact" && bv.key === v.key);
27+
if (exact) {
28+
return false;
29+
}
30+
31+
const prefix = blacklistedVariables.find(
32+
(bv) => bv.type === "prefix" && v.key.startsWith(bv.prefix)
33+
);
34+
if (prefix) {
35+
return false;
36+
}
37+
38+
return true;
39+
});
40+
}

apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
type Repository,
1616
type Result,
1717
} from "./repository";
18+
import { removeBlacklistedVariables } from "../environmentVariableRules.server";
1819

1920
function secretKeyProjectPrefix(projectId: string) {
2021
return `environmentvariable:${projectId}:`;
@@ -1038,42 +1039,3 @@ async function resolveCommonBuiltInVariables(
10381039
): Promise<Array<EnvironmentVariable>> {
10391040
return [];
10401041
}
1041-
1042-
type VariableRule =
1043-
| { type: "exact"; key: string }
1044-
| { type: "prefix"; prefix: string }
1045-
| { type: "whitelist"; key: string };
1046-
1047-
const blacklistedVariables: VariableRule[] = [
1048-
{ type: "exact", key: "TRIGGER_SECRET_KEY" },
1049-
{ type: "exact", key: "TRIGGER_API_URL" },
1050-
{ type: "prefix", prefix: "OTEL_" },
1051-
{ type: "whitelist", key: "OTEL_LOG_LEVEL" },
1052-
];
1053-
1054-
export function removeBlacklistedVariables(
1055-
variables: EnvironmentVariable[]
1056-
): EnvironmentVariable[] {
1057-
return variables.filter((v) => {
1058-
const whitelisted = blacklistedVariables.find(
1059-
(bv) => bv.type === "whitelist" && bv.key === v.key
1060-
);
1061-
if (whitelisted) {
1062-
return true;
1063-
}
1064-
1065-
const exact = blacklistedVariables.find((bv) => bv.type === "exact" && bv.key === v.key);
1066-
if (exact) {
1067-
return false;
1068-
}
1069-
1070-
const prefix = blacklistedVariables.find(
1071-
(bv) => bv.type === "prefix" && v.key.startsWith(bv.prefix)
1072-
);
1073-
if (prefix) {
1074-
return false;
1075-
}
1076-
1077-
return true;
1078-
});
1079-
}

apps/webapp/test/environmentVariableRules.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect } from "vitest";
2-
import { removeBlacklistedVariables } from "../app/v3/environmentVariables/environmentVariablesRepository.server";
32
import type { EnvironmentVariable } from "../app/v3/environmentVariables/repository";
3+
import { removeBlacklistedVariables } from "~/v3/environmentVariableRules.server";
44

55
describe("removeBlacklistedVariables", () => {
66
it("should remove exact match blacklisted variables", () => {

0 commit comments

Comments
 (0)