Test Failed
Pull Request — master (#3425)
by Anthony
04:54
created

ExecuteActionAliasAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 26
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 19 1
A __init__() 0 5 1
1
import os
2
3
from st2common.runners.base_action import Action
4
from st2client.models.action_alias import ActionAliasMatch, ActionAliasExecution
5
6
from st2client.client import Client
7
8
9
class ExecuteActionAliasAction(Action):
10
    def __init__(self, config=None):
11
        super(ExecuteActionAliasAction, self).__init__(config=config)
12
        api_url = os.environ.get('ST2_ACTION_API_URL', None)
13
        token = os.environ.get('ST2_ACTION_AUTH_TOKEN', None)
14
        self.client = Client(api_url=api_url, token=token)
15
16
    def run(self, text, source_channel=None, user=None):
17
        alias_match = ActionAliasMatch()
18
        alias_match.command = text
19
        alias, representation = self.client.managers['ActionAlias'].match(
20
            alias_match)
21
22
        execution = ActionAliasExecution()
23
        execution.name = alias.name
24
        execution.format = representation
25
        execution.command = text
26
        execution.source_channel = source_channel  # ?
27
        execution.notification_channel = None
28
        execution.notification_route = None
29
        execution.user = user
30
31
        action_exec_mgr = self.app.client.managers['ActionAliasExecution']
32
33
        execution = action_exec_mgr.create(execution)
34
        return execution.execution['id']
35