Skip to content

Commit

Permalink
Fix slice identification (#46)
Browse files Browse the repository at this point in the history
* Minor formatting changes, adding missing loggers.

Signed-off-by: Caroline Russell <[email protected]>

* Fix slice identification when slices are empty, bump version.

Signed-off-by: Caroline Russell <[email protected]>

---------

Signed-off-by: Caroline Russell <[email protected]>
  • Loading branch information
cerrussell authored Apr 8, 2024
1 parent 3fd2456 commit 17d4ab4
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion atom_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
A cli, classes and functions for converting an atom slice to a different format
"""
__version__ = '0.5.2'
__version__ = '0.5.3'
2 changes: 1 addition & 1 deletion atom_tools/cli/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def register_command_loggers(event: Event, event_name: str, _: EventDispatcher)
io = event.io

loggers = []
loggers += command.loggers
loggers += command.loggers # type: ignore

handler = IOHandler(io)
handler.setFormatter(IOFormatter())
Expand Down
3 changes: 0 additions & 3 deletions atom_tools/cli/commands/command.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# pylint: disable-all
from __future__ import annotations

from typing import ClassVar

from cleo.commands.command import Command as BaseCommand


class Command(BaseCommand):
loggers: ClassVar[list[str]] = ['atom_tools.cli.commands.filter']

def handle(self):
pass
3 changes: 2 additions & 1 deletion atom_tools/cli/commands/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class ConvertCommand(Command):
]
help = """The convert command converts an atom slice to a different format.
Currently supports creating an OpenAPI 3.x document based on a usages slice."""
loggers = ['atom_tools.lib.converter', 'atom_tools.lib.regex_utils', 'atom_tools.lib.slices']
loggers = ['atom_tools.lib.converter', 'atom_tools.lib.regex_utils', 'atom_tools.lib.slices',
'atom_tools.lib.utils']

def handle(self):
"""
Expand Down
17 changes: 10 additions & 7 deletions atom_tools/cli/commands/query_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ class QueryEndpointsCommand(Command):
'Only display names; do not include path and line numbers.',
)
]
help = """The query command can be used to return results directly to the console. """
loggers = ['atom_tools.lib.converter', 'atom_tools.lib.regex_utils', 'atom_tools.lib.slices']
help = """The query command can be used to return endpoint results directly to the console. """
loggers = ['atom_tools.lib.converter', 'atom_tools.lib.regex_utils', 'atom_tools.lib.slices',
'atom_tools.lib.utils']

def handle(self):
"""
Expand All @@ -74,8 +75,10 @@ def handle(self):
)
if not (result := converter.endpoints_to_openapi('')):
logging.warning('No results produced!')
line_filter = ()
if self.option('filter-lines'):
line_filter = get_ln_range(self.option('filter-lines'))
output = output_endpoints(result, self.option('sparse'), line_filter)
print(output)
print('')
else:
line_filter = ()
if self.option('filter-lines'):
line_filter = get_ln_range(self.option('filter-lines'))
output = output_endpoints(result, self.option('sparse'), line_filter)
print(output)
7 changes: 6 additions & 1 deletion atom_tools/cli/commands/validate_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
Line validation command for the atom-tools CLI.
"""
import logging
import os
import pathlib
import sys
Expand All @@ -12,6 +13,9 @@
from atom_tools.lib.validator import LineValidator


logger = logging.getLogger(__name__)


class ValidateLinesCommand(Command):
"""
This command handles the conversion of an atom slice to a specified
Expand Down Expand Up @@ -72,7 +76,8 @@ class ValidateLinesCommand(Command):

]
help = """Validate source file line numbers in an atom usages or reachables slice."""
loggers = ['atom_tools.lib.validator', 'atom_tools.lib.regex_utils', 'atom_tools.lib.slices']
loggers = ['atom_tools.lib.validator', 'atom_tools.lib.regex_utils', 'atom_tools.lib.slices',
'atom_tools.lib.utils']

def handle(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions atom_tools/lib/slices.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ def import_slice(filename: str | Path) -> Tuple[Dict, str, str]:
elif 'django' in raw_content:
custom_attr = 'django'
content = json.loads(raw_content)
if content.get('objectSlices'):
if 'objectSlices' in content:
slice_type = 'usages'
if content.get('reachables'):
elif 'reachables' in content:
slice_type = 'reachables'
except (json.decoder.JSONDecodeError, UnicodeDecodeError):
logger.warning(
Expand Down
1 change: 1 addition & 0 deletions atom_tools/lib/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from atom_tools.lib.regex_utils import ValidationRegexCollection
from atom_tools.lib.utils import export_json, remove_duplicates_list


logger = logging.getLogger(__name__)
regex: ValidationRegexCollection = ValidationRegexCollection()
operator_map: Dict[str, List[str]] = {
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "atom-tools"
version = "0.5.2"
version = "0.5.3"
description = "Collection of tools for use with AppThreat/atom."
authors = [
{ name = "Caroline Russell", email = "[email protected]" },
Expand Down

0 comments on commit 17d4ab4

Please sign in to comment.