Skip to content

Commit 7afa44b

Browse files
authored
feat: add install_gitleaks command (#51)
The command to install Gitleaks secrets detection tool. By default, the latest version is installed. Useful for cases when using the machine executor.
1 parent 5128115 commit 7afa44b

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

.circleci/test-deploy.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ jobs:
136136
echo "Failed to install chosen semgrep version"
137137
exit 1
138138
fi
139+
install_gitleaks:
140+
executor: core/node
141+
steps:
142+
- security/install_gitleaks:
143+
version: v8.25.1
144+
- run:
145+
name: Validate installation
146+
command: |
147+
if ! gitleaks --version | grep -q "8.25.1"; then
148+
echo "Failed to install chosen gitleaks version"
149+
exit 1
150+
fi
139151
140152
workflows:
141153
test-deploy:
@@ -186,6 +198,8 @@ workflows:
186198
filters: *filters
187199
- install_semgrep:
188200
filters: *filters
201+
- install_gitleaks:
202+
filters: *filters
189203
- orb-tools/pack:
190204
filters: *release-filters
191205
- orb-tools/publish:
@@ -207,5 +221,6 @@ workflows:
207221
- install_syft
208222
- install_grype
209223
- install_semgrep
224+
- install_gitleaks
210225
context: orb-publishing
211226
filters: *release-filters

src/commands/install_gitleaks.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
description: >
2+
Install Gitleaks (https://github.com/gitleaks/gitleaks) a tool for detecting secrets.
3+
4+
parameters:
5+
version:
6+
type: string
7+
default: ""
8+
description: >
9+
Choose the specific version of Gitleaks from https://github.com/anchore/grype/releases.
10+
By default, the latest version is picked.
11+
12+
steps:
13+
- run:
14+
name: Install Gitleaks
15+
environment:
16+
PARAM_STR_VERSION: <<parameters.version>>
17+
command: <<include(scripts/install-gitleaks.sh)>>

src/scripts/install-gitleaks.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
OS=$(uname | sed 's/Darwin/darwin/;s/Linux/linux/')
4+
ARCH=$(uname -m | sed 's/x86_64/x64/;s/aarch64/arm64/')
5+
GL_DEST_DIR="${GL_DEST_DIR:-/usr/local/bin}"
6+
BASE_URL="https://github.com/gitleaks/gitleaks"
7+
8+
function get_release_url() {
9+
local release_url
10+
local version
11+
12+
if [[ -n "${PARAM_STR_VERSION}" ]]; then
13+
version="${PARAM_STR_VERSION}"
14+
else
15+
version=$(curl -s https://api.github.com/repos/gitleaks/gitleaks/releases/latest | jq -r .tag_name)
16+
fi
17+
18+
release_url="${BASE_URL}/releases/download/${version}/gitleaks_${version#v}_${OS}_${ARCH}.tar.gz"
19+
20+
echo "${release_url}"
21+
}
22+
23+
function install_gitleaks() {
24+
local work_dir
25+
local temp_dir
26+
local release_url
27+
28+
work_dir=$(pwd)
29+
temp_dir=$(mktemp -d 'tmp.XXXXX')
30+
release_url=$(get_release_url)
31+
32+
cd "${temp_dir}" || exit 1
33+
34+
set -x
35+
curl -sfL --retry 1 "${release_url}" | tar zx
36+
sudo install "gitleaks" "${GL_DEST_DIR}"
37+
set +x
38+
39+
echo "Installed $(gitleaks --version) at $(command -v gitleaks)"
40+
41+
cd "${work_dir}" || exit 1
42+
rm -rf "${temp_dir}"
43+
}
44+
45+
if ! command -v gitleaks >/dev/null 2>&1; then
46+
echo "Failed to detect gitleaks, installing..."
47+
48+
install_gitleaks
49+
fi

0 commit comments

Comments
 (0)