|
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 st2api.controllers.resource import ResourceController |
|
17
|
|
|
from st2common.models.api.trace import TraceAPI |
|
18
|
|
|
from st2common.persistence.trace import Trace |
|
19
|
|
|
from st2common.rbac.types import PermissionType |
|
20
|
|
|
|
|
21
|
|
|
__all__ = [ |
|
22
|
|
|
'TracesController' |
|
23
|
|
|
] |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
class TracesController(ResourceController): |
|
27
|
|
|
model = TraceAPI |
|
28
|
|
|
access = Trace |
|
29
|
|
|
supported_filters = { |
|
30
|
|
|
'trace_tag': 'trace_tag', |
|
31
|
|
|
'execution': 'action_executions.object_id', |
|
32
|
|
|
'rule': 'rules.object_id', |
|
33
|
|
|
'trigger_instance': 'trigger_instances.object_id', |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
query_options = { |
|
37
|
|
|
'sort': ['-start_timestamp', 'trace_tag'] |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
def get_all(self, sort=None, offset=0, limit=None, **raw_filters): |
|
41
|
|
|
# Use a custom sort order when filtering on a timestamp so we return a correct result as |
|
42
|
|
|
# expected by the user |
|
43
|
|
|
query_options = None |
|
44
|
|
|
if 'sort_desc' in raw_filters and raw_filters['sort_desc'] == 'True': |
|
45
|
|
|
query_options = {'sort': ['-start_timestamp', 'trace_tag']} |
|
46
|
|
|
elif 'sort_asc' in raw_filters and raw_filters['sort_asc'] == 'True': |
|
47
|
|
|
query_options = {'sort': ['+start_timestamp', 'trace_tag']} |
|
48
|
|
|
return self._get_all(sort=sort, |
|
49
|
|
|
offset=offset, |
|
50
|
|
|
limit=limit, |
|
51
|
|
|
query_options=query_options, |
|
52
|
|
|
raw_filters=raw_filters) |
|
53
|
|
|
|
|
54
|
|
|
def get_one(self, id, requester_user): |
|
|
|
|
|
|
55
|
|
|
return self._get_one_by_id(id, |
|
56
|
|
|
requester_user=requester_user, |
|
57
|
|
|
permission_type=PermissionType.TRACE_VIEW) |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
traces_controller = TracesController() |
|
61
|
|
|
|
It is generally discouraged to redefine built-ins as this makes code very hard to read.