Skip to content

Commit

Permalink
APP-4246 - [Playbook] Removed support for AOT execution
Browse files Browse the repository at this point in the history
  • Loading branch information
bsummers-tc committed Oct 19, 2023
1 parent e05fd64 commit e99de07
Show file tree
Hide file tree
Showing 11 changed files with 4 additions and 229 deletions.
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 4.0.3

- APP-4245 - [Inputs] Added support for secure Redis (SSL and User/Pass)
- APP-4246 - [Playbook] Removed support for AOT execution

## 4.0.2

Expand Down
2 changes: 1 addition & 1 deletion tcex/app/config
38 changes: 0 additions & 38 deletions tcex/exit/exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ def __init__(self, inputs: 'Input'):
self._message = None
self.log = _logger

def _aot_rpush(self, exit_code: int):
"""Push message to AOT action channel."""
if self.inputs.contents.get('tc_playbook_db_type') == 'Redis':
try:
# pylint: disable=no-member
registry.redis_client.rpush(self.inputs.contents['tc_exit_channel'], exit_code)
except Exception as e: # pragma: no cover
self._exit(ExitCode.FAILURE, f'Exception during AOT exit push ({e}).')

def _exit(self, code: ExitCode | int, msg: str) -> NoReturn:
"""Exit the App"""
code = ExitCode(code) if code is not None else self.code
Expand Down Expand Up @@ -140,42 +131,13 @@ def exit(self, code: ExitCode | int | None = None, msg: str | None = None) -> No
if self.ij.model.is_playbook_app:
self.exit_playbook_handler(msg)

# aot notify
if 'tc_aot_enabled' in self.inputs.contents and self.inputs.contents.get('tc_aot_enabled'):
# push exit message
self._aot_rpush(code.value)

# exit token renewal thread
if not self.ij.is_external_app:
registry.token.shutdown = True

# exit
self._exit(code, msg)

# TODO: [med] @cblades - is msg required?
# pylint: disable=unused-argument
def exit_aot_terminate(self, code: ExitCode | int | None = None, msg: str | None = None):
"""Application exit method with proper exit code only for AOT.
The method will run the Python standard sys.exit() with the exit code
previously defined via :py:meth:`~tcex.tcex.TcEx.exit_code` or provided
during the call of this method.
Args:
code: The exit code value for the app.
msg: A message to log and add to message tc output.
"""
code = ExitCode(code) if code is not None else self.code
msg = msg if msg is not None else self.message

# aot notify
if 'tc_aot_enabled' in self.inputs.contents and self.inputs.contents.get('tc_aot_enabled'):
# push exit message
self._aot_rpush(code.value)

self.log.info(f'exit-code={code}')
sys.exit(code)

def _exit_msg_handler(self, code: ExitCode, msg: str):
"""Handle exit message. Write to both log and message_tc."""
if msg is not None:
Expand Down
4 changes: 2 additions & 2 deletions tcex/input/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ def contents_resolved(self) -> dict:

# TODO: [high] - can this be replaced with a pydantic root validator?
def contents_update(self, inputs: dict):
"""Update inputs provided by AOT to be of the proper value and type."""
"""Update inputs provided by core to be of the proper value and type."""
for name, value in inputs.items():
# ThreatConnect AOT params could be updated in the future to proper JSON format.
# ThreatConnect params could be updated in the future to proper JSON format.
# MultiChoice data should be represented as JSON array and Boolean values should be a
# JSON boolean and not a string.
param = self.ij.model.get_param(name)
Expand Down
34 changes: 0 additions & 34 deletions tcex/input/model/aot_execution_enabled_model.py

This file was deleted.

2 changes: 0 additions & 2 deletions tcex/input/model/model_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# first-party
from tcex.input.model.advanced_request_model import AdvancedRequestModel
from tcex.input.model.aot_execution_enabled_model import AotExecutionEnabledModel
from tcex.input.model.app_api_service_model import AppApiServiceModel
from tcex.input.model.app_external_model import AppExternalModel
from tcex.input.model.app_feed_api_service_model import AppFeedApiServiceModel
Expand All @@ -18,7 +17,6 @@

# define feature to model map
feature_map = {
'aotExecutionEnabled': [AotExecutionEnabledModel],
'appBuilderCompliant': [],
# 'advancedRequest': [],
'CALSettings': [CalSettingModel],
Expand Down
1 change: 0 additions & 1 deletion tests/app/config/apps/tcpb/app_1/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ app:
appName: TCPB_-_TcEx_App_1
displayName: TCPB_-_TcEx_App_1
features:
- aotExecutionEnabled
- appBuilderCompliant
- fileParams
- layoutEnabledApp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"appId": "7d1a3338-59ef-59a9-a41e-ae853af5988f",
"displayName": "Playbook App",
"features": [
"aotExecutionEnabled",
"appBuilderCompliant",
"fileParams",
"layoutEnabledApp",
Expand Down
97 changes: 0 additions & 97 deletions tests/app/playbook/test_playbook_aot.py

This file was deleted.

50 changes: 0 additions & 50 deletions tests/input/test_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,17 @@
import os
from collections.abc import Callable
from pathlib import Path
from random import randint
from uuid import uuid4

# third-party
import redis
from _pytest.monkeypatch import MonkeyPatch
from pydantic import BaseModel, Extra

# first-party
from tcex import TcEx
from tcex.input.input import Input
from tcex.registry import registry
from tests.mock_app import MockApp


class TestInputsConfig:
"""Test TcEx Inputs Config."""

@staticmethod
def test_aot_inputs(
playbook_app: Callable[..., MockApp], redis_client: redis.Redis, monkeypatch: MonkeyPatch
):
"""Test AOT input method of TcEx"""
registry._reset()

class PytestModel(BaseModel):
"""Test Model for Inputs"""

my_bool: bool
my_multi: list

class Config:
"""."""

extra = Extra.allow

# add AOT setting to App
config_data = {
'tc_action_channel': f'pytest-action-channel-{randint(1000,9999)}',
'tc_aot_enabled': True,
}
app = playbook_app(config_data=config_data)

# ensure inputs object has same FakeRedis instance as the one we will push data to
monkeypatch.setattr(Input, '_get_redis_client', lambda *args, **kwargs: redis_client)

# send redis rpush AOT message
aot_config_data = {'my_bool': 'true', 'my_multi': 'one|two'}
aot_config_data.update(app.config_data)
aot_msg = {'type': 'execute', 'params': aot_config_data}
redis_client.rpush(config_data['tc_action_channel'], json.dumps(aot_msg))

# get a configured instance of tcex, missing AOT values
# tcex will block, check for the AOT method, parse new config, and then run
tcex = app.tcex
tcex.inputs.add_model(PytestModel) # type: ignore

# print(tcex.inputs.model.json(indent=2))
assert tcex.inputs.model.my_bool is True # type: ignore
assert tcex.inputs.model.my_multi == ['one', 'two'] # type: ignore

@staticmethod
def test_config_kwarg():
"""Test config file input method of TcEx"""
Expand Down
3 changes: 0 additions & 3 deletions tests/mock_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ def _config_common(self) -> dict[str, bool | str | None]:
def _config_playbook(self) -> dict[str, bool | int | str]:
"""Return config data for mocked App."""
return {
'tc_action_channel': 'action-channel',
'tc_aot_enabled': False,
'tc_exit_channel': 'exit-channel',
'tc_terminate_seconds': 30,
}
Expand Down Expand Up @@ -136,7 +134,6 @@ def _ij_common(self) -> dict[str, Any]:
'displayName': self.ijd.get('display_name') or 'Pytest',
'features': self.ijd.get('features', [])
or [
'aotExecutionEnabled',
'appBuilderCompliant',
'layoutEnabledApp',
'fileParams',
Expand Down

0 comments on commit e99de07

Please sign in to comment.