Skip to content

Commit 9110a17

Browse files
committed
Use storage: number when parsing account configs.
1 parent 4f9a86e commit 9110a17

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

.tools/test/stacks/config/targets.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ interface AccountConfig {
1010
// https://docs.aws.amazon.com/batch/latest/APIReference/API_ResourceRequirement.html
1111
vcpus?: string; // Count
1212
memory?: string; // MiB, but limited based on vCPU count, see docs
13-
storage?: string; // GiB, 20GiB to 200GiB
13+
storage?: number; // GiB, 20GiB to 200GiB
14+
}
15+
16+
type AccountConfigYaml = {
17+
[K in keyof AccountConfig]: string
1418
}
1519

1620
interface AccountConfigs {
@@ -20,17 +24,38 @@ interface AccountConfigs {
2024
export function readAccountConfig(filePath: string): AccountConfigs {
2125
try {
2226
const fileContents = fs.readFileSync(filePath, "utf8");
23-
const data: AccountConfigs = parse(fileContents);
24-
25-
Object.values(data).forEach((config) => {
26-
if (!config.account_id || !config.status) {
27-
throw new Error("Validation failed: Missing required account fields.");
27+
const data = Object.entries(parse(fileContents) as Record<string, AccountConfigYaml>).reduce((data, [name, config]) => {
28+
const {account_id, status, vcpus, memory, storage} = config;
29+
if (!account_id) {
30+
throw new Error(`Validation failed: Missing account_id field in ${name}`);
31+
}
32+
switch (status) {
33+
case "enabled": // fallthrough
34+
case "disabled":
35+
break;
36+
default:
37+
throw new Error(`Validation failed: invalid status ${status} in ${name}`)
2838
}
29-
});
39+
data[name] = {
40+
account_id,
41+
status,
42+
vcpus,
43+
memory,
44+
storage: numberOrDefault(storage, 20),
45+
}
46+
return data;
47+
}, {} as Record<string, AccountConfig>)
3048

3149
return data;
3250
} catch (error) {
3351
console.error("Failed to read or parse the YAML file:", { error });
3452
throw error;
3553
}
3654
}
55+
56+
function numberOrDefault(storage: string | undefined, defaultValue: number) {
57+
const batchStorage = Number(storage);
58+
const batchStorageNumber = isNaN(batchStorage) ? defaultValue : batchStorage;
59+
return batchStorageNumber;
60+
}
61+

.tools/test/stacks/plugin/typescript/plugin_stack.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ class PluginStack extends cdk.Stack {
4444
// https://docs.aws.amazon.com/batch/latest/APIReference/API_ResourceRequirement.html
4545
this.batchMemory = acctConfig[`${toolName}`]?.memory ?? "16384"; // MiB
4646
this.batchVcpus = acctConfig[`${toolName}`]?.vcpus ?? "4"; // CPUs
47-
const batchStorage = Number(acctConfig[`${toolName}`]?.storage ?? undefined);
48-
this.batchStorage = isNaN(batchStorage) ? 20 : batchStorage; // GiB
47+
this.batchStorage = acctConfig[`${toolName}`]?.storage ?? 20; // GiB
4948
}
5049

5150
const [jobDefinition, jobQueue] = this.initBatchFargate();
@@ -142,7 +141,7 @@ class PluginStack extends cdk.Stack {
142141
},
143142
],
144143
ephemeralStorage: {
145-
sizeInGiB: this.batchStorage,
144+
sizeInGib: this.batchStorage,
146145
},
147146
environment: variableConfigJson,
148147
},

0 commit comments

Comments
 (0)