fix reading initial values from .bandit #722
Merged
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.
How to fix reading .bandit initial values:
Previously bandit was not able to read initialization values from the .bandit file
like the
exclude
keyword. This has caused a lot of CI pipelines that were usingbandit to fail. In this pull, I have tried to fix this problem.
What was the main problem that was causing this bug?
The CLI of bandit is written with python's popular library
argparse
.The main problem was with the handling of default arguments' values
of the bandit command-line program. The program was not able to
distinguish between manually passed arguments and default arguments
values. Before In the first line of
_log_option_source
function inbandit.cli.main.py
, the function only checked whetherarg_val
existsor not. At first glance, it seems that this is a correct action, but the truth is
that this function fails when the default value of an argument is a string
like
--exclude
. When we didn't pass an argument to--exclude
, the valueof
arg_val
would be equal to default value of the argument and passedthe
if
condition and will neglect the initial value in the .bandit file.Resolves: #499, #595