-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Added --name-only option #229
Open
pzarfostph
wants to merge
2
commits into
awslabs:master
Choose a base branch
from
pzarfostph:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
# permissions and limitations under the License. | ||
|
||
NONGIT_OK=1 OPTIONS_SPEC="\ | ||
git secrets --scan [-r|--recursive] [--cached] [--no-index] [--untracked] [<files>...] | ||
git secrets --scan [-r|--recursive] [--cached] [--name-only] [--no-index] [--untracked] [<files>...] | ||
git secrets --scan-history | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this also apply to |
||
git secrets --install [-f|--force] [<target-directory>] | ||
git secrets --list [--global] | ||
|
@@ -32,6 +32,7 @@ aws-provider Secret provider that outputs credentials found in an ini file | |
register-aws Adds common AWS patterns to the git config and scans for ~/.aws/credentials | ||
r,recursive --scan scans directories recursively | ||
cached --scan scans searches blobs registered in the index file | ||
name-only --scan shows only file names that contain secrets, not the secrets themselves | ||
no-index --scan searches files in the current directory that is not managed by Git | ||
untracked In addition to searching in the tracked files in the working tree, --scan also in untracked files | ||
f,force --install overwrites hooks if the hook already exists | ||
|
@@ -84,6 +85,7 @@ scan() { | |
local files=("${@}") options="" | ||
[ "${SCAN_CACHED}" == 1 ] && options+="--cached" | ||
[ "${SCAN_UNTRACKED}" == 1 ] && options+=" --untracked" | ||
[ "${SCAN_NAME_ONLY}" == 1 ] && options+=" --name-only" | ||
[ "${SCAN_NO_INDEX}" == 1 ] && options+=" --no-index" | ||
# Scan using git-grep if there are no files or if git options are applied. | ||
if [ ${#files[@]} -eq 0 ] || [ ! -z "${options}" ]; then | ||
|
@@ -205,7 +207,7 @@ install_hook() { | |
echo "#!/usr/bin/env bash" > "${dest}" | ||
echo "git secrets --${cmd} -- \"\$@\"" >> "${dest}" | ||
chmod +x "${dest}" | ||
say "$(tput setaf 2)✓$(tput sgr 0) Installed ${hook} hook to ${dest}" | ||
[[ $(type -P say) ]] && say "$(tput setaf 2)✓$(tput sgr 0) Installed ${hook} hook to ${dest}" | ||
} | ||
|
||
install_all_hooks() { | ||
|
@@ -269,7 +271,7 @@ assert_option_for_command() { | |
} | ||
|
||
declare COMMAND="$1" FORCE=0 RECURSIVE=0 LITERAL=0 GLOBAL=0 ALLOWED=0 | ||
declare SCAN_CACHED=0 SCAN_NO_INDEX=0 SCAN_UNTRACKED=0 | ||
declare SCAN_CACHED=0 SCAN_NAME_ONLY=0 SCAN_NO_INDEX=0 SCAN_UNTRACKED=0 | ||
|
||
# Shift off the command name | ||
shift 1 | ||
|
@@ -295,6 +297,10 @@ while [ "$#" -ne 0 ]; do | |
assert_option_for_command "--scan" "--cached" | ||
SCAN_CACHED=1 | ||
;; | ||
--name-only) | ||
assert_option_for_command "--scan" "--name-only" | ||
SCAN_NAME_ONLY=1 | ||
;; | ||
--no-index) | ||
assert_option_for_command "--scan" "--no-index" | ||
SCAN_NO_INDEX=1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,18 @@ load test_helper | |
[ $status -eq 1 ] | ||
} | ||
|
||
@test "Scans all files displaying file name only - pass" { | ||
setup_good_repo | ||
repo_run git-secrets --scan --name-only | ||
[ $status -eq 0 ] | ||
} | ||
|
||
@test "Scans all files displaying file name only - fail" { | ||
setup_bad_repo | ||
repo_run git-secrets --scan --name-only | ||
[ $status -eq 1 ] | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This or another test should confirm that the output doesn't include the secret |
||
@test "Scans recursively" { | ||
setup_bad_repo | ||
mkdir -p $TEST_REPO/foo/bar/baz | ||
|
@@ -350,6 +362,11 @@ load test_helper | |
[ $status -eq 1 ] | ||
} | ||
|
||
@test "--name-only can only be used with --scan" { | ||
repo_run git-secrets --list --name-only | ||
[ $status -eq 1 ] | ||
} | ||
|
||
@test "--no-index can only be used with --scan" { | ||
repo_run git-secrets --list --no-index | ||
[ $status -eq 1 ] | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also be mentioned at README.rst#synopsis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And an update to README.rst requires
make man
.