2021-10-22 01:28:41 +00:00
|
|
|
#!/usr/bin/env bash
|
2018-04-08 20:55:48 +00:00
|
|
|
|
|
|
|
|
. support/scripts/functions.sh
|
|
|
|
|
|
|
|
|
|
checkfmt() {
|
|
|
|
|
local files="$(gofmt -l $(local_go_pkgs))"
|
|
|
|
|
if [ -n "$files" ]; then
|
|
|
|
|
echo "You need to run \"gofmt -w ./\" to fix your formating."
|
|
|
|
|
echo "$files" >&2
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lint() {
|
2021-10-22 01:28:41 +00:00
|
|
|
golangci-lint run \
|
|
|
|
|
--skip-files=_mock.go \
|
2018-04-19 18:53:12 +00:00
|
|
|
--disable=golint \
|
2021-10-22 01:28:41 +00:00
|
|
|
--skip-dirs=test \
|
2018-04-08 20:55:48 +00:00
|
|
|
--fast \
|
2021-10-22 01:28:41 +00:00
|
|
|
--timeout=600s \
|
|
|
|
|
--verbose \
|
2018-04-08 20:55:48 +00:00
|
|
|
$(local_go_pkgs)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scanast() {
|
|
|
|
|
set +e
|
2021-10-22 01:28:41 +00:00
|
|
|
gosec version
|
2018-08-27 19:23:20 +00:00
|
|
|
gosec ./... > security.log 2>&1
|
2018-04-08 20:55:48 +00:00
|
|
|
set -e
|
|
|
|
|
|
2021-10-22 01:28:41 +00:00
|
|
|
local issues="$(grep -E 'Severity: MEDIUM' security.log | wc -l)"
|
2018-04-08 20:55:48 +00:00
|
|
|
if [ -n $issues ] && [ $issues -gt 0 ]; then
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Medium Severity Issues:"
|
|
|
|
|
grep -E "Severity: MEDIUM" -A 1 security.log
|
|
|
|
|
echo $issues "medium severity issues found."
|
|
|
|
|
fi
|
|
|
|
|
|
2021-10-22 01:28:41 +00:00
|
|
|
local issues="$(grep -E 'Severity: HIGH' security.log | grep -v vendor)"
|
|
|
|
|
local issues_count="$(grep -E 'Severity: HIGH' security.log | grep -v vendor | wc -l)"
|
2018-04-08 20:55:48 +00:00
|
|
|
if [ -n $issues_count ] && [ $issues_count -gt 0 ]; then
|
|
|
|
|
echo ""
|
|
|
|
|
echo "High Severity Issues:"
|
|
|
|
|
grep -E "Severity: HIGH" -A 1 security.log
|
|
|
|
|
echo $issues_count "high severity issues found."
|
|
|
|
|
echo $issues
|
|
|
|
|
echo "You need to resolve the high severity issues at the least."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2021-10-22 01:28:41 +00:00
|
|
|
local issues="$(grep -E 'Errors unhandled' security.log | grep -v vendor | grep -v /src/go/src)"
|
|
|
|
|
local issues_count="$(grep -E 'Errors unhandled' security.log | grep -v vendor | grep -v /src/go/src | wc -l)"
|
2018-04-08 20:55:48 +00:00
|
|
|
if [ -n $issues_count ] && [ $issues_count -gt 0 ]; then
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Unhandled errors:"
|
|
|
|
|
grep -E "Errors unhandled" security.log
|
|
|
|
|
echo $issues_count "unhandled errors, please indicate with the right comment that this case is ok, or handle the error."
|
|
|
|
|
echo $issues
|
|
|
|
|
echo "You need to resolve the all unhandled errors."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
rm security.log
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
|
echo "check.sh fmt|lint" >&2
|
|
|
|
|
exit 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
|
fmt) checkfmt ;;
|
|
|
|
|
lint) lint ;;
|
|
|
|
|
scanast) scanast;;
|
|
|
|
|
*) usage ;;
|
|
|
|
|
esac
|