This repository has been archived by the owner on Apr 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
pre-push
executable file
·136 lines (102 loc) · 4.66 KB
/
pre-push
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
# set against for comparisons
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(git hash-object -t tree /dev/null)
fi
# Check for common data formats #
#################################
if [ -z "${GIT_ALLOW_DATA}" ]; then
REG='.*\.(xls[sxtm]?|csv|txt|sav|db|sqlite|feather|pkl|pickle|ods|gsheet|RData|Rds)'
MATCH=$(git diff --cached --name-only $against | grep -i -P $REG)
if [[ ! -z $MATCH ]]; then
printf "\nIt looks like you're trying to commit a data file':\n\n"
printf "$MATCH\n\n"
printf "Check to ensure that it is ok to commit the file, then run:\n\n\tGIT_ALLOW_DATA=1 git commit"
printf "\n\nYou can stack these commands if required, like:\n\n\tGIT_ALLOW_DATA=1 GIT_ALLOW_OFFICIAL=1 git commit\n\n"
exit 1
fi
fi
# Check for files labelled official #
#####################################
if [ -z "${GIT_ALLOW_OFFICIAL}" ]; then
REG='.*OFFICIAL.*'
MATCH=$(git diff --cached --name-only $against | grep -i -P $REG)
if [[ ! -z $MATCH ]]; then
printf "\nIt looks like you're trying to commit a file which has been\nlabelled 'OFFICIAL':\n\n"
printf "$MATCH\n\n"
printf "Ideally you should rename the file, and remove 'OFFICIAL'.\n"
printf "If you must commit the file without changing the name,\n ensure that the file is OK to commit, then run:\n\n\tGIT_ALLOW_OFFICIAL=1 git commit\n\n"
printf "You can stack these commands if required, like:\n\n\tGIT_ALLOW_DATA=1 GIT_ALLOW_OFFICIAL=1 git commit\n\n"
exit 1
fi
fi
# Check for AWS keys #
######################
if [ -z "${GIT_ALLOW_AWS_KEYS}" ]; then
REG='((?<![A-Z0-9])[A-Z0-9]{20}(?![A-Z0-9])|(?<![A-Za-z0-9/+=])[A-Za-z0-9/+=]{40}(?![A-Za-z0-9/+=]))'
# key match regex from http://blogs.aws.amazon.com/security/blog/tag/key+rotation
MATCH=$(git diff --cached --name-only -z $against | xargs -0 cat | grep -c -P $REG)
if [[ $MATCH -ne 0 ]]; then
printf "Found patterns for AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY in:"
printf "$MATCH\n\n"
printf "Please check your code and remove API keys."
printf "If you really want to commit this:\n\n\tGIT_ALLOW_AWS_KEYS=1 git commit\n"
printf "You can stack these commands if required, like:\n\n\tGIT_ALLOW_DATA=1 GIT_ALLOW_OFFICIAL=1 git commit\n\n"
exit 1
fi
fi
# Check for Private Keys #
##########################
if [ -z "${GIT_ALLOW_PRIVATE_KEYS}" ]; then
REG=' PRIVATE KEY'
# key match regex from http://blogs.aws.amazon.com/security/blog/tag/key+rotation
MATCH=$(git diff --cached --name-only -z $against | xargs -0 cat | grep -c ' PRIVATE KEY')
if [[ $MATCH -ne 0 ]]; then
printf "It looks like you're trying to commit a private key in:"
printf "$MATCH\n\n"
printf "Please check your code and remove any private keys."
printf "If you really want to commit this:\n\n\tGIT_ALLOW_PRIVATE_KEYS=1 git commit\n"
printf "You can stack these commands if required, like:\n\n\tGIT_ALLOW_DATA=1 GIT_ALLOW_OFFICIAL=1 git commit\n\n"
exit 1
fi
fi
# Check for .pem files #
########################
if [ -z "${GIT_ALLOW_PEM_FILES}" ]; then
REG='.*\.pem$'
# key match regex from http://blogs.aws.amazon.com/security/blog/tag/key+rotation
MATCH=$(git diff --cached --name-only $against | grep -P $REG)
if [[ ! -z $MATCH ]]; then
printf "It looks like you're trying to commit a PEM file in:"
printf "$MATCH\n\n"
printf "Please check your code and remove any PEM files."
printf "If you really want to commit this:\n\n\tGIT_ALLOW_PEM_FILES=1 git commit\n"
printf "You can stack these commands if required, like:\n\n\tGIT_ALLOW_DATA=1 GIT_ALLOW_OFFICIAL=1 git commit\n\n"
exit 1
fi
fi
# Check for ipynb formats #
#################################
if [ -z "${GIT_ALLOW_IPYNB}" ]; then
REG='.*\.(ipynb|IPYNB)'
MATCH=$(git diff --cached --name-only $against | grep -i -P $REG)
if [[ ! -z $MATCH ]]; then
printf "\nIt looks like you're trying to commit an ipython notebook':\n\n"
printf "$MATCH\n\n"
printf "Have you checked that no sensitive information is contained in any output chunks?\n"
printf "Check to ensure that it is ok to commit the file, then run:\n\n\tGIT_ALLOW_IPYNB=1 git commit"
printf "\n\nYou can stack these commands if required, like:\n\n\tGIT_ALLOW_DATA=1 GIT_ALLOW_OFFICIAL=1 git commit\n\n"
exit 1
fi
fi
# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et