Skip to content

Commit 691f465

Browse files
bersbersbersericwb
andauthored
Support configfile in .bandit file (#1052)
* Support `(--)config` in `.bandit` file * Use `configfile` instead of `config` --------- Co-authored-by: Eric Brown <[email protected]>
1 parent f1a397e commit 691f465

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

bandit/cli/main.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -450,16 +450,17 @@ def main():
450450
args.confidence = 4
451451
# Other strings will be blocked by argparse
452452

453-
try:
454-
b_conf = b_config.BanditConfig(config_file=args.config_file)
455-
except utils.ConfigError as e:
456-
LOG.error(e)
457-
sys.exit(2)
458-
459453
# Handle .bandit files in projects to pass cmdline args from file
460454
ini_options = _get_options_from_ini(args.ini_path, args.targets)
461455
if ini_options:
462456
# prefer command line, then ini file
457+
args.config_file = _log_option_source(
458+
parser.get_default("configfile"),
459+
args.config_file,
460+
ini_options.get("configfile"),
461+
"config file",
462+
)
463+
463464
args.excluded_paths = _log_option_source(
464465
parser.get_default("excluded_paths"),
465466
args.excluded_paths,
@@ -592,6 +593,12 @@ def main():
592593
"path of a baseline report",
593594
)
594595

596+
try:
597+
b_conf = b_config.BanditConfig(config_file=args.config_file)
598+
except utils.ConfigError as e:
599+
LOG.error(e)
600+
sys.exit(2)
601+
595602
if not args.targets:
596603
parser.print_usage()
597604
sys.exit(2)

0 commit comments

Comments
 (0)