Skip to content

Commit f185e6b

Browse files
committed
Replace jq with python3 in detect-secrets baseline script
jq is not available in all CI environments (e.g. GitHub Actions), causing the detect-secrets pre-commit hook to fail. Replace jq JSON parsing with equivalent python3 one-liners since Python is always present when detect-secrets runs.
1 parent 3b48b95 commit f185e6b

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

scripts/detect_secrets_baseline.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,18 @@ DETECT_SECRETS_ARGS=(
3232

3333
compare_secrets() {
3434
diff \
35-
<(jq -r '.results | keys[] as $key | "\($key),\(.[$key] | .[] | .hashed_secret)"' "$1" | sort) \
36-
<(jq -r '.results | keys[] as $key | "\($key),\(.[$key] | .[] | .hashed_secret)"' "$2" | sort) \
35+
<(python3 -c "
36+
import json, sys
37+
with open(sys.argv[1]) as f: data = json.load(f)
38+
lines = [f\"{k},{s['hashed_secret']}\" for k, v in data.get('results', {}).items() for s in v]
39+
print('\n'.join(sorted(lines)))
40+
" "$1") \
41+
<(python3 -c "
42+
import json, sys
43+
with open(sys.argv[1]) as f: data = json.load(f)
44+
lines = [f\"{k},{s['hashed_secret']}\" for k, v in data.get('results', {}).items() for s in v]
45+
print('\n'.join(sorted(lines)))
46+
" "$2") \
3747
>/dev/null
3848
}
3949

@@ -45,7 +55,12 @@ elif [ "$1" = "audit" ]; then
4555
detect-secrets audit .secrets.baseline
4656
else
4757
# Check 1: Fail if any secrets in the baseline have not been audited
48-
unaudited=$(jq '[.results[][] | select(has("is_secret") | not)] | length' .secrets.baseline)
58+
unaudited=$(python3 -c "
59+
import json, sys
60+
with open('.secrets.baseline') as f: data = json.load(f)
61+
count = sum(1 for v in data.get('results', {}).values() for s in v if 'is_secret' not in s)
62+
print(count)
63+
")
4964
if [ "$unaudited" -gt 0 ]; then
5065
echo "⚠️ Attention Required! ⚠️" >&2
5166
echo "$unaudited secret(s) in .secrets.baseline have not been audited." >&2

0 commit comments

Comments
 (0)