2026-09-13 17:51:28 +02:00
|
|
|
#!/bin/sh
|
2026-10-02 21:57:42 +02:00
|
|
|
# OpenUltraSAST pre-push safety net. Advisory: nothing here rejects a push unless
|
|
|
|
|
# OUSAST_PUSH_MODE=blocking is set explicitly. Install with `ousast pre-push install`
|
|
|
|
|
# (or ops/install-pre-push from a checkout); remove with `ousast pre-push uninstall`.
|
|
|
|
|
# A prior hook is chained only after it was moved to the sibling path "$0.before-ousast".
|
2026-09-13 17:51:28 +02:00
|
|
|
artifact_dir=${OUSAST_ARTIFACT_DIR:-${XDG_CACHE_HOME:-$HOME/.cache}/openultrasast/push}
|
|
|
|
|
prior="$0.before-ousast"
|
2026-10-02 22:51:22 +02:00
|
|
|
# The Docker wrapper installed beside this hook (`ousast pre-push install --docker`) is used
|
|
|
|
|
# unless OUSAST_COMMAND names another command; otherwise `ousast` from PATH.
|
|
|
|
|
if [ -z "${OUSAST_COMMAND:-}" ] && [ -x "$(dirname -- "$0")/ousast-docker" ]; then
|
|
|
|
|
OUSAST_COMMAND="$(dirname -- "$0")/ousast-docker"
|
|
|
|
|
fi
|
2026-10-02 21:57:42 +02:00
|
|
|
command=${OUSAST_COMMAND:-ousast}
|
|
|
|
|
if ! command -v "$command" >/dev/null 2>&1; then
|
|
|
|
|
echo "ousast: pre-push check did not run: '$command' is not on PATH." \
|
2026-10-02 23:02:32 +02:00
|
|
|
"Install it (pip install git+https://github.com/norandom/OpenUltraSAST) or set OUSAST_COMMAND. Push continues."
|
2026-10-02 21:57:42 +02:00
|
|
|
if [ -e "$prior" ] || [ -L "$prior" ]; then
|
|
|
|
|
exec "$prior" "$@"
|
|
|
|
|
fi
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
2026-10-02 22:10:33 +02:00
|
|
|
remote_name=$1
|
|
|
|
|
remote_url=$2
|
|
|
|
|
set -- pre-push . --artifact "$artifact_dir/push-$$.json" \
|
2026-09-13 17:51:28 +02:00
|
|
|
--deadline "${OUSAST_PUSH_DEADLINE:-30}" \
|
|
|
|
|
--mode "${OUSAST_PUSH_MODE:-advisory}" \
|
2026-10-02 22:51:22 +02:00
|
|
|
--incomplete-coverage "${OUSAST_INCOMPLETE_COVERAGE:-allow}"
|
|
|
|
|
# Optional settings are passed only when set, so an older ousast (or image) still runs.
|
|
|
|
|
if [ -n "${OUSAST_PUSH_ENGINE:-}" ]; then
|
|
|
|
|
set -- "$@" --engine "$OUSAST_PUSH_ENGINE"
|
|
|
|
|
fi
|
2026-10-02 22:10:33 +02:00
|
|
|
if [ -n "${OUSAST_COMPARISON_BASE:-}" ]; then
|
|
|
|
|
set -- "$@" --comparison-base "$OUSAST_COMPARISON_BASE"
|
|
|
|
|
fi
|
|
|
|
|
if [ -e "$prior" ] || [ -L "$prior" ]; then
|
|
|
|
|
set -- "$@" --prior-hook "$prior"
|
|
|
|
|
fi
|
|
|
|
|
exec "$command" "$@" --remote "$remote_name" "$remote_url"
|