From 1020554f1c2b43dc9af84d217a57a9a2263f1f44 Mon Sep 17 00:00:00 2001 From: Nikolay Mahotkin Date: Fri, 24 Jan 2014 19:27:56 +0400 Subject: [PATCH] Modified Rest action for process 'input' property * For HTTP GET task input is converted to request url parameters * For HTTP POST/PUT - into request body Change-Id: Ibc863ffb99ffdd0099f9ba2f43178e02dc1dd0c2 --- mistral/engine/actions/action_factory.py | 13 ++++++++++++- mistral/engine/actions/actions.py | 5 +++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/mistral/engine/actions/action_factory.py b/mistral/engine/actions/action_factory.py index ea88cbcda..dc7b2d7e8 100644 --- a/mistral/engine/actions/action_factory.py +++ b/mistral/engine/actions/action_factory.py @@ -53,9 +53,20 @@ def get_rest_action(task): headers.update(action_dsl.get('headers', {})) method = action_dsl['parameters'].get('method', "GET") + + # input_yaql = task.get('input') + # TODO(nmakhotkin) extract input from context within the YAQL expression + task_input = {} # yaql_utils.evaluate(input_yaql, ctx) + task_data = {} + + if method.upper() == "GET": + task_params.update(task_input) + elif method.upper() in ["POST", "PUT"]: + task_data.update(task_input) + return actions.RestAction(action_type, action_name, url, params=task_params, method=method, - headers=headers) + headers=headers, data=task_data) def get_mistral_rest_action(task): diff --git a/mistral/engine/actions/actions.py b/mistral/engine/actions/actions.py index 31e2a46fe..15f5b191a 100644 --- a/mistral/engine/actions/actions.py +++ b/mistral/engine/actions/actions.py @@ -41,19 +41,20 @@ class BaseAction(object): class RestAction(BaseAction): def __init__(self, action_type, action_name, url, params={}, - method="GET", headers={}): + method="GET", headers={}, data={}): super(RestAction, self).__init__(action_type, action_name) self.url = url self.params = params self.method = method self.headers = headers + self.data = data def run(self): LOG.info("Sending action HTTP request " "[method=%s, url=%s, params=%s, headers=%s]" % (self.method, self.url, self.params, self.headers)) resp = requests.request(self.method, self.url, params=self.params, - headers=self.headers) + headers=self.headers, data=self.data) LOG.info("Received HTTP response:\n%s\n%s" % (resp.status_code, resp.content)) # Return rather json than text, but response can contain text also.