EasyCV/.github/hooks/pre-commit

55 lines
1.5 KiB
Bash

#!/usr/bin/env bash
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03
# check ak leak
echo "Check for sensitive information leak:"
projectUrl=`git config --get remote.origin.url`
user=`git config --get user.name`
user_email=`git config --get user.email`
STAGE_FILES=$(git diff --cached --name-only)
stage_files=(${STAGE_FILES/ // })
keywords=("LTAI[a-zA-Z0-9]{20}" "LTAI[a-zA-Z0-9]{12}" "acs:ram::[0-9]{16}:role/")
result=0
for i in "${!stage_files[@]}"; do
if [ ! -e "${stage_files[i]}" ]
then
continue
fi
for index in "${!keywords[@]}"; do
grep -E -q ${keywords[index]} ${stage_files[i]}
if [ $? -eq 0 ]
then
echo "Check Failed, ${stage_files[i]} contain sensitive info: pattern=${keywords[index]}, details: "
grep -E ${keywords[index]} ${stage_files[i]}
result=1
break
fi
done
done
if [ $result -eq 0 ];then
echo "Sensitive Information Leak Check Passed."
else
echo "Sensitive Information Leak Check Failed"
exit 1
fi
# start templated
INSTALL_PYTHON=python
ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=pre-commit)
# end templated
HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")
if [ -x "$INSTALL_PYTHON" ]; then
exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}"
elif command -v pre-commit > /dev/null; then
exec pre-commit "${ARGS[@]}"
else
echo '`pre-commit` not found. Did you forget to activate your virtualenv?' 1>&2
exit 1
fi