Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{CI} Fix file name space when iterating git diffs for secret scan task #30434

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .githooks/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ else
against=$(git hash-object -t tree /dev/null)
fi
has_secrets=0

IFS_OLD=${IFS}
IFS=$'\n'
for FILE in `git diff --cached --name-only --diff-filter=AM $against` ; do
# Check if the file contains secrets
detected=$(azdev scan -f "$FILE" | python -c "import sys, json; print(json.load(sys.stdin)['secrets_detected'])")
Expand All @@ -28,6 +31,7 @@ for FILE in `git diff --cached --name-only --diff-filter=AM $against` ; do
has_secrets=1
fi
done
IFS=${IFS_OLD}

if [ $has_secrets -eq 1 ]; then
printf "\033[0;31mSecret detected. If you want to skip that, run add '--no-verify' in the end of 'git commit' command.\033[0m\n"
Expand Down
4 changes: 4 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1137,13 +1137,17 @@ jobs:
. env/bin/activate
git fetch origin --depth=1 $(System.PullRequest.TargetBranch)
declare -A secret_files
IFS_OLD=${IFS}
IFS=$'\n'
for FILE in `git diff --name-only --diff-filter=AM origin/$(System.PullRequest.TargetBranch)` ; do
echo $FILE
detected=$(azdev scan -f "$FILE" | python -c "import sys, json; print(json.load(sys.stdin)['secrets_detected'])")
if [ $detected == 'True' ]; then
printf "\033[0;31mDetected secrets from %s, You can run 'azdev mask' to remove secrets.\033[0m\n" "$FILE"
secret_files+=$FILE
fi
done
IFS=${IFS_OLD}
if [ "${#secret_files[@]}" -gt 0 ]; then
exit 1
fi
Expand Down