Completed
Pull Request — master (#2895)
by Anthony
05:47
created

ActionAlias.match()   A

Complexity

Conditions 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
1
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
16
from six.moves.urllib.parse import urlencode
17
18
from st2client.models import core
19
20
__all__ = [
21
    'ActionAlias'
22
]
23
24
25
class ActionAlias(core.Resource):
26
    _alias = 'Action-Alias'
27
    _display_name = 'Action Alias'
28
    _plural = 'ActionAliases'
29
    _plural_display_name = 'Runners'
30
    _url_path = 'actionalias'
31
    _repr_attributes = ['name', 'pack', 'action_ref']
32
33
    @core.add_auth_token_to_kwargs_from_env
34
    def match(self, command, **kwargs):
35
        url = '/%s/match' % self.resource.get_url_path_name()
36
        query_str = urlencode({'command': command})
37
        response = self.client.post(url, query_str, **kwargs)
38
        if response.status_code != 201:
39
            self.handle_error(response)
40
        instance = self.resource.deserialize(response.json())
41
        return instance
42