22//
33// SPDX-License-Identifier: Apache-2.0
44
5+ const axios = require ( "axios" ) ;
56const { handle } = require ( "./hook/hook" ) ;
67const k8s = require ( "@kubernetes/client-node" ) ;
78
@@ -15,37 +16,7 @@ kc.loadFromCluster();
1516const k8sApi = kc . makeApiClient ( k8s . CustomObjectsApi ) ;
1617
1718function downloadFile ( url ) {
18- return fetch ( url )
19- . then ( response => {
20- if ( ! response . ok ) {
21- return response . text ( ) . then ( body => {
22- throw new Error ( `Failed to download file with Response Code: ${ response . status } - ${ body } ` ) ;
23- } ) ;
24- }
25- return response ;
26- } ) ;
27- }
28-
29- function uploadFile ( url , fileContents ) {
30- return fetch ( url , {
31- method : 'PUT' ,
32- headers : { 'Content-Type' : '' } ,
33- body : fileContents
34- } )
35- . then ( response => {
36- if ( ! response . ok ) {
37- return response . text ( ) . then ( body => {
38- console . error ( `File Upload Failed with Response Code: ${ response . status } ` ) ;
39- console . error ( `Error Response Body: ${ body } ` ) ;
40- process . exit ( 1 ) ;
41- } ) ;
42- }
43- // Successful response
44- } )
45- . catch ( error => {
46- console . error ( error . message ) ;
47- process . exit ( 1 ) ;
48- } ) ;
19+ return axios . get ( url ) ;
4920}
5021
5122function getRawResults ( ) {
@@ -64,6 +35,32 @@ function getFindings() {
6435 } ) ;
6536}
6637
38+ function uploadFile ( url , fileContents ) {
39+ return axios
40+ . put ( url , fileContents , {
41+ headers : { "content-type" : "" } ,
42+ } )
43+ . catch ( function ( error ) {
44+ if ( error . response ) {
45+ // The request was made and the server responded with a status code
46+ // that falls out of the range of 2xx
47+ console . error (
48+ `File Upload Failed with Response Code: ${ error . response . status } `
49+ ) ;
50+ console . error ( `Error Response Body: ${ error . response . data } ` ) ;
51+ } else if ( error . request ) {
52+ console . error (
53+ "No response received from FileStorage when uploading finding"
54+ ) ;
55+ console . error ( error ) ;
56+ } else {
57+ // Something happened in setting up the request that triggered an Error
58+ console . log ( "Error" , error . message ) ;
59+ }
60+ process . exit ( 1 ) ;
61+ } ) ;
62+ }
63+
6764function updateRawResults ( fileContents ) {
6865 const rawResultUploadUrl = process . argv [ 4 ] ;
6966 if ( rawResultUploadUrl === undefined ) {
0 commit comments