-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Feat/Passing multiple arguments to dir #1750
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
base: master
Are you sure you want to change the base?
Conversation
PR is currently WIP. There is still some testing necessary if the changes have any impact on the core functionalities (e.g. passing config file path, gitleaks-ignore-path etc.) I am happy for any volunteer that reviews the changes and tests Detector functionalities. |
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 is a good base.
I have a few suggestions to streamline the approach a bit. You can apply this with git apply patch.txt
: patch.txt
cmd/directory.go
Outdated
var allFindings []report.Finding | ||
|
||
start := time.Now() | ||
findingsMap := make(map[string]report.Finding) |
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.
What's the purpose of this map? Wouldn't it technically change the behaviour of how things are reported?
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.
From my point of view the behavior itself would not change. The only reason for creating the map is to remove redundant findings by overriding them with the same fingerprint. Otherwise the report would not be accurate anymore when e.g. scanning a root directory with a child directory.
You can test this by scanning the ./testdata
directory with ./testdata/repos/nogit
as additional argument.
cmd/directory.go
Outdated
for _, finding := range findings { | ||
findingsMap[finding.Fingerprint] = finding | ||
} | ||
detector = det |
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 is an unfortunate consequence of configuring report output under Detector
. I don't know if there's a better way.
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.
I see your point. In general, more testing is required from my end as new Detector structs will be initialized for each directory. This basically has an impact on all cli flag that you pass in.
Will think about a better way, ideally there is only one Detector initialized that stores all flags with e.g. absolute paths for config files etc
Can you elaborate? It sounds like the results are the same?
|
Update Test Case 1
Test Case 2
Even with passing a custom toml I haven't noticed any issues with the changes. Since the value of config flag is the only one used to setup the gitleaks config I assume that the changes made within this MR do not have an impact on how the detector is initialized. To-Do Test and adjust the logging while initializing new detectors. You can see e.g. in Output from scanning 2 directories: gitleaks dir testdata/config testdata/repos -c gitleaks-test.toml -l debug
○
│╲
│ ○
○ ░
░ gitleaks
10:38PM DBG using github.com/wasilibs/go-re2 regex engine
10:38PM DBG using gitleaks config gitleaks-test.toml from `--config`
10:38PM DBG found .gitleaksignore file: .gitleaksignore
10:38PM DBG using github.com/wasilibs/go-re2 regex engine
10:38PM DBG using gitleaks config gitleaks-test.toml from `--config`
10:38PM DBG found .gitleaksignore file: .gitleaksignore
10:38PM DBG Skipping symlink path=testdata/repos/symlinks/file_symlink/symlinked_id_ed25519
10:38PM INF scanned ~17007 bytes (17.01 KB) in 52.9ms
10:38PM WRN leaks found: 2
|
@rgmz I have adopted your approach to initialize the config once while iterating over the args (= directories). In addition, I enhanced the logging within the PR is ready for review |
@rgmz is this PR still relevant? |
Does the current state of the pr allows doing If so it's still very relevant to me to be able to fix the
|
@UnknownPlatypus yes the current state allows doing |
@recreator66 Can you resolve the merge conflicts? Thanks! @rgmz Anything else missing here? I really would like to get #1409 fixed, and both this PR as well as #1918 are needed to fix the issue without introducing a major performance regression. |
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.
LGTM, thank you!
logging.Err(scanErr). | ||
Str("path", arg). | ||
Msg("failed scan path") | ||
err = scanErr |
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.
If multiple paths raise an error, only the last one will be kept in err
, correct? If so, I guess it's not a problem because we still have them logged anyway.
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.
Yes, your assumption is correct. Only the last error will be detected and passed to findingSummaryAndExit
.
Anyway, since we log it the output looks like this (without verbose mode)
./gitleaks dir testdata/config123 testdata123 testdata/repos -c .gitleaks-test.toml
○
│╲
│ ○
○ ░
░ gitleaks
9:09PM WRN skipping error="lstat testdata/config123: no such file or directory" path=testdata/config123
9:09PM WRN skipping error="lstat testdata123: no such file or directory" path=testdata123
9:09PM INF scanned ~0 bytes (0) in 27.3ms
9:09PM WRN leaks found: 1
@recreator66 Maybe you can consider using the "Request review" function in the upper right corner to request a review from @rgmz and/or @zricethezav. |
Description:
Closes #1727
Checklist: