Skip to content

Commit 18529aa

Browse files
HackedRicodeacon-mpCopilot
authored
fix(3078, 3079): Resolve issues in Operations API Manager and Plugin Hooks (#3187)
* Pull from PR#3101 * * fix!: Typo * fix!: Conditional to Catch None Attribute Error Running Operations * Planning Services attempts to fcall() and assume all abilities utilizes Builder Plugin and attempts to build payload. * fix!: Caldera Operations Api Manager creates Builder Payloads during Runtime * Conditional required to validate that only abilities utilizing builder plugin is used. * Required encoded_command before building of ability and executor * Update planning_svc.py Added EOF new line to fix linting issue * Update conftest.py no longer able to use event_loop replaced all instances of event_loop with loop * Fixes Flake8 Linter Run Errors * fix: Direct Executer Function Call from Map * Revert "Update conftest.py" This reverts commit 3ecb69c. * fix: additional executor checks * Python Linting Co-authored-by: Copilot <[email protected]> * fix: flake8 linting error due to conditionals * Pull Workflow from Upstream --------- Co-authored-by: deacon-mp <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent a12cab9 commit 18529aa

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

app/api/v2/managers/operation_api_manager.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ async def create_potential_link(self, operation_id: str, data: dict, access: Bas
102102
file_svc=self.services['file_svc']))
103103
executor = self.build_executor(data=data.pop('executor', {}), agent=agent)
104104
ability = self.build_ability(data=data.pop('ability', {}), executor=executor)
105+
await self._call_ability_plugin_hooks(ability, executor)
105106
link = Link.load(dict(command=encoded_command, plaintext_command=encoded_command, paw=agent.paw, ability=ability, executor=executor,
106107
status=operation.link_status(), score=data.get('score', 0), jitter=data.get('jitter', 0),
107108
cleanup=data.get('cleanup', 0), pin=data.get('pin', 0),
@@ -171,6 +172,13 @@ async def _construct_and_dump_source(self, source_id: str):
171172
source = (await self.services['data_svc'].locate('sources', match=dict(name='basic')))
172173
return SourceSchema().dump(source[0])
173174

175+
async def _call_ability_plugin_hooks(self, ability, executor):
176+
"""Calls any plugin hooks (at runtime) that exist for the ability and executor."""
177+
if (hasattr(executor, 'HOOKS') and executor.HOOKS and
178+
hasattr(executor, 'language') and executor.language and
179+
executor.language in executor.HOOKS):
180+
await executor.HOOKS[executor.language](ability, executor)
181+
174182
async def validate_operation_state(self, data: dict, existing: Operation = None):
175183
if not existing:
176184
if data.get('state') in Operation.get_finished_states():

app/service/planning_svc.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,7 @@ async def _generate_new_links(self, operation, agent, abilities, link_status):
351351
executor = await agent.get_preferred_executor(ability)
352352
if not executor:
353353
continue
354-
355-
if executor.HOOKS and executor.language and executor.language in executor.HOOKS:
356-
await executor.HOOKS[executor.language](ability, executor)
354+
await self._call_ability_plugin_hooks(ability, executor)
357355
if executor.command:
358356
link = Link.load(dict(command=self.encode_string(executor.test), paw=agent.paw, score=0,
359357
ability=ability, executor=executor, status=link_status,
@@ -392,6 +390,13 @@ async def _generate_cleanup_links(self, operation, agent, link_status):
392390
links.append(lnk)
393391
return links
394392

393+
async def _call_ability_plugin_hooks(self, ability, executor):
394+
"""Calls any plugin hooks (at runtime) that exist for the ability and executor."""
395+
if (hasattr(executor, 'HOOKS') and executor.HOOKS and
396+
hasattr(executor, 'language') and executor.language and
397+
executor.language in executor.HOOKS):
398+
await executor.HOOKS[executor.language](ability, executor)
399+
395400
@staticmethod
396401
async def _apply_adjustments(operation, links):
397402
"""Apply operation source ability adjustments to links

0 commit comments

Comments
 (0)