-
Notifications
You must be signed in to change notification settings - Fork 15
Improved command data structure & handler #529
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
Changes from all commits
d897644
1e005c0
dc5777f
c5f4251
2d30deb
0b35c50
14b34ed
cf3bf1c
a81cfa5
d179445
964ad49
48d6df9
fba6c2c
7d4c053
346d4e2
f811a61
fa94194
b7a25ac
dcfe12d
88676cd
5d481a4
e240d03
5a7e6d1
4901d34
9884fee
34d1a32
2ac1c58
f1648e9
d7014ec
d97b807
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,26 +5,16 @@ | |
|
|
||
|
|
||
| def on_start(connection_manager): | ||
| """ | ||
| This will send out an Event signalling the start to the server | ||
| """ | ||
| if not connection_manager.token: | ||
| return | ||
| res = connection_manager.api.report( | ||
| connection_manager.token, | ||
| { | ||
| "type": "started", | ||
| "time": get_unixtime_ms(), | ||
| "agent": connection_manager.get_manager_info(), | ||
| }, | ||
| connection_manager.timeout_in_sec, | ||
| ) | ||
| event = {"type": "started"} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function on_start no longer fails fast when connection_manager.token is missing; the prior early-return was removed, reducing clarity of control flow Details🔧 How do I fix it? More info - Comment |
||
| res = connection_manager.report_api_event(event) | ||
|
|
||
| if not res.get("success", True): | ||
| # Update config time even in failure : | ||
| connection_manager.conf.last_updated_at = get_unixtime_ms() | ||
| logger.error("Failed to communicate with Aikido Server : %s", res["error"]) | ||
| connection_manager.conf.last_updated_at = ( | ||
| get_unixtime_ms() | ||
| ) # Update config time even in failure | ||
| else: | ||
| connection_manager.update_service_config(res) | ||
| connection_manager.update_firewall_lists() | ||
| logger.info("Established connection with Aikido Server") | ||
|
|
||
| return res | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,34 @@ | ||
| """Commands __init__.py file""" | ||
|
|
||
| from aikido_zen.helpers.logging import logger | ||
| from .attack import process_attack | ||
| from aikido_zen.helpers.ipc.command_types import CommandContext | ||
| from .put_event import PutEventCommand | ||
| from .check_firewall_lists import process_check_firewall_lists | ||
| from .read_property import process_read_property | ||
| from .should_ratelimit import process_should_ratelimit | ||
| from .ping import process_ping | ||
| from .sync_data import process_sync_data | ||
|
|
||
| commands_map = { | ||
| # This maps to a tuple : (function, returns_data?) | ||
| # Commands that don't return data : | ||
| "ATTACK": (process_attack, False), | ||
| # Commands that return data : | ||
| "SYNC_DATA": (process_sync_data, True), | ||
| "READ_PROPERTY": (process_read_property, True), | ||
| "SHOULD_RATELIMIT": (process_should_ratelimit, True), | ||
| "PING": (process_ping, True), | ||
| "CHECK_FIREWALL_LISTS": (process_check_firewall_lists, True), | ||
| "SYNC_DATA": process_sync_data, | ||
| "READ_PROPERTY": process_read_property, | ||
| "SHOULD_RATELIMIT": process_should_ratelimit, | ||
| "PING": process_ping, | ||
| "CHECK_FIREWALL_LISTS": process_check_firewall_lists, | ||
| } | ||
|
|
||
| modern_commands = [PutEventCommand] | ||
|
|
||
|
|
||
| def process_incoming_command(connection_manager, obj, conn, queue): | ||
| """Processes an incoming command""" | ||
| action = obj[0] | ||
| data = obj[1] | ||
| if action in commands_map: | ||
| func, returns_data = commands_map[action] | ||
| if returns_data: | ||
| return conn.send(func(connection_manager, data, queue)) | ||
| func(connection_manager, data, queue) | ||
| else: | ||
| logger.debug("Command : `%s` not found, aborting", action) | ||
| inbound_identifier = obj[0] | ||
| inbound_request = obj[1] | ||
| if inbound_identifier in commands_map: | ||
| func = commands_map[inbound_identifier] | ||
| return conn.send(func(connection_manager, inbound_request)) | ||
|
|
||
| for cmd in modern_commands: | ||
| if cmd.identifier() == inbound_identifier: | ||
| cmd.run(CommandContext(connection_manager, queue, conn), inbound_request) | ||
| return None | ||
|
|
||
| logger.debug("Command : `%s` not found - did not execute", inbound_identifier) | ||
| return None |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.