Skip to content
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
16 changes: 15 additions & 1 deletion src/attackmate/playbook_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,21 @@ def parse_playbook(playbook_file: str, logger: logging.Logger) -> Playbook:
except OSError:
logger.error(f'Error: Could not open playbook file {target_file}')
exit(1)
except ValidationError:
except ValidationError as e:
logger.error(f'A Validation error occured when parsing playbook file {playbook_file}')
for error in e.errors():
if error['type'] == 'missing':
logger.error(
f'Missing field in {error["loc"][-2]} command: {error["loc"][-1]} - {error["msg"]}'
)
elif error['type'] == 'literal_error':
logger.error(
f'Invalid value in {error["loc"][-2]} command: {error["loc"][-1]} - {error["msg"]}'
)
elif error['type'] == 'value_error':
logger.error(
f'Value error in command {int(error["loc"][-2]) + 1}: '
f'{error["loc"][-1]} - {error["msg"]}'
)
logger.error(traceback.format_exc())
exit(1)
10 changes: 7 additions & 3 deletions src/attackmate/schemas/command_types.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@


from typing import List, TypeAlias, Union
from typing import List, Annotated, TypeAlias, Union
from pydantic import Field
from attackmate.schemas.command_subtypes import RemotelyExecutableCommand
from attackmate.schemas.remote import AttackMateRemoteCommand


Command: TypeAlias = Union[
Command: TypeAlias = Annotated[
Union[
RemotelyExecutableCommand,
AttackMateRemoteCommand
]
],
Field(discriminator='type'),
]


Commands: TypeAlias = List[Command]