Skip to content

Commit

Permalink
[Backport 2.x] Don't fail create workflow on already-consumed OpenSea…
Browse files Browse the repository at this point in the history
…rch REST params (#544)

Don't fail create workflow on already-consumed OpenSearch REST params (#543)


(cherry picked from commit 37a2869)

Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 2540db6 commit 1335d4a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,17 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
String workflowId = request.param(WORKFLOW_ID);
String[] validation = request.paramAsStringArray(VALIDATION, new String[] { "all" });
boolean provision = request.paramAsBoolean(PROVISION_WORKFLOW, false);
final List<String> validCreateParams = List.of(WORKFLOW_ID, VALIDATION, PROVISION_WORKFLOW);
// If provisioning, consume all other params and pass to provision transport action
Map<String, String> params = provision
? request.params()
.keySet()
.stream()
.filter(k -> !validCreateParams.contains(k))
.filter(k -> !request.consumedParams().contains(k))
.collect(Collectors.toMap(Function.identity(), request::param))
: request.params()
.entrySet()
.stream()
.filter(e -> !validCreateParams.contains(e.getKey()))
.filter(e -> !request.consumedParams().contains(e.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
if (!flowFrameworkSettings.isFlowFrameworkEnabled()) {
FlowFrameworkException ffe = new FlowFrameworkException(
Expand All @@ -105,7 +104,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
params.keySet().stream().forEach(request::param);
request.content();
FlowFrameworkException ffe = new FlowFrameworkException(
"Only the parameters " + validCreateParams + " are permitted unless the provision parameter is set to true.",
"Only the parameters " + request.consumedParams() + " are permitted unless the provision parameter is set to true.",
RestStatus.BAD_REQUEST
);
return channel -> channel.sendResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,7 @@ public void testCreateWorkflowRequestWithParamsButNoProvision() throws Exception
createWorkflowRestAction.handleRequest(request, channel, nodeClient);
assertEquals(RestStatus.BAD_REQUEST, channel.capturedResponse().status());
assertTrue(
channel.capturedResponse()
.content()
.utf8ToString()
.contains(
"Only the parameters [workflow_id, validation, provision] are permitted unless the provision parameter is set to true."
)
channel.capturedResponse().content().utf8ToString().contains("are permitted unless the provision parameter is set to true.")
);
}

Expand Down

0 comments on commit 1335d4a

Please sign in to comment.