-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·48 lines (40 loc) · 1.5 KB
/
Copy pathpre-commit
File metadata and controls
executable file
·48 lines (40 loc) · 1.5 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
#!/bin/bash
# Check if docker is installed
if ! command -v "docker" &> /dev/null
then
echo "Unable to find docker. Is it installed and added to your \$PATH?"
exit 1
fi
# Check if user is logged in to quay.io
DOCKER_REGISTRY=quay.io
docker pull ${DOCKER_REGISTRY}/typeform/gitleaks-config
exit_code=$?
if [ ! $exit_code -eq 0 ]; then
echo "Unable to pull gitleaks container image. Are you logged in ${DOCKER_REGISTRY}?"
exit 1
fi
# If this is being ran as a Github ACtion use $GITHUB_WORKSPACE
if [ -z "$GITHUB_WORKSPACE" ]; then
repo_dir=$PWD
else
repo_dir=$GITHUB_WORKSPACE
fi
repo_name="$(basename "$repo_dir")"
# Generate gitleaks configuration
local_config=".gitleaks.toml"
final_config="/tmp/gitleaks_config.toml"
gitleaks_config_container="${DOCKER_REGISTRY}/typeform/gitleaks-config"
gitleaks_container="${DOCKER_REGISTRY}/typeform/gitleaks"
# Generate the final gitleaks config file. If the repo has a local config, merge both
if [ -f ./"$local_config" ]; then
docker container run --rm -v $repo_dir/$local_config:/app/$local_config \
$gitleaks_config_container python gitleaks_config_generator.py > $final_config
else
docker container run --rm $gitleaks_config_container \
python gitleaks_config_generator.py > $final_config
fi
# Run gitleaks with the generated config
docker container run --rm --name=gitleaks \
-v $final_config:$final_config \
-v $repo_dir:/tmp/$repo_name \
$gitleaks_container --config=$final_config --repo=/tmp/$repo_name --verbose --pretty