Skip to content

Commit c6667ad

Browse files
committed
[STORM-755] When listing sensors, actions and triggers include "ref" attribute for every
item.
1 parent 4c53b63 commit c6667ad

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

st2api/st2api/controllers/actions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class ActionsController(resource.ContentPackResourceControler):
3939
'sort': ['pack', 'name']
4040
}
4141

42+
include_reference = True
43+
4244
@staticmethod
4345
def _get_by_id(action_id):
4446
try:

st2api/st2api/controllers/resource.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,21 @@ def _get_all(self, **kwargs):
9393

9494

9595
class ContentPackResourceControler(ResourceController):
96+
include_reference = False
97+
9698
@jsexpose()
9799
def get_all(self, **kwargs):
98-
return self._get_all(**kwargs)
100+
result = self._get_all(**kwargs)
101+
result = result or []
102+
103+
if self.include_reference:
104+
for item in result:
105+
pack = getattr(item, 'pack', None)
106+
name = getattr(item, 'name', None)
107+
108+
item.ref = ResourceReference(pack=pack, name=name).ref
109+
110+
return result
99111

100112
def _get_all(self, **kwargs):
101113
kwargs = self._get_filters(**kwargs)

st2api/st2api/controllers/sensors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ class SensorTypeController(resource.ContentPackResourceControler):
2020
options = {
2121
'sort': ['pack', 'name']
2222
}
23+
24+
include_reference = True

st2api/st2api/controllers/triggers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class TriggerTypeController(resource.ContentPackResourceControler):
3131
'sort': ['pack', 'name']
3232
}
3333

34+
include_reference = True
35+
3436
@jsexpose(body=TriggerTypeAPI, status_code=http_client.CREATED)
3537
def post(self, triggertype):
3638
"""

0 commit comments

Comments
 (0)