-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathenvironmentVariableRules.server.ts
More file actions
38 lines (32 loc) · 991 Bytes
/
environmentVariableRules.server.ts
File metadata and controls
38 lines (32 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { type EnvironmentVariable } from "./environmentVariables/repository";
type VariableRule =
| { type: "exact"; key: string }
| { type: "prefix"; prefix: string }
| { type: "whitelist"; key: string };
const blacklistedVariables: VariableRule[] = [
{ type: "exact", key: "TRIGGER_SECRET_KEY" },
{ type: "exact", key: "TRIGGER_API_URL" },
];
export function removeBlacklistedVariables(
variables: EnvironmentVariable[]
): EnvironmentVariable[] {
return variables.filter((v) => {
const whitelisted = blacklistedVariables.find(
(bv) => bv.type === "whitelist" && bv.key === v.key
);
if (whitelisted) {
return true;
}
const exact = blacklistedVariables.find((bv) => bv.type === "exact" && bv.key === v.key);
if (exact) {
return false;
}
const prefix = blacklistedVariables.find(
(bv) => bv.type === "prefix" && v.key.startsWith(bv.prefix)
);
if (prefix) {
return false;
}
return true;
});
}