Skip to content

Commit

Permalink
feat: improve handle-secrets function
Browse files Browse the repository at this point in the history
- No longer require popd/pushd and streamline that part
- Make the select more robust against invalid input
  • Loading branch information
Okeanos committed Sep 24, 2024
1 parent af1ec3b commit f016f56
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions stow/shell/.config/bash/functions
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,10 @@ function handle-secrets {
fi

echo "Scanning: ${target_directory}"
pushd "${target_directory}" >/dev/null
if [[ -f .gitleaksignore ]]; then
ignore_file_contents=$(cat .gitleaksignore)
if [[ -f "${target_directory}/.gitleaksignore" ]]; then
ignore_file_contents=$(< "${target_directory}/.gitleaksignore")
fi
gitleaks git --verbose --report-format=json --report-path="${report_file}" --exit-code=0 &>/dev/null
popd >/dev/null
gitleaks git --verbose --report-format=json --report-path="${report_file}" --exit-code=0 "${target_directory}" &>/dev/null

if [[ -f ${report_file} ]]; then
if [[ $(jq length "${report_file}") == 0 ]]; then
Expand All @@ -236,6 +234,7 @@ function handle-secrets {
echo "Commit: ${commit}"
echo "Secret: ${secret}"
select finding_type in "False Positive" "Valid" "Other"; do
[[ -n "${finding_type}" ]] || { echo "Please select a valid option." >&2; continue; }
documented_as="${finding_type}"
break
done
Expand Down

0 comments on commit f016f56

Please sign in to comment.