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.models import TriggerType |
||
20 | from st2client.formatters import table |
||
21 | |||
22 | |||
23 | class TriggerTypeBranch(resource.ResourceBranch): |
||
24 | def __init__(self, description, app, subparsers, parent_parser=None): |
||
25 | super(TriggerTypeBranch, self).__init__( |
||
26 | TriggerType, description, app, subparsers, |
||
27 | parent_parser=parent_parser, |
||
28 | commands={ |
||
29 | 'list': TriggerTypeListCommand, |
||
30 | 'get': TriggerTypeGetCommand, |
||
31 | 'update': TriggerTypeUpdateCommand, |
||
32 | 'delete': TriggerTypeDeleteCommand |
||
33 | }) |
||
34 | |||
35 | # Registers extended commands |
||
36 | self.commands['getspecs'] = TriggerTypeSubTriggerCommand( |
||
37 | self.resource, self.app, self.subparsers, |
||
38 | add_help=False) |
||
39 | |||
40 | |||
41 | class TriggerTypeListCommand(resource.ContentPackResourceListCommand): |
||
42 | display_attributes = ['ref', 'pack', 'description'] |
||
43 | |||
44 | |||
45 | class TriggerTypeGetCommand(resource.ContentPackResourceGetCommand): |
||
46 | display_attributes = ['all'] |
||
47 | attribute_display_order = ['id', 'ref', 'pack', 'name', 'description', |
||
48 | 'parameters_schema', 'payload_schema'] |
||
49 | |||
50 | |||
51 | class TriggerTypeUpdateCommand(resource.ContentPackResourceUpdateCommand): |
||
52 | pass |
||
53 | |||
54 | |||
55 | class TriggerTypeDeleteCommand(resource.ContentPackResourceDeleteCommand): |
||
56 | pass |
||
57 | |||
58 | |||
59 | class TriggerTypeSubTriggerCommand(resource.ResourceCommand): |
||
60 | attribute_display_order = ['id', 'ref', 'context', 'parameters', 'status', |
||
61 | 'start_timestamp', 'result'] |
||
62 | |||
63 | def __init__(self, resource, *args, **kwargs): |
||
0 ignored issues
–
show
|
|||
64 | |||
65 | super(TriggerTypeSubTriggerCommand, self).__init__( |
||
66 | resource, kwargs.pop('name', 'getspecs'), |
||
67 | 'Return Trigger Specifications of a Trigger.', |
||
68 | *args, **kwargs) |
||
69 | |||
70 | self.parser.add_argument('ref', nargs='?', |
||
71 | metavar='ref', |
||
72 | help='Fully qualified name (pack.trigger_name) ' + |
||
73 | 'of the trigger.') |
||
74 | |||
75 | self.parser.add_argument('-h', '--help', |
||
76 | action='store_true', dest='help', |
||
77 | help='Print usage for the given action.') |
||
78 | |||
79 | @resource.add_auth_token_to_kwargs_from_cli |
||
80 | def run(self, args, **kwargs): |
||
81 | trigger_mgr = self.app.client.managers['Trigger'] |
||
82 | return trigger_mgr.query(**{'type': args.ref}) |
||
83 | |||
84 | @resource.add_auth_token_to_kwargs_from_cli |
||
85 | def run_and_print(self, args, **kwargs): |
||
86 | if args.help: |
||
87 | self.parser.print_help() |
||
88 | return |
||
89 | instances = self.run(args, **kwargs) |
||
90 | self.print_output(instances, table.MultiColumnTable, |
||
91 | json=args.json, yaml=args.yaml) |
||
92 |
It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior: