Test Failed
Pull Request — master (#3425)
by Anthony
05:14
created

_format_match()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
1
import os
2
3
from st2common.runners.base_action import Action
4
from st2client.models.action_alias import ActionAliasMatch
5
from st2client.client import Client
6
7
8
class MatchAction(Action):
9
    def __init__(self, config=None):
10
        super(MatchAction, self).__init__(config=config)
11
        api_url = os.environ.get('ST2_ACTION_API_URL', None)
12
        token = os.environ.get('ST2_ACTION_AUTH_TOKEN', None)
13
        self.client = Client(api_url=api_url, token=token)
14
15
    def run(self, text):
16
        alias_match = ActionAliasMatch()
17
        alias_match.command = text
18
        matches = self.client.managers['ActionAlias'].match(alias_match)
19
        return {
20
            'alias': _format_match(matches[0]),
21
            'representation': matches[1]
22
        }
23
24
25
def _format_match(match):
26
        return {
27
            'name': match.name,
28
            'pack': match.pack,
29
            'action_ref': match.action_ref
30
        }
31