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

Make -c support ini as well. #944

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions bandit/cli/config_generator.py
Expand Up @@ -153,8 +153,8 @@ def main():

try:
with open(args.output_file, "w") as f:
skips = args.skips.split(",") if args.skips else []
tests = args.tests.split(",") if args.tests else []
skips = args.skips if args.skips else []
tests = args.tests if args.tests else []

for skip in skips:
if not extension_loader.MANAGER.check_id(skip):
Expand Down
4 changes: 2 additions & 2 deletions bandit/cli/main.py
Expand Up @@ -609,8 +609,8 @@ def main():
profile = _get_profile(b_conf, args.profile, args.config_file)
_log_info(args, profile)

profile["include"].update(args.tests.split(",") if args.tests else [])
profile["exclude"].update(args.skips.split(",") if args.skips else [])
profile["include"].update(args.tests if args.tests else [])
profile["exclude"].update(args.skips if args.skips else [])
extension_mgr.validate_profile(profile)

except (utils.ProfileNotFound, ValueError) as e:
Expand Down
17 changes: 11 additions & 6 deletions bandit/core/config.py
Expand Up @@ -58,12 +58,17 @@ def __init__(self, config_file=None):
LOG.error(err)
raise utils.ConfigError("Error parsing file.", config_file)
else:
try:
with f:
self._config = yaml.safe_load(f)
except yaml.YAMLError as err:
LOG.error(err)
raise utils.ConfigError("Error parsing file.", config_file)
self._config = utils.parse_ini_file(config_file)
if not self._config:
try:
with f:
self._config = yaml.safe_load(f)
except yaml.YAMLError as err:
LOG.error(err)
raise utils.ConfigError(
"Error parsing YAML file.",
config_file
)

self.validate(config_file)

Expand Down
5 changes: 4 additions & 1 deletion bandit/core/utils.py
Expand Up @@ -349,7 +349,10 @@ def parse_ini_file(f_loc):
config = configparser.ConfigParser()
try:
config.read(f_loc)
return {k: v for k, v in config.items("bandit")}
d = {k: v for k, v in config.items("bandit")}
for k in ("skips", "tests"):
d[k] = d[k].split(",") if k in d else []
return d

except (configparser.Error, KeyError, TypeError):
LOG.warning(
Expand Down