diff --git a/git_hooks/pre-commit b/git_hooks/pre-commit new file mode 100755 index 0000000000000000000000000000000000000000..6c25fe34c294c862a41390cce870a3b17fd43b0b --- /dev/null +++ b/git_hooks/pre-commit @@ -0,0 +1,36 @@ +#!/bin/sh + +### This is a small pre-commit script that checks for the presence of secrets using ggshield. +### If ggshield is not installed, it will run a custom list of grep expressions to perform the secret check + +set -ep + +# Function to check if a command is available +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# Check if ggshield is installed +if command_exists ggshield; then + # Run ggshield to scan for sensitive information + ggshield secret scan pre-commit "$@" +else + # Display a warning if ggshield is not installed + echo "WARNING: ggshield is not installed." + echo + echo "INFO: Please consider to installing by following the steps below:" + echo "pip install --user -U ggshield" + echo "ggshield auth login" + echo + echo "INFO: Running a custom lit of grep to check for common passwords patterns." + # Run grep to search for potential passwords (modify this command as needed) + if grep -r -I -E '(?:ghp|gho|ghu|ghs|ghr)_[0-9a-zA-Z]{36,}' . >/dev/null; then + echo "WARNING: Potential Github passwords found. Commit blocked." + exit 1 + fi +fi + +# If everything is fine, allow the commit to proceed +echo +echo "INFO: No issues found out" +exit 0 \ No newline at end of file