File: bdba.sh

package info (click to toggle)
ospray 3.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,048 kB
  • sloc: cpp: 80,569; ansic: 951; sh: 805; makefile: 170; python: 69
file content (61 lines) | stat: -rwxr-xr-x 2,262 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
## Copyright 2019 Intel Corporation
## SPDX-License-Identifier: Apache-2.0

files=$1
jq_tool="$SHARED_TOOLS_PATH/jq-linux64"
logfile="bdba.log"
failed=0
for file_path in $files ; do
    echo -e "\n" >> $logfile
    #upload file
    upload_response=`curl -k -H "Authorization: Bearer $BDBA_TOKEN" -H "Group: $BDBA_GROUP" -T $file_path "$BDBA_SERVER/api/upload/"`
    product_id=`echo "$upload_response" | $jq_tool -r '.results.product_id'`
    if [ $product_id == "null" ]; then
        echo "Cannot upload file $file_path" >> $logfile
        failed=1
        continue
    fi
    report_url=`echo "$upload_response" | $jq_tool -r '.results.report_url'`

    echo "Scan upload of $file_path completed - product id: $product_id ($report_url)" >> $logfile

    set +e
    MAX_RETRY=600

    RETRY_COUNTER="0"
    while [ $RETRY_COUNTER -lt $MAX_RETRY ]; do
        response=`curl -s -X GET -H "Authorization: Bearer $BDBA_TOKEN" -k $BDBA_SERVER/api/product/$product_id/`
        CMD_RETURN_CODE=$?

        status=`echo "$response" | $jq_tool -r '.results.status'`
        verdict=`echo "$response" | $jq_tool -r '.results.summary.verdict.short'`
        if [ $CMD_RETURN_CODE == 0 ] && [[ $status == "R" ]]; then
            echo $response | python -m json.tool
            echo "Verdict: $verdict" >> $logfile
            if [ $verdict != "Pass" ] && [ $verdict != "null" ]; then
                echo "There is a problem - please check report $report_url" >> $logfile
                failed=1
            fi
            # Download pdf report & components list
            file_name=`basename "$file_path"`
            echo "File name: $file_name"
            curl -H "Authorization: Bearer $BDBA_TOKEN" -k $BDBA_SERVER/api/product/$product_id/pdf-report?cvss_version=3 -o ${file_name}_report.pdf
            curl -H "Authorization: Bearer $BDBA_TOKEN" -k $BDBA_SERVER/api/product/$product_id/csv-libs -o ${file_name}_components.csv
            break
        fi
        RETRY_COUNTER=$[$RETRY_COUNTER+1]
        echo "Scan not finished yet, [$RETRY_COUNTER/$MAX_RETRY] - checking again ... "
        sleep 20
    done

    set -e
    if [ $RETRY_COUNTER -ge $MAX_RETRY ]; then
        failed=62
        continue
    fi
done

cat $logfile

exit $failed