Skip to content

Commit

Permalink
Add modular scanners
Browse files Browse the repository at this point in the history
  • Loading branch information
swashko authored and seanpmorgan committed Jan 4, 2024
1 parent 07958d0 commit d756846
Show file tree
Hide file tree
Showing 19 changed files with 641 additions and 410 deletions.
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

0 comments on commit d756846

Please sign in to comment.