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

Modularize scanners and add results method #66

Merged
merged 1 commit into from
Jan 4, 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: 3 additions & 4 deletions modelscan/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import click

from modelscan.modelscan import Modelscan
from modelscan.modelscan import ModelScan
from modelscan.reports import ConsoleReport
from modelscan._version import __version__

Expand Down Expand Up @@ -61,14 +61,13 @@ def cli(
if log is not None:
logger.setLevel(getattr(logging, log))

modelscan = Modelscan()
modelscan = ModelScan()
if path is not None:
pathlibPath = Path().cwd() if path == "." else Path(path).absolute()
if not pathlibPath.exists():
raise FileNotFoundError(f"Path {path} does not exist")
else:
modelscan.scan_path(pathlibPath)

modelscan.scan(pathlibPath)
else:
raise click.UsageError("Command line must include a path")
ConsoleReport.generate(
Expand Down
23 changes: 21 additions & 2 deletions modelscan/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ class IssueCode(Enum):


class IssueDetails(metaclass=abc.ABCMeta):
def __init__(self, scanner: str = "") -> None:
self.scanner = scanner

@abc.abstractmethod
def output_lines(self) -> List[str]:
raise NotImplemented
raise NotImplementedError

@abc.abstractmethod
def output_json(self) -> Dict[str, str]:
raise NotImplementedError


class Issue:
Expand Down Expand Up @@ -110,13 +117,25 @@ def group_by_severity(self) -> Dict[str, List[Issue]]:


class OperatorIssueDetails(IssueDetails):
def __init__(self, module: str, operator: str, source: Union[Path, str]) -> None:
def __init__(
self, module: str, operator: str, source: Union[Path, str], scanner: str = ""
) -> None:
self.module = module
self.operator = operator
self.source = source
self.scanner = scanner

def output_lines(self) -> List[str]:
return [
f"Description: Use of unsafe operator '{self.operator}' from module '{self.module}'",
f"Source: {str(self.source)}",
]

def output_json(self) -> Dict[str, str]:
return {
"description": f"Use of unsafe operator '{self.operator}' from module '{self.module}'",
"operator": f"{self.operator}",
"module": f"{self.module}",
"source": f"{str(self.source)}",
"scanner": f"{self.scanner}",
}
8 changes: 0 additions & 8 deletions modelscan/models/__init__.py

This file was deleted.

77 changes: 0 additions & 77 deletions modelscan/models/pickle/scan.py

This file was deleted.

25 changes: 0 additions & 25 deletions modelscan/models/scan.py

This file was deleted.

Loading
Loading