Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added amazon rekognition as a trust endpoint #3419

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ private MLCommonsSettings() {}
public static final Setting<Boolean> ML_COMMONS_OFFLINE_BATCH_INFERENCE_ENABLED = Setting
.boolSetting("plugins.ml_commons.offline_batch_inference_enabled", true, Setting.Property.NodeScope, Setting.Property.Dynamic);

public static final String REKOGNITION_TRUST_ENDPOINT_REGEX = "^https://rekognition(-fips)?\\..*[a-z0-9-]\\.amazonaws\\.com$";

public static final Setting<List<String>> ML_COMMONS_TRUSTED_CONNECTOR_ENDPOINTS_REGEX = Setting
.listSetting(
"plugins.ml_commons.trusted_connector_endpoints_regex",
Expand All @@ -170,7 +172,8 @@ private MLCommonsSettings() {}
"^https://bedrock-agent-runtime\\..*[a-z0-9-]\\.amazonaws\\.com/.*$",
"^https://bedrock\\..*[a-z0-9-]\\.amazonaws\\.com/.*$",
"^https://textract\\..*[a-z0-9-]\\.amazonaws\\.com$",
"^https://comprehend\\..*[a-z0-9-]\\.amazonaws\\.com$"
"^https://comprehend\\..*[a-z0-9-]\\.amazonaws\\.com$",
REKOGNITION_TRUST_ENDPOINT_REGEX
),
Function.identity(),
Setting.Property.NodeScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static org.opensearch.ml.common.CommonValue.ML_CONNECTOR_INDEX;
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_CONNECTOR_ACCESS_CONTROL_ENABLED;
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_TRUSTED_CONNECTOR_ENDPOINTS_REGEX;
import static org.opensearch.ml.settings.MLCommonsSettings.REKOGNITION_TRUST_ENDPOINT_REGEX;
import static org.opensearch.ml.task.MLPredictTaskRunnerTests.USER_STRING;
import static org.opensearch.ml.utils.TestHelper.clusterSetting;

Expand Down Expand Up @@ -122,6 +123,7 @@ public class TransportCreateConnectorActionTests extends OpenSearchTestCase {
"^https://runtime\\.sagemaker\\..*\\.amazonaws\\.com/.*$",
"^https://api\\.openai\\.com/.*$",
"^https://api\\.cohere\\.ai/.*$",
REKOGNITION_TRUST_ENDPOINT_REGEX,
"^https://api\\.deepseek\\.com/.*$"
);

Expand Down Expand Up @@ -559,6 +561,56 @@ public void test_connector_creation_success_deepseek() {
mlModelManager,
mlFeatureEnabledSetting
);
doAnswer(invocation -> {
ActionListener<Boolean> listener = invocation.getArgument(0);
listener.onResponse(true);
return null;
}).when(mlIndicesHandler).initMLConnectorIndex(isA(ActionListener.class));
doAnswer(invocation -> {
ActionListener<IndexResponse> listener = invocation.getArgument(1);
listener.onResponse(indexResponse);
return null;
}).when(client).index(any(IndexRequest.class), isA(ActionListener.class));
List<ConnectorAction> actions = new ArrayList<>();
actions
.add(
ConnectorAction
.builder()
.actionType(ConnectorAction.ActionType.PREDICT)
.method("POST")
.url("https://api.deepseek.com/v1/chat/completions")
.build()
);
Map<String, String> credential = ImmutableMap.of("access_key", "mockKey", "secret_key", "mockSecret");
MLCreateConnectorInput mlCreateConnectorInput = MLCreateConnectorInput
.builder()
.name(randomAlphaOfLength(5))
.description(randomAlphaOfLength(10))
.version("1")
.protocol(ConnectorProtocols.HTTP)
.credential(credential)
.actions(actions)
.build();
MLCreateConnectorRequest request = new MLCreateConnectorRequest(mlCreateConnectorInput);
action.doExecute(task, request, actionListener);
verify(actionListener).onResponse(any(MLCreateConnectorResponse.class));
}

public void test_connector_creation_success_rekognition() {
TransportCreateConnectorAction action = new TransportCreateConnectorAction(
transportService,
actionFilters,
mlIndicesHandler,
client,
sdkClient,
mlEngine,
connectorAccessControlHelper,
settings,
clusterService,
mlModelManager,
mlFeatureEnabledSetting
);

doAnswer(invocation -> {
ActionListener<Boolean> listener = invocation.getArgument(0);
listener.onResponse(true);
Expand All @@ -578,7 +630,16 @@ public void test_connector_creation_success_deepseek() {
.builder()
.actionType(ConnectorAction.ActionType.PREDICT)
.method("POST")
.url("https://api.deepseek.com/v1/chat/completions")
.url("https://rekognition.test-region-1.amazonaws.com")
.build()
);
actions
.add(
ConnectorAction
.builder()
.actionType(ConnectorAction.ActionType.PREDICT)
.method("POST")
.url("https://rekognition-fips.test-region-1.amazonaws.com")
.build()
);

Expand All @@ -594,6 +655,7 @@ public void test_connector_creation_success_deepseek() {
.build();

MLCreateConnectorRequest request = new MLCreateConnectorRequest(mlCreateConnectorInput);

action.doExecute(task, request, actionListener);
verify(actionListener).onResponse(any(MLCreateConnectorResponse.class));
}
Expand Down
Loading