@@ -8,8 +8,8 @@ const k8sBatchApi = kc.makeApiClient(k8s.BatchV1Api);
88
99const namespace = "integration-tests" ;
1010
11- const sleep = duration =>
12- new Promise ( resolve => setTimeout ( resolve , duration * 1000 ) ) ;
11+ const sleep = ( duration ) =>
12+ new Promise ( ( resolve ) => setTimeout ( resolve , duration * 1000 ) ) ;
1313
1414async function deleteScan ( name ) {
1515 await k8sCRDApi . deleteNamespacedCustomObject (
@@ -30,21 +30,18 @@ async function getScan(name) {
3030 "scans" ,
3131 name
3232 ) ;
33- return scan
33+ return scan ;
3434}
3535
3636async function logJob ( name ) {
3737 try {
38- const { body : job } = await k8sBatchApi . readNamespacedJob (
39- name ,
40- namespace ,
41- ) ;
42- console . log ( `Job: '${ name } ' Spec:` )
43- console . dir ( job . spec )
44- console . log ( `Job: '${ name } ' Status:` )
45- console . dir ( job . status )
38+ const { body : job } = await k8sBatchApi . readNamespacedJob ( name , namespace ) ;
39+ console . log ( `Job: '${ name } ' Spec:` ) ;
40+ console . dir ( job . spec ) ;
41+ console . log ( `Job: '${ name } ' Status:` ) ;
42+ console . dir ( job . status ) ;
4643 } catch ( error ) {
47- console . info ( `Job: '${ name } not found.'` )
44+ console . info ( `Job: '${ name } not found.'` ) ;
4845 }
4946}
5047
@@ -61,12 +58,12 @@ async function scan(name, scanType, parameters = [], timeout = 180) {
6158 kind : "Scan" ,
6259 metadata : {
6360 // Use `generateName` instead of name to generate a random sufix and avoid name clashes
64- generateName : `${ name } -`
61+ generateName : `${ name } -` ,
6562 } ,
6663 spec : {
6764 scanType,
68- parameters
69- }
65+ parameters,
66+ } ,
7067 } ;
7168
7269 const { body } = await k8sCRDApi . createNamespacedCustomObject (
@@ -82,25 +79,27 @@ async function scan(name, scanType, parameters = [], timeout = 180) {
8279 for ( let i = 0 ; i < timeout ; i ++ ) {
8380 await sleep ( 1 ) ;
8481 const { status } = await getScan ( actualName ) ;
85-
82+
8683 if ( status && status . state === "Done" ) {
8784 await deleteScan ( actualName ) ;
8885 return status . findings ;
8986 } else if ( status && status . state === "Errored" ) {
9087 await deleteScan ( actualName ) ;
91- throw new Error ( `Scan failed with description "${ status . errorDescription } "` )
88+ throw new Error (
89+ `Scan failed with description "${ status . errorDescription } "`
90+ ) ;
9291 }
9392 }
94-
95- console . error ( "Scan Timed out!" )
93+
94+ console . error ( "Scan Timed out!" ) ;
9695
9796 const scan = await getScan ( actualName ) ;
98- console . log ( "Last Scan State:" )
99- console . dir ( scan )
100- await logJob ( `scan-${ actualName } ` )
101- await logJob ( `parse-${ actualName } ` )
97+ console . log ( "Last Scan State:" ) ;
98+ console . dir ( scan ) ;
99+ await logJob ( `scan-${ actualName } ` ) ;
100+ await logJob ( `parse-${ actualName } ` ) ;
102101
103102 throw new Error ( "timed out while waiting for scan results" ) ;
104103}
105104
106- module . exports . scan = scan ;
105+ module . exports . scan = scan ;
0 commit comments