Test Failed
Pull Request — master (#3425)
by Anthony
05:14
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
5
from st2client.models.aliasexecution import ActionAliasExecution
6
7
from st2client.client import Client
8
9
10
class ExecuteActionAliasAction(Action):
11
    def __init__(self, config=None):
12
        super(ExecuteActionAliasAction, self).__init__(config=config)
13
        api_url = os.environ.get('ST2_ACTION_API_URL', None)
14
        token = os.environ.get('ST2_ACTION_AUTH_TOKEN', None)
15
        self.client = Client(api_url=api_url, token=token)
16
17
    def run(self, text, source_channel=None, user=None):
18
        alias_match = ActionAliasMatch()
19
        alias_match.command = text
20
        alias, representation = self.client.managers['ActionAlias'].match(
21
            alias_match)
22
23
        execution = ActionAliasExecution()
24
        execution.name = alias.name
25
        execution.format = representation
26
        execution.command = text
27
        execution.source_channel = source_channel  # ?
28
        execution.notification_channel = None
29
        execution.notification_route = None
30
        execution.user = user
31
32
        action_exec_mgr = self.app.client.managers['ActionAliasExecution']
33
34
        execution = action_exec_mgr.create(execution)
35
        return execution.execution['id']
36