@@ -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
1620interface AccountConfigs {
@@ -20,17 +24,38 @@ interface AccountConfigs {
2024export 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+
0 commit comments