This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.ts
79 lines (73 loc) · 1.9 KB
/
config.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { makeEnv, parsers } from "@strattadb/environment";
import dotenv from "dotenv";
import type SSH from "node-ssh";
import username from "username";
/** Retrieve array item using letter index A=0,B=1,etc. */
export function atIndex<T>(arr: readonly T[], index: string): T {
const i = index.charCodeAt(0) - "A".charCodeAt(0);
if (i < 0 || i >= arr.length) {
throw new Error("index out of range");
}
return arr[i];
}
/** Configured information about a network interface. */
export interface NetifInfo {
pci: string;
numa: number;
}
/** Parse netif list in "PCI@numa" format. */
function parseIfList(s: string): NetifInfo[] {
return s.split(",").map((ifDef) => {
const m = /^([\da-f]{2}:[\da-f]{2}\.[\da-f])@(\d)$/.exec(ifDef);
if (!m) {
throw new Error(`invalid netif definition: ${ifDef}`);
}
return { pci: m[1], numa: Number.parseInt(m[2], 10) };
});
}
dotenv.config();
export const env = makeEnv({
MGMT_FW: {
parser: parsers.string,
envVarName: "MGMT_FW",
required: true,
},
MGMT_GEN: {
parser: parsers.string,
envVarName: "MGMT_GEN",
required: true,
},
HUGE1G_NPAGES: {
parser: parsers.positiveInteger,
envVarName: "HUGE1G_NPAGES",
required: false,
defaultValue: 64,
},
SPDK_PATH: {
parser: parsers.string,
envVarName: "SPDK_PATH",
required: true,
},
ENABLE_CPUSET: {
parser: parsers.boolean,
envVarName: "ENABLE_CPUSET",
required: true,
},
IF_FW: {
parser: parseIfList,
envVarName: "IF_FW",
required: true,
},
IF_GEN: {
parser: parseIfList,
envVarName: "IF_GEN",
required: true,
},
});
export function getSshConfig(id: string): SSH.ConfigGiven {
return {
host: process.env[`SSH_${id}_HOST`] ?? "localhost",
username: process.env[`SSH_${id}_USER`] ?? username.sync() ?? "root",
privateKey: process.env[`SSH_${id}_KEY`] ?? `${process.env.HOME}/.ssh/id_rsa`,
};
}