From 76e63756c6b793b76e265f7896a29a149f0679c1 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:51:45 -0800 Subject: [PATCH] [Backport 2.12] Ensure params are consumed before checking feature flag (#517) Ensure params are consumed before checking feature flag (#514) (cherry picked from commit 1727434f3b2b86091247622590f8da0fa531624d) Signed-off-by: Daniel Widdis Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- .../flowframework/rest/RestCreateWorkflowAction.java | 4 ++-- .../flowframework/rest/RestGetWorkflowStateAction.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java b/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java index 54c485ec0..490f4f3ff 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java @@ -73,6 +73,8 @@ public List routes() { @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { String workflowId = request.param(WORKFLOW_ID); + String[] validation = request.paramAsStringArray(VALIDATION, new String[] { "all" }); + boolean provision = request.paramAsBoolean(PROVISION_WORKFLOW, false); if (!flowFrameworkSettings.isFlowFrameworkEnabled()) { FlowFrameworkException ffe = new FlowFrameworkException( "This API is disabled. To enable it, set [" + FLOW_FRAMEWORK_ENABLED.getKey() + "] to true.", @@ -86,8 +88,6 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli XContentParser parser = request.contentParser(); ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser); Template template = Template.parse(parser); - String[] validation = request.paramAsStringArray(VALIDATION, new String[] { "all" }); - boolean provision = request.paramAsBoolean(PROVISION_WORKFLOW, false); WorkflowRequest workflowRequest = new WorkflowRequest(workflowId, template, validation, provision); diff --git a/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java b/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java index 9db927f34..ded82f92c 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java @@ -57,6 +57,7 @@ public String getName() { @Override protected BaseRestHandler.RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { String workflowId = request.param(WORKFLOW_ID); + boolean all = request.paramAsBoolean("all", false); try { if (!flowFrameworkFeatureEnabledSetting.isFlowFrameworkEnabled()) { throw new FlowFrameworkException( @@ -75,7 +76,6 @@ protected BaseRestHandler.RestChannelConsumer prepareRequest(RestRequest request throw new FlowFrameworkException("workflow_id cannot be null", RestStatus.BAD_REQUEST); } - boolean all = request.paramAsBoolean("all", false); GetWorkflowStateRequest getWorkflowRequest = new GetWorkflowStateRequest(workflowId, all); return channel -> client.execute(GetWorkflowStateAction.INSTANCE, getWorkflowRequest, ActionListener.wrap(response -> { XContentBuilder builder = response.toXContent(channel.newBuilder(), ToXContent.EMPTY_PARAMS);