File tree Expand file tree Collapse file tree 5 files changed +29
-33
lines changed
st2api/st2api/controllers Expand file tree Collapse file tree 5 files changed +29
-33
lines changed Original file line number Diff line number Diff line change 2121LOG = logging .getLogger (__name__ )
2222
2323
24- class ActionsController (resource .ResourceController ):
24+ class ActionsController (resource .ContentPackResourceControler ):
2525 """
2626 Implements the RESTful web endpoint that handles
2727 the lifecycle of Actions in the system.
@@ -58,11 +58,6 @@ def _validate_action_parameters(action, runnertype_db):
5858 LOG .error (msg )
5959 abort (http_client .CONFLICT , msg )
6060
61- @jsexpose ()
62- @resource .referenced
63- def get_all (self , ** kwargs ):
64- return super (ActionsController , self )._get_all (** kwargs )
65-
6661 @jsexpose (body = ActionAPI , status_code = http_client .CREATED )
6762 def post (self , action ):
6863 """
Original file line number Diff line number Diff line change @@ -71,7 +71,11 @@ def _get_one(action_id):
7171 return {'parameters' : all_params }
7272
7373
74- class OverviewController (RestController ):
74+ class OverviewController (resource .ContentPackResourceControler ):
75+ model = None
76+ access = None
77+ supported_filters = {}
78+
7579 @jsexpose (str )
7680 def get_one (self , action_id ):
7781 """
@@ -87,16 +91,16 @@ def get_one(self, action_id):
8791 return self ._transform_action_api (action_api )
8892
8993 @jsexpose (str )
90- @resource .referenced
91- def get_all (self , ** kw ):
94+ def get_all (self , ** kwargs ):
9295 """
9396 List all actions.
9497
9598 Handles requests:
9699 GET /actions/views/overview
97100 """
98- LOG .info ('GET all /actions/views/overview with filters=%s' , kw )
99- action_dbs = Action .get_all (** kw )
101+ LOG .info ('GET all /actions/views/overview with filters=%s' , kwargs )
102+ kwargs = self ._get_filters (** kwargs )
103+ action_dbs = Action .get_all (** kwargs )
100104 action_apis = [ActionAPI .from_model (action_db ) for action_db in action_dbs ]
101105 return map (self ._transform_action_api , action_apis )
102106
Original file line number Diff line number Diff line change @@ -92,9 +92,19 @@ def _get_all(self, **kwargs):
9292 return [self .model .from_model (instance ) for instance in instances [offset :eop ]]
9393
9494
95- def referenced (f ):
96- def decorate (* args , ** kwargs ):
97- ref = kwargs .get ('ref' , None )
95+ class ContentPackResourceControler (ResourceController ):
96+ @jsexpose ()
97+ def get_all (self , ** kwargs ):
98+ return self ._get_all (** kwargs )
99+
100+ def _get_all (self , ** kwargs ):
101+ kwargs = self ._get_filters (** kwargs )
102+ return super (ContentPackResourceControler , self )._get_all (** kwargs )
103+
104+ def _get_filters (self , ** kwargs ):
105+ filters = copy .deepcopy (kwargs )
106+
107+ ref = filters .get ('ref' , None )
98108
99109 if ref :
100110 try :
@@ -103,10 +113,8 @@ def decorate(*args, **kwargs):
103113 # Invalid reference
104114 return []
105115
106- kwargs ['name' ] = ref_obj .name
107- kwargs ['pack' ] = ref_obj .pack
108- del kwargs ['ref' ]
109-
110- return f (* args , ** kwargs )
116+ filters ['name' ] = ref_obj .name
117+ filters ['pack' ] = ref_obj .pack
118+ del filters ['ref' ]
111119
112- return decorate
120+ return filters
Original file line number Diff line number Diff line change 22from st2common import log as logging
33from st2common .persistence .reactor import SensorType
44from st2common .models .api .reactor import SensorTypeAPI
5- from st2common .models .base import jsexpose
65from st2api .controllers import resource
76
87http_client = six .moves .http_client
98
109LOG = logging .getLogger (__name__ )
1110
1211
13- class SensorTypeController (resource .ResourceController ):
12+ class SensorTypeController (resource .ContentPackResourceControler ):
1413 model = SensorTypeAPI
1514 access = SensorType
1615 supported_filters = {
@@ -21,8 +20,3 @@ class SensorTypeController(resource.ResourceController):
2120 options = {
2221 'sort' : ['pack' , 'name' ]
2322 }
24-
25- @jsexpose ()
26- @resource .referenced
27- def get_all (self , ** kwargs ):
28- return super (SensorTypeController , self )._get_all (** kwargs )
Original file line number Diff line number Diff line change 1515LOG = logging .getLogger (__name__ )
1616
1717
18- class TriggerTypeController (resource .ResourceController ):
18+ class TriggerTypeController (resource .ContentPackResourceControler ):
1919 """
2020 Implements the RESTful web endpoint that handles
2121 the lifecycle of TriggerTypes in the system.
@@ -31,11 +31,6 @@ class TriggerTypeController(resource.ResourceController):
3131 'sort' : ['pack' , 'name' ]
3232 }
3333
34- @jsexpose ()
35- @resource .referenced
36- def get_all (self , ** kwargs ):
37- return super (TriggerTypeController , self )._get_all (** kwargs )
38-
3934 @jsexpose (body = TriggerTypeAPI , status_code = http_client .CREATED )
4035 def post (self , triggertype ):
4136 """
You can’t perform that action at this time.
0 commit comments