forked from alibaba/EasyRec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
executable file
·45 lines (40 loc) · 1.12 KB
/
pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
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
exit 1
fi
python git-lfs/git_lfs.py push
pwd
gt_py36=`python --version 2>&1 | awk '{ print ($2 >= 3.6) }'`
if [ $gt_py36 -eq 1 ]
then
pip install pre-commit
pre-commit run -a
else
echo "[WARNING] pre-commit is not supported, please use python >= 3.6"
fi