Files
donotpassgo/src/security.sh

44 lines
1.0 KiB
Bash
Raw Normal View History

2026-04-03 00:22:36 -04:00
#!/bin/bash
set -eo pipefail
2026-04-03 15:11:33 -04:00
if [[ "$STATIC_FLAG" == "no" && "$VULN_CHECK" == "no" ]]; then
2026-04-03 00:22:36 -04:00
echo "[INFO] no security flags set, skipping!";
exit 0;
fi
2026-04-03 15:33:31 -04:00
toolchain=$(go mod edit -json go.mod | jq -r ".Toolchain");
2026-04-03 15:28:01 -04:00
echo "[DEBUG] $toolchain found in go.mod";
2026-04-03 15:33:31 -04:00
version=$(go env -json | jq -r ".GOVERSION");
2026-04-03 15:28:01 -04:00
echo "[DEBUG] $version found in go env";
2026-04-03 15:11:33 -04:00
if [[ ! -z "$toolchain" ]]; then
version=$toolchain;
fi
2026-04-03 00:22:36 -04:00
if [[ "$STATIC_FLAG" == "yes" ]]; then
2026-04-03 15:11:33 -04:00
if GOTOOLCHAIN=$version gosec ./...; then
2026-04-03 00:22:36 -04:00
echo "[INFO] gosec passed!";
else
if [[ "$STATIC_FAIL" == "yes" ]]; then
echo "[FATAL] gosec failed!";
exit 1;
else
echo "[INFO] gosec failed!";
fi
fi
fi
if [[ "$VULN_CHECK" == "yes" ]]; then
2026-04-03 15:11:33 -04:00
if GOTOOLCHAIN=$version govulncheck ./...; then
2026-04-03 00:22:36 -04:00
echo "[INFO] govulncheck passed!";
else
if [[ "$VULN_FAIL" == "yes" ]]; then
echo "[FATAL] govulncheck failed!"
exit 1;
else
echo "[INFO] govulncheck failed!"
fi
fi
fi