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

Support configfile in .bandit file #44

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions flake8_bandit.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


class Flake8BanditConfig(NamedTuple):
config_file: str
profile: Dict
target_paths: Set
excluded_paths: Set
Expand All @@ -27,6 +28,7 @@ class Flake8BanditConfig(NamedTuple):
@lru_cache(maxsize=32)
def from_config_file(cls) -> "Flake8BanditConfig":
# set defaults
config_file = ""
profile = {}
target_paths = set()
excluded_paths = set()
Expand All @@ -37,6 +39,7 @@ def from_config_file(cls) -> "Flake8BanditConfig":
bandit_config = {k: v for k, v in cfg["bandit"].items()}

# test-set profile
config_file = bandit_config.get("configfile", "")
if bandit_config.get("skips"):
profile["exclude"] = (
bandit_config.get("skips").replace("S", "B").split(",")
Expand Down Expand Up @@ -66,7 +69,7 @@ def from_config_file(cls) -> "Flake8BanditConfig":
except (ExecutionError, KeyError, TypeError) as e:
profile = {}

return cls(profile, target_paths, excluded_paths)
return cls(config_file, profile, target_paths, excluded_paths)


class BanditTester(object):
Expand Down Expand Up @@ -106,7 +109,7 @@ def _check_source(self):
fname=self.filename,
fdata=None,
metaast=BanditMetaAst(),
testset=BanditTestSet(BanditConfig(), profile=config.profile),
testset=BanditTestSet(BanditConfig(config.config_file), profile=config.profile),
debug=False,
nosec_lines={},
metrics=Metrics(),
Expand All @@ -116,7 +119,7 @@ def _check_source(self):
bnv = BanditNodeVisitor(
fname=self.filename,
metaast=BanditMetaAst(),
testset=BanditTestSet(BanditConfig(), profile=config.profile),
testset=BanditTestSet(BanditConfig(config.config_file), profile=config.profile),
debug=False,
nosec_lines=[],
metrics=Metrics(),
Expand Down