|
23 | 23 |
|
24 | 24 | class FormatResultAction(Action): |
25 | 25 | def __init__(self, config=None, action_service=None): |
26 | | - super(FormatResultAction, self).__init__(config=config, action_service=action_service) |
27 | | - api_url = os.environ.get('ST2_ACTION_API_URL', None) |
28 | | - token = os.environ.get('ST2_ACTION_AUTH_TOKEN', None) |
| 26 | + super(FormatResultAction, self).__init__( |
| 27 | + config=config, action_service=action_service |
| 28 | + ) |
| 29 | + api_url = os.environ.get("ST2_ACTION_API_URL", None) |
| 30 | + token = os.environ.get("ST2_ACTION_AUTH_TOKEN", None) |
29 | 31 | self.client = Client(api_url=api_url, token=token) |
30 | 32 | self.jinja = jinja_utils.get_jinja_environment(allow_undefined=True) |
31 | | - self.jinja.tests['in'] = lambda item, list: item in list |
| 33 | + self.jinja.tests["in"] = lambda item, list: item in list |
32 | 34 |
|
33 | 35 | path = os.path.dirname(os.path.realpath(__file__)) |
34 | | - with open(os.path.join(path, 'templates/default.j2'), 'r') as f: |
| 36 | + with open(os.path.join(path, "templates/default.j2"), "r") as f: |
35 | 37 | self.default_template = f.read() |
36 | 38 |
|
37 | 39 | def run(self, execution_id): |
38 | 40 | execution = self._get_execution(execution_id) |
39 | | - context = { |
40 | | - 'six': six, |
41 | | - 'execution': execution |
42 | | - } |
| 41 | + context = {"six": six, "execution": execution} |
43 | 42 | template = self.default_template |
44 | 43 | result = {"enabled": True} |
45 | 44 |
|
46 | | - alias_id = execution['context'].get('action_alias_ref', {}).get('id', None) |
| 45 | + alias_id = execution["context"].get("action_alias_ref", {}).get("id", None) |
47 | 46 | if alias_id: |
48 | | - alias = self.client.managers['ActionAlias'].get_by_id(alias_id) |
| 47 | + alias = self.client.managers["ActionAlias"].get_by_id(alias_id) |
49 | 48 |
|
50 | | - context.update({ |
51 | | - 'alias': alias |
52 | | - }) |
| 49 | + context.update({"alias": alias}) |
53 | 50 |
|
54 | | - result_params = getattr(alias, 'result', None) |
| 51 | + result_params = getattr(alias, "result", None) |
55 | 52 | if result_params: |
56 | | - if not result_params.get('enabled', True): |
| 53 | + if not result_params.get("enabled", True): |
57 | 54 | result["enabled"] = False |
58 | 55 | else: |
59 | | - if 'format' in alias.result: |
60 | | - template = alias.result['format'] |
61 | | - if 'extra' in alias.result: |
62 | | - result['extra'] = jinja_utils.render_values(alias.result['extra'], context) |
| 56 | + if "format" in alias.result: |
| 57 | + template = alias.result["format"] |
| 58 | + if "extra" in alias.result: |
| 59 | + result["extra"] = jinja_utils.render_values( |
| 60 | + alias.result["extra"], context |
| 61 | + ) |
63 | 62 |
|
64 | | - result['message'] = self.jinja.from_string(template).render(context) |
| 63 | + result["message"] = self.jinja.from_string(template).render(context) |
65 | 64 |
|
66 | 65 | return result |
67 | 66 |
|
68 | 67 | def _get_execution(self, execution_id): |
69 | 68 | if not execution_id: |
70 | | - raise ValueError('Invalid execution_id provided.') |
| 69 | + raise ValueError("Invalid execution_id provided.") |
71 | 70 | execution = self.client.liveactions.get_by_id(id=execution_id) |
72 | 71 | if not execution: |
73 | 72 | return None |
|
0 commit comments