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

Fix connector can use subfield of ARN #2320

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -148,7 +148,14 @@ public static MLCreateConnectorInput parse(XContentParser parser, boolean update
parameters = getParameterMap(parser.map());
break;
case CONNECTOR_CREDENTIAL_FIELD:
credential = parser.mapStrings();
// We need to filter out any key string that is trying to imitate the subfield of the secretArn of the credential map
b4sjoo marked this conversation as resolved.
Show resolved Hide resolved
credential = new HashMap<>();
Map<String, String> credentialKeyToAdd = parser.mapStrings();
for (String key : credentialKeyToAdd.keySet()) {
if (!key.startsWith("secretArn.")) {
b4sjoo marked this conversation as resolved.
Show resolved Hide resolved
b4sjoo marked this conversation as resolved.
Show resolved Hide resolved
credential.put(key, credentialKeyToAdd.get(key));
}
}
break;
case CONNECTOR_ACTIONS_FIELD:
actions = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
Expand Down Expand Up @@ -191,6 +192,25 @@ public void testParse_ArrayParameter() throws Exception {
});
}

@Test
public void testParse_SecretArnPrefix() throws Exception {
String expectedInputStr = "{\"name\":\"test_connector_name\"," +
"\"description\":\"this is a test connector\",\"version\":\"1\",\"protocol\":\"http\"," +
"\"parameters\":{\"input\":[\"test input value\"]},\"credential\":{\"key\":\"test_key_value\", \"secretArn\":\"test_secretArn_value\", \"secretArn.key\":\"test_key_value\"}," +
"\"actions\":[{\"action_type\":\"PREDICT\",\"method\":\"POST\",\"url\":\"https://test.com\"," +
"\"headers\":{\"api_key\":\"${credential.key}\"}," +
"\"request_body\":\"{\\\"input\\\": \\\"${parameters.input}\\\"}\"," +
"\"pre_process_function\":\"connector.pre_process.openai.embedding\"," +
"\"post_process_function\":\"connector.post_process.openai.embedding\"}]," +
"\"backend_roles\":[\"role1\",\"role2\"],\"add_all_backend_roles\":false," +
"\"access_mode\":\"PUBLIC\"}";
HashSet<String> expectedCredentialKeys = new HashSet<>(Arrays.asList("key", "secretArn"));
testParseFromJsonString(expectedInputStr, parsedInput -> {
assertEquals(expectedCredentialKeys, parsedInput.getCredential().keySet());
assertEquals("test_secretArn_value", parsedInput.getCredential().get("secretArn"));
});
}

@Test
public void testParseWithDryRun() throws Exception {
String expectedInputStrWithDryRun = "{\"dry_run\":true}";
Expand Down
Loading