github.com/verrazzano/verrazzano@v1.7.0/release/scripts/generate_upload_file.sh (about) 1 #!/usr/bin/env bash 2 # 3 # Copyright (c) 2022, Oracle and/or its affiliates. 4 # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 5 # 6 7 declare reportName="Daily Scan Results" 8 declare reportType="VZ_DAILY_SCAN" 9 declare reportRelease= 10 declare reportBranch= 11 declare reportTimestamp= 12 declare resultVersion= 13 14 get_timestamp_from_csv_file () { 15 local csv_file="${1}" 16 head -1 ${csv_file} | cut -f4 -d, 17 } 18 19 get_branch_from_csv_file () { 20 local csv_file="${1}" 21 head -1 ${csv_file} | cut -f2 -d, 22 } 23 24 get_release_from_branch_name () { 25 local branch_name="${1}" 26 local url_prefix="https://raw.githubusercontent.com/verrazzano/verrazzano" 27 local version_file=".verrazzano-development-version" 28 curl -s ${url_prefix}/${branch_name}/${version_file} | grep -- "^verrazzano-development-version=" | cut -f2 -d= 29 } 30 31 output_report_prologue () { 32 echo "{" 33 echo " \"reportType\": \"${reportType}\"," 34 echo " \"reportName\": \"${reportName}\"," 35 echo " \"reportRelease\": \"${reportRelease}\"," 36 echo " \"reportBranch\": \"${reportBranch}\"," 37 echo " \"reportTimestamp\": \"${reportTimestamp}\"," 38 echo " \"reportResults\": [" 39 } 40 41 output_report_epilogue () { 42 echo " }" 43 echo " ]" 44 echo "}" 45 } 46 47 output_scan_result () { 48 49 oIFS="$IFS" 50 IFS="," 51 set -- ${1} 52 IFS="${oIFS}" 53 54 if [[ ${_firstLine} = false ]] ; then 55 echo " }," 56 fi 57 58 echo " {" 59 echo " \"vulnerabilityId\" : \"${7}\"," 60 echo " \"vulnerabilitySeverity\" : \"${8}\"," 61 echo " \"reportingScanner\" : \"${6}\"," 62 echo " \"artifactName\" : \"${9%%:*}\"," 63 echo " \"artifactVersion\" : \"${9#*:}\"," 64 echo " \"verrazzanoVersion\" : \"${resultVersion}\"" 65 } 66 67 declare _inputFile="${1}" 68 if [[ -z ${_inputFile} || ! -f ${_inputFile} ]] ; then 69 echo "Input file '${_inputFile}' not found" 70 exit 1 71 fi 72 73 if [[ -n "${2}" ]] ; then 74 reportName="${reportName} (${2})" 75 fi 76 77 reportBranch=$(get_branch_from_csv_file ${_inputFile}) 78 reportRelease=$(get_release_from_branch_name ${reportBranch}) 79 reportTimestamp=$(get_timestamp_from_csv_file ${_inputFile}) 80 resultVersion=$(echo ${reportRelease} | cut -f1,2 -d.) 81 reportRelease=${resultVersion} 82 83 output_report_prologue 84 85 declare _line= 86 declare _firstLine=first 87 cat ${_inputFile} | while read _line 88 do 89 output_scan_result "${_line}" 90 _firstLine=false 91 done 92 93 output_report_epilogue 94