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

Avoid init of parsers twice #486

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 0 additions & 7 deletions precli/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from rich.console import Console

import precli
from precli.core import loader
from precli.core.artifact import Artifact
from precli.core.run import Run
from precli.core.tool import Tool
Expand Down Expand Up @@ -328,11 +327,6 @@ def main():
# Compile a list of the targets
artifacts = discover_files(args.targets, args.recursive)

# TODO: Move this to Run
# Flatten into a list of rules for all parsers
parsers = loader.load_parsers()
rules = [r for parser in parsers.values() for r in parser.rules.values()]

if args.gist is True:
file = tempfile.NamedTemporaryFile(mode="w+t")
else:
Expand All @@ -353,7 +347,6 @@ def main():
organization=precli.__author__,
short_description=precli.__summary__,
version=precli.__version__,
rules=rules,
)
run = Run(tool, enabled, disabled, artifacts, console, debug)

Expand Down
7 changes: 7 additions & 0 deletions precli/core/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
from precli.core.metrics import Metrics
from precli.core.result import Result
from precli.core.tool import Tool
from precli.rules import Rule


LOG = logging.getLogger(__name__)
PROGRESS_THRESHOLD = 50
parsers = loader.load_parsers()
rules = [r for parser in parsers.values() for r in parser.rules.values()]


def parse_file(
Expand Down Expand Up @@ -141,6 +143,11 @@ def tool(self) -> Tool:
"""Get the tool associated with this run."""
return self._tool

@property
def rules(self) -> list[Rule]:
"""Set of supported rules."""
return rules

def invoke(self):
"""Invokes a run"""
self._start_time = datetime.datetime.now(datetime.UTC)
Expand Down
10 changes: 0 additions & 10 deletions precli/core/tool.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Copyright 2024 Secure Sauce LLC
from precli.rules import Rule


class Tool:
def __init__(
self,
Expand All @@ -12,7 +9,6 @@ def __init__(
organization: str,
short_description: str,
version: str,
rules: list[Rule],
):
self._name = name
self._download_uri = download_uri
Expand All @@ -21,7 +17,6 @@ def __init__(
self._organization = organization
self._short_description = short_description
self._version = version
self._rules = rules
self._release_date = ""
self._extensions = []
self._policies = []
Expand Down Expand Up @@ -71,11 +66,6 @@ def extensions(self) -> list:
"""Extensions for the tool in use."""
return self._extensions

@property
def rules(self) -> list[Rule]:
"""Set of supported rules."""
return self._rules

@property
def policies(self) -> list:
"""Set of rule configurations."""
Expand Down