Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit d5a4428

Browse files
committed
update .githooks from dataworks-github-config
1 parent 1a8a579 commit d5a4428

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

.githooks/pre-commit

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
declare -a patterns=(
4+
"\b[A-Z0-9]{20}\b"
5+
"\b[A-Za-z0-9\/+=]{40}\b"
6+
"\b[0-9]{12}\b"
7+
"\b[a-z0-9]{32}\b"
8+
"\b[A-Z]{2}[0-9]{6}[A-Z]{1}\b"
9+
"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b"
10+
"PRIVATE KEY-----"
11+
"\b[A-Za-z0-9._%+-]{1,}@[A-Za-z0-9]{1,}.[A-Za-z0-9]{1,4}.[A-Za-z0-9]{1,4}\b"
12+
"\b.[a-z]{2}-[a-z]{4,9}-[0-9]{1}.\b"
13+
)
14+
15+
declare -a descriptions=(
16+
"AWS access key ID"
17+
"40 character random (e.g. AWS secret access key, PAT)"
18+
"AWS account number"
19+
"16 byte hex (e.g. S3 bucket name)"
20+
"NINO"
21+
"IP address"
22+
"Private key (e.g. rsa private key, openssh private key)"
23+
"Email addresses"
24+
"Regions embedded as part of resource descriptions"
25+
)
26+
27+
if [ -d ".gitsecret" ]; then
28+
git secret hide
29+
fi
30+
31+
match=0
32+
for i in "${!patterns[@]}"
33+
do
34+
git diff-index -p -M --cached HEAD -- |
35+
grep '^+[^+]' | grep -Eq "${patterns[$i]}" &&
36+
echo "Blocking commit: ${descriptions[$i]} detected in patch" &&
37+
((match++))
38+
done
39+
40+
if (( match > 0 )); then
41+
echo "If the above are false positives then you can use the --no-verify flag to skip checks"
42+
echo "git commit --no-verify"
43+
exit 1
44+
fi

0 commit comments

Comments
 (0)