Skip to content
Snippets Groups Projects

Adding a small pre-commit script to check out a presence of secrets using...

Merged Francisco Perez requested to merge a_small_pre-commit-script_to_check_out_secrets into main
1 file
+ 36
0
Compare changes
  • Side-by-side
  • Inline
+ 36
0
 
#!/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
Loading