-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathpre-commit
More file actions
51 lines (42 loc) · 1.22 KB
/
pre-commit
File metadata and controls
51 lines (42 loc) · 1.22 KB
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
46
47
48
49
50
51
#List all staged Python files
files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.py$')
# Run Black for formatting
echo "Running Black for formatting..."
black $files
#————————————————
# Run Flake8 for potential errors, bugs, stylistic issues, and suspicious constructs without actually running the code.
ccho “Running Flake8 for linting……..”
flake8 $files
#————————————————————
# Define patterns to search for secrets
patterns=(
"aws_secret_access_key"
"aws_access_key_id"
"password"
"secret"
"token"
"api_key"
"client_secret"
)
# Function to search for patterns in a file
check_file_for_secrets() {
local file="$1"
for pattern in "${patterns[@]}"; do
if grep -i "$pattern" "$file" > /dev/null; then
echo "Potential security issue detected in file: $file"
echo "Pattern matched: $pattern"
echo "Commit aborted. Remove secrets before committing."
return 1
fi
done
return 0
}
# Check each staged Python file for secrets
for file in $files; do
if ! check_file_for_secrets "$file"; then
exit 1
fi
done
# If all checks pass
echo "No secrets detected. Proceeding with commit."
exit 0