Skip to content

Commit 37a2869

Browse files
authored
Don't fail create workflow on already-consumed OpenSearch REST params (#543)
Signed-off-by: Daniel Widdis <[email protected]>
1 parent 2c6dfd5 commit 37a2869

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,17 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
7878
String workflowId = request.param(WORKFLOW_ID);
7979
String[] validation = request.paramAsStringArray(VALIDATION, new String[] { "all" });
8080
boolean provision = request.paramAsBoolean(PROVISION_WORKFLOW, false);
81-
final List<String> validCreateParams = List.of(WORKFLOW_ID, VALIDATION, PROVISION_WORKFLOW);
8281
// If provisioning, consume all other params and pass to provision transport action
8382
Map<String, String> params = provision
8483
? request.params()
8584
.keySet()
8685
.stream()
87-
.filter(k -> !validCreateParams.contains(k))
86+
.filter(k -> !request.consumedParams().contains(k))
8887
.collect(Collectors.toMap(Function.identity(), request::param))
8988
: request.params()
9089
.entrySet()
9190
.stream()
92-
.filter(e -> !validCreateParams.contains(e.getKey()))
91+
.filter(e -> !request.consumedParams().contains(e.getKey()))
9392
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
9493
if (!flowFrameworkSettings.isFlowFrameworkEnabled()) {
9594
FlowFrameworkException ffe = new FlowFrameworkException(
@@ -105,7 +104,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
105104
params.keySet().stream().forEach(request::param);
106105
request.content();
107106
FlowFrameworkException ffe = new FlowFrameworkException(
108-
"Only the parameters " + validCreateParams + " are permitted unless the provision parameter is set to true.",
107+
"Only the parameters " + request.consumedParams() + " are permitted unless the provision parameter is set to true.",
109108
RestStatus.BAD_REQUEST
110109
);
111110
return channel -> channel.sendResponse(

src/test/java/org/opensearch/flowframework/rest/RestCreateWorkflowActionTests.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,7 @@ public void testCreateWorkflowRequestWithParamsButNoProvision() throws Exception
127127
createWorkflowRestAction.handleRequest(request, channel, nodeClient);
128128
assertEquals(RestStatus.BAD_REQUEST, channel.capturedResponse().status());
129129
assertTrue(
130-
channel.capturedResponse()
131-
.content()
132-
.utf8ToString()
133-
.contains(
134-
"Only the parameters [workflow_id, validation, provision] are permitted unless the provision parameter is set to true."
135-
)
130+
channel.capturedResponse().content().utf8ToString().contains("are permitted unless the provision parameter is set to true.")
136131
);
137132
}
138133

0 commit comments

Comments
 (0)