-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.ts
47 lines (42 loc) · 1.01 KB
/
store.ts
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
39
40
41
42
43
44
45
46
47
import { IngressTLS } from "kubernetes_apis/builtin/networking";
import { ArrayRule, ObjectRule, Rule } from "hoyams";
type SerializedConfig = {
certs: Array<{
match: string;
cert: {
secretName: string;
};
}>;
};
export type CertRule = {
match: RegExp;
cert: IngressTLS;
};
const configRule = new ObjectRule<SerializedConfig>({
certs: new ArrayRule({
match: new Rule((v) => {
try {
return !!new RegExp(v as string) || "no regex";
} catch (e) {
return e.toString();
}
}),
cert: {
secretName: new Rule((v) =>
typeof v === "string" || v === undefined || "is not a string"
),
},
}),
});
const deserialiceConfig = (json: string) => {
const parsed = configRule.validate(JSON.parse(json));
return {
certs: parsed.certs.map(({ match, cert }) => ({
match: new RegExp(match),
cert,
})) as Array<CertRule>,
};
};
export const store = {
config: deserialiceConfig(await Deno.readTextFile("./config.json")),
};