This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update .githooks from dataworks-github-config
- Loading branch information
1 parent
2fb956f
commit bc7ba49
Showing
1 changed file
with
26 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,44 @@ | ||
#!/bin/bash | ||
|
||
declare -a patterns=( | ||
"\b[A-Z0-9]{20}\b" | ||
"\b[A-Za-z0-9\/+=]{40}\b" | ||
"\b[0-9]{12}\b" | ||
"\b[a-z0-9]{32}\b" | ||
"\b[A-Z]{2}[0-9]{6}[A-Z]{1}\b" | ||
"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b" | ||
"PRIVATE KEY-----" | ||
"\b[A-Za-z0-9._%+-]{1,}@[A-Za-z0-9]{1,}.[A-Za-z0-9]{1,4}.[A-Za-z0-9]{1,4}\b" | ||
"\b.[a-z]{2}-[a-z]{4,9}-[0-9]{1}.\b" | ||
"\b[A-Z0-9]{20}\b" | ||
"\b[A-Za-z0-9\/+=]{40}\b" | ||
"\b[0-9]{12}\b" | ||
"\b[a-z0-9]{32}\b" | ||
"\b[A-Z]{2}[0-9]{6}[A-Z]{1}\b" | ||
"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b" | ||
"PRIVATE KEY-----" | ||
"\b[A-Za-z0-9._%+-]{1,}@[A-Za-z0-9]{1,}.[A-Za-z0-9]{1,4}.[A-Za-z0-9]{1,4}\b" | ||
"\b.[a-z]{2}-[a-z]{4,9}-[0-9]{1}.\b" | ||
) | ||
|
||
declare -a descriptions=( | ||
"AWS access key ID" | ||
"40 character random (e.g. AWS secret access key, PAT)" | ||
"AWS account number" | ||
"16 byte hex (e.g. S3 bucket name)" | ||
"NINO" | ||
"IP address" | ||
"Private key (e.g. rsa private key, openssh private key)" | ||
"Email addresses" | ||
"Regions embedded as part of resource descriptions" | ||
"AWS access key ID" | ||
"40 character random (e.g. AWS secret access key, PAT)" | ||
"AWS account number" | ||
"16 byte hex (e.g. S3 bucket name)" | ||
"NINO" | ||
"IP address" | ||
"Private key (e.g. rsa private key, openssh private key)" | ||
"Email addresses" | ||
"Regions embedded as part of resource descriptions" | ||
) | ||
|
||
count=`ls -1 *.secret 2>/dev/null | wc -l` | ||
if [ count != 0 ]; then | ||
if [ -d ".gitsecret" ]; then | ||
git secret hide | ||
fi | ||
|
||
match=0 | ||
for i in "${!patterns[@]}" | ||
do | ||
git diff-index -p -M --cached HEAD -- | | ||
grep '^+[^+]' | grep -Eq "${patterns[$i]}" && | ||
echo "Blocking commit: ${descriptions[$i]} detected in patch" && | ||
((match++)) | ||
git diff-index -p -M --cached HEAD -- | | ||
grep '^+[^+]' | grep -Eq "${patterns[$i]}" && | ||
echo "Blocking commit: ${descriptions[$i]} detected in patch" && | ||
((match++)) | ||
done | ||
|
||
if (( match > 0 )); then | ||
echo "If the above are false positives then you can use the --no-verify flag to skip checks" | ||
echo "git commit --no-verify" | ||
exit 1 | ||
echo "If the above are false positives then you can use the --no-verify flag to skip checks" | ||
echo "git commit --no-verify" | ||
exit 1 | ||
fi |