-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstep.sh
61 lines (52 loc) · 1.41 KB
/
step.sh
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
set -ex
filesize=$(wc ${app_path} | awk '{print $3}')
if [ "$filesize" -gt 524288000 ]
then
echo "File size is bigger than 500MB, exiting..."
exit 1
fi
auth_header="Authorization: Bearer ${appray_api_token}"
jobid=""
upload_response=$(curl -w "%{http_code}" -H "$auth_header" -F "app_file=@${app_path}" -X POST ${base_url}api/v1/jobs)
upload_response=$(echo ${upload_response} | grep "\<202\>" | cut -d\" -f2)
if [ -z "$upload_response" ]
then
echo "Upload error"
echo "Exiting..."
exit 1
else
jobid=$upload_response
fi
jobdone=0
while [ $jobdone -ne 1 ]
do
sleep 30
pending=$(curl -H "$auth_header" ${base_url}api/v1/jobs?status=done | { grep "$jobid" || :; })
if [ -z "$pending" ]
then
jobdone=0
echo "Scan running"
else
jobdone=1
echo "Scanning finished"
fi
done
if [ -z ${result_path} ]
then
echo "result_path was left empty"
echo "Saving results interrupted"
else
echo "Saving results to ${result_path}/app_ray_results.xml"
curl -H "$auth_header" ${base_url}api/v1/jobs/"$jobid"/junit --output "${result_path}"app_ray_result.xml
fi
risk=$(curl -H "$auth_header" ${base_url}api/v1/jobs/"$jobid" | awk '/"risk_score":/{riskscore=$2}END{print riskscore}' | cut -d\, -f1)
envman add --key APP_RAY_RISK_SCORE --value "$risk"
if [ "$risk" -gt "${score_treshold}" ]
then
echo "Analysis risk score is greater than set treshold"
exit 1
else
echo "Analysis risk score is whitin treshold"
fi
exit 0