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 __future__ import absolute_import |
17
|
|
|
|
18
|
|
|
from st2client.commands import resource |
19
|
|
|
from st2client.formatters import table |
20
|
|
|
from st2client.models import Webhook |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
class WebhookBranch(resource.ResourceBranch): |
24
|
|
|
def __init__(self, description, app, subparsers, parent_parser=None): |
25
|
|
|
super(WebhookBranch, self).__init__( |
26
|
|
|
Webhook, description, app, subparsers, |
27
|
|
|
parent_parser=parent_parser, |
28
|
|
|
read_only=True, |
29
|
|
|
commands={ |
30
|
|
|
'list': WebhookListCommand, |
31
|
|
|
'get': WebhookGetCommand |
32
|
|
|
}) |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
class WebhookListCommand(resource.ContentPackResourceListCommand): |
36
|
|
|
display_attributes = ['webhook', 'type', 'pack', 'name', 'description', 'parameters'] |
37
|
|
|
|
38
|
|
|
def run_and_print(self, args, **kwargs): |
39
|
|
|
instances = self.run(args, **kwargs) |
40
|
|
|
|
41
|
|
|
for instance in instances: |
42
|
|
|
instance.webhook = instance.parameters['url'] |
43
|
|
|
|
44
|
|
|
instances = sorted(instances, key=lambda k: k.webhook) |
45
|
|
|
|
46
|
|
|
if args.json or args.yaml: |
47
|
|
|
self.print_output(instances, table.MultiColumnTable, |
48
|
|
|
attributes=args.attr, widths=args.width, |
49
|
|
|
json=args.json, yaml=args.yaml) |
50
|
|
|
else: |
51
|
|
|
self.print_output(instances, table.MultiColumnTable, |
52
|
|
|
attributes=args.attr, widths=args.width) |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
class WebhookGetCommand(resource.ResourceGetCommand): |
56
|
|
|
display_attributes = ['all'] |
57
|
|
|
attribute_display_order = ['type', 'pack', 'name', 'description', 'parameters'] |
58
|
|
|
|
59
|
|
|
pk_argument_name = 'webhook' |
60
|
|
|
|