github.com/vmware/go-vcloud-director/v2@v2.24.0/scripts/gosec.sh (about) 1 #!/usr/bin/env bash 2 scripts_dir=$(dirname $0) 3 cd $scripts_dir 4 scripts_dir=$PWD 5 cd - > /dev/null 6 7 sc_exit_code=0 8 9 if [ ! -d ./govcd ] 10 then 11 echo "source directory ./govcd not found" 12 exit 1 13 fi 14 15 if [ ! -f ./scripts/gosec-config.sh ] 16 then 17 echo "file ./scripts/gosec-config.sh not found" 18 exit 1 19 fi 20 21 source ./scripts/gosec-config.sh 22 23 function exists_in_path { 24 what=$1 25 for dir in $(echo $PATH | tr ':' ' ') 26 do 27 wanted=$dir/$what 28 if [ -x $wanted ] 29 then 30 echo $wanted 31 return 32 fi 33 done 34 } 35 36 function get_gosec { 37 gosec=$(exists_in_path gosec) 38 if [ -z "$gosec" -a -n "$GITHUB_ACTIONS" ] 39 then 40 curl=$(exists_in_path curl) 41 if [ -z "$curl" ] 42 then 43 echo "'curl' executable not found - Skipping gosec" 44 exit 0 45 fi 46 $curl -sfL $GOSEC_URL > gosec_install.sh 47 exit_code=$? 48 if [ "$exit_code" != "0" ] 49 then 50 echo "Error downloading gosec installer" 51 exit $exit_code 52 fi 53 sh -x gosec_install.sh $GOSEC_VERSION > gosec_install.log 2>&1 54 exit_code=$? 55 if [ "$exit_code" != "0" ] 56 then 57 echo "Error installing gosec" 58 cat gosec_install.log 59 exit $exit_code 60 fi 61 gosec=$PWD/bin/gosec 62 fi 63 if [ -n "$gosec" ] 64 then 65 echo "## Found $gosec" 66 echo -n "## " 67 $gosec -version 68 else 69 echo "*** gosec executable not found - Exiting" 70 exit 0 71 fi 72 } 73 74 function run_gosec { 75 if [ -n "$gosec" ] 76 then 77 $gosec -tests -tags ALL ./... 78 exit_code=$? 79 if [ "$exit_code" != "0" ] 80 then 81 sc_exit_code=$exit_code 82 fi 83 fi 84 echo "" 85 } 86 87 get_gosec 88 echo "" 89 90 run_gosec 91 echo "Exit code: $sc_exit_code" 92 exit $sc_exit_code 93