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

Updated 'inherits_from' to correct new format. Pin flake8 to less than version 5. Update to tool plugins to match new structure [sscpac/statick#423]. #25

Merged
merged 7 commits into from
Oct 10, 2022
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### Added
## Changed

- Updated tool plugins to match new structure introduced in sscpac/statick#423.
- Update `inherits_from` usage in configuration file to match new list format.

### Fixed

### Removed
- Pin flake8<5 and pycodestyle<2.9.0 until <https://github.com/tholo/pytest-flake8/issues/87> is fixed.

## v0.1.0 - 2022-01-04

Expand Down
3 changes: 2 additions & 1 deletion rsc/tooling-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ levels:
flags: ""

tooling_with_pylint:
inherits_from: "tooling"
inherits_from:
- "tooling"
discovery:
python:
flags: ""
Expand Down
24 changes: 11 additions & 13 deletions src/statick_tooling/plugins/tool/dockerfile_lint_tool_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ def get_name(self) -> str:
"""Get name of tool."""
return "dockerfile-lint"

def get_file_types(self) -> List[str]:
"""Return a list of file types the plugin can scan."""
return ["dockerfile_src"]

# pylint: disable=too-many-locals
def scan(self, package: Package, level: str) -> Optional[List[Issue]]:
def process_files(
self, package: Package, level: str, files: List[str], user_flags: List[str]
) -> Optional[List[str]]:
"""Run tool and gather output."""
tool_bin = "dockerfile_lint"

Expand All @@ -34,13 +40,8 @@ def scan(self, package: Package, level: str) -> Optional[List[Issue]]:
if format_file_name is not None:
flags += ["-r", format_file_name]
flags += ["--json"]
user_flags = self.get_user_flags(level)
flags += user_flags

files: List[str] = []
if "dockerfile_src" in package:
files += package["dockerfile_src"]

total_output: List[str] = []

for src in files:
Expand Down Expand Up @@ -69,12 +70,7 @@ def scan(self, package: Package, level: str) -> Optional[List[Issue]]:
for output in total_output:
logging.debug("%s", output)

with open(self.get_name() + ".log", "w", encoding="utf8") as fid:
for output in total_output:
fid.write(output)

issues: List[Issue] = self.parse_output(total_output)
return issues
return total_output

# pylint: enable=too-many-locals

Expand All @@ -92,7 +88,9 @@ def add_filename(cls, output: str, src: str) -> str:
logging.warning("ValueError: %s", ex)
return output

def parse_output(self, total_output: List[str]) -> List[Issue]:
def parse_output(
self, total_output: List[str], package: Optional[Package] = None
) -> List[Issue]:
"""Parse tool output and report issues."""
issues: List[Issue] = []

Expand Down
24 changes: 11 additions & 13 deletions src/statick_tooling/plugins/tool/dockerfilelint_tool_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ def get_name(self) -> str:
"""Get name of tool."""
return "dockerfilelint"

def get_file_types(self) -> List[str]:
"""Return a list of file types the plugin can scan."""
return ["dockerfile_src"]

# pylint: disable=too-many-locals
def scan(self, package: Package, level: str) -> Optional[List[Issue]]:
def process_files(
self, package: Package, level: str, files: List[str], user_flags: List[str]
) -> Optional[List[str]]:
"""Run tool and gather output."""
tool_bin = "dockerfilelint"

Expand All @@ -36,13 +42,8 @@ def scan(self, package: Package, level: str) -> Optional[List[Issue]]:
if format_file_name is not None:
flags += ["-c", str(format_file_path)]
flags += ["-o", "json"]
user_flags = self.get_user_flags(level)
flags += user_flags

files: List[str] = []
if "dockerfile_src" in package:
files += package["dockerfile_src"]

total_output: List[str] = []

for src in files:
Expand Down Expand Up @@ -71,16 +72,13 @@ def scan(self, package: Package, level: str) -> Optional[List[Issue]]:
for output in total_output:
logging.debug("%s", output)

with open(self.get_name() + ".log", "w", encoding="utf8") as fid:
for output in total_output:
fid.write(output)

issues: List[Issue] = self.parse_output(total_output)
return issues
return total_output

# pylint: enable=too-many-locals

def parse_output(self, total_output: List[str]) -> List[Issue]:
def parse_output(
self, total_output: List[str], package: Optional[Package] = None
) -> List[Issue]:
"""Parse tool output and report issues."""
issues: List[Issue] = []

Expand Down
24 changes: 11 additions & 13 deletions src/statick_tooling/plugins/tool/hadolint_tool_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ def gather_args(self, args: argparse.Namespace) -> None:
help="Use hadolint docker image instead of binary",
)

def get_file_types(self) -> List[str]:
"""Return a list of file types the plugin can scan."""
return ["dockerfile_src"]

# pylint: disable=too-many-locals
def scan(self, package: Package, level: str) -> Optional[List[Issue]]:
def process_files(
self, package: Package, level: str, files: List[str], user_flags: List[str]
) -> Optional[List[str]]:
"""Run tool and gather output."""
tool_bin = "hadolint"

Expand All @@ -51,7 +57,6 @@ def scan(self, package: Package, level: str) -> Optional[List[Issue]]:

config_file_path = self.plugin_context.resources.get_file(tool_config)
flags: List[str] = ["-f", "json", "--no-fail"]
user_flags = self.get_user_flags(level)
if "-f" in user_flags:
idx = user_flags.index("-f")
logging.warning(
Expand All @@ -63,10 +68,6 @@ def scan(self, package: Package, level: str) -> Optional[List[Issue]]:
user_flags.pop(idx)
flags += user_flags

files: List[str] = []
if "dockerfile_src" in package:
files += package["dockerfile_src"]

total_output: List[str] = []
if (
self.plugin_context
Expand All @@ -87,12 +88,7 @@ def scan(self, package: Package, level: str) -> Optional[List[Issue]]:
for output in total_output:
logging.debug("%s", output)

with open(self.get_name() + ".log", "w", encoding="utf8") as fid:
for output in total_output:
fid.write(output)

issues: List[Issue] = self.parse_output(total_output)
return issues
return total_output

# pylint: enable=too-many-locals

Expand Down Expand Up @@ -172,7 +168,9 @@ def scan_docker(
logging.warning("Couldn't find %s! (%s)", tool_bin, ex)
return None

def parse_output(self, total_output: List[str]) -> List[Issue]:
def parse_output(
self, total_output: List[str], package: Optional[Package] = None
) -> List[Issue]:
"""Parse tool output and report issues."""
issues: List[Issue] = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def setup_dockerfilelint_tool_plugin():
)
config = Config(resources.get_file("config.yaml"))
plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
plugin_context.args.output_directory = os.path.dirname(__file__)
plugin = DockerfileULintToolPlugin()
plugin.set_plugin_context(plugin_context)
return plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def setup_dockerfilelint_tool_plugin(package="valid_package"):
)
config = Config(resources.get_file("config.yaml"))
plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
plugin_context.args.output_directory = os.path.dirname(__file__)
plugin = DockerfileLintToolPlugin()
plugin.set_plugin_context(plugin_context)
return plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def setup_hadolint_tool_plugin(
)
config = Config(resources.get_file("config.yaml"))
plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
plugin_context.args.output_directory = os.path.dirname(__file__)
plugin = HadolintToolPlugin()
if binary:
plugin_context.args.hadolint_bin = binary
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ passenv = CI
setenv = PY_IGNORE_IMPORTMISMATCH = 1
deps =
codecov
flake8<5 # Pin until https://github.com/tholo/pytest-flake8/issues/87 is fixed.
flake8-pep3101
pycodestyle
pycodestyle<2.9.0 # Pin until https://github.com/tholo/pytest-flake8/issues/87 is fixed.
pydocstyle
pytest
pytest-cov
Expand Down