-
Notifications
You must be signed in to change notification settings - Fork 8
integration of attackmate in external projects #144
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
Merged
whotwagner
merged 24 commits into
ait-testbed:development
from
thorinaboenke:112_return_result_in_run_method
Feb 7, 2025
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
ea7c61f
add function to run single command
thorinaboenke 8f98e30
let exec_background always return None Result
thorinaboenke 937fbf8
refactor for conciseness
thorinaboenke 5330ca0
baseexecutor run returns result
thorinaboenke d4ca63c
provide default playbook and config
thorinaboenke baefa33
command registry
thorinaboenke f43fb1b
register commands
thorinaboenke 4408ac7
import Commands type from playbook.py
thorinaboenke a31fe6a
define commands in loop to avoind circular import
thorinaboenke 8f84209
pass varstore dict as parameter to AttackMate
thorinaboenke c0fa251
return output of debug command
thorinaboenke 5e65fc2
use BaseCommand Type for Command registry to avoid circular imports
thorinaboenke 2e7067f
add repr method to Result
thorinaboenke 607c2bc
Merge branch 'development' into 112_return_result_in_run_method
thorinaboenke 8d32bdc
remove comment
thorinaboenke efdeb85
Update metadata.py
whotwagner 328249b
Update conf.py
whotwagner f01b162
Update conf.py
whotwagner 30d88af
Update metadata.py
whotwagner c41a903
Update README.md
skopikf dc424d3
Update README.md
skopikf 7939c8d
Update README.md
skopikf 7628942
add clarification which commands set RESULT_STDOUT
thorinaboenke 52e6e77
typo
thorinaboenke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| from typing import Dict, Tuple, Optional | ||
| from attackmate.schemas.base import BaseCommand | ||
|
|
||
|
|
||
| class CommandRegistry: | ||
| _type_registry: Dict[str, BaseCommand] = {} | ||
| _type_cmd_registry: Dict[Tuple[str, str], BaseCommand] = {} | ||
|
|
||
| @classmethod | ||
| def register(cls, type_: str, cmd: Optional[str] = None): | ||
| """register a command class by type or type + cmd.""" | ||
|
|
||
| def decorator(command_class: BaseCommand): | ||
| if cmd: | ||
| cls._type_cmd_registry[(type_, cmd)] = command_class | ||
| else: | ||
| cls._type_registry[type_] = command_class | ||
| return command_class | ||
|
|
||
| return decorator | ||
|
|
||
| @classmethod | ||
| def get_command_class(cls, type_: str, cmd: Optional[str] = None): | ||
| """Retrieve the command class based on type or type + cmd.""" | ||
| if cmd and (type_, cmd) in cls._type_cmd_registry: | ||
| return cls._type_cmd_registry[(type_, cmd)] | ||
| if type_ in cls._type_registry: | ||
| return cls._type_registry[type_] | ||
| raise ValueError(f"No command registered for type '{type_}' and cmd '{cmd}'") | ||
|
|
||
|
|
||
| # Command interface | ||
| class Command: | ||
| @staticmethod | ||
| def create(type: str, cmd: Optional[str] = None, **kwargs): | ||
| """return a command instance based on type and cmd.""" | ||
| CommandClass = CommandRegistry.get_command_class(type, cmd) | ||
| return CommandClass(type=type, cmd=cmd, **kwargs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.