Skip to content

Commit 5291e54

Browse files
committed
format code
Signed-off-by: zane-neo <zaniu@amazon.com>
1 parent 355a32a commit 5291e54

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

common/src/main/java/org/opensearch/ml/common/connector/HttpConnector.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,15 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
196196
builder.field(PARAMETERS_FIELD, parameters);
197197
}
198198
if (credential != null) {
199-
// Include the encrypted flag in the credential map for serialization
200-
Map<String, String> credentialWithFlag = new HashMap<>(credential);
201-
credentialWithFlag.put(ENCRYPTED_FIELD, String.valueOf(isEncrypted));
202-
builder.field(CREDENTIAL_FIELD, credentialWithFlag);
199+
// Only include the encrypted flag when isEncrypted is false to avoid document pollution
200+
// and maintain backward compatibility with existing connectors
201+
if (Boolean.FALSE.equals(isEncrypted)) {
202+
Map<String, String> credentialWithFlag = new HashMap<>(credential);
203+
credentialWithFlag.put(ENCRYPTED_FIELD, "false");
204+
builder.field(CREDENTIAL_FIELD, credentialWithFlag);
205+
} else {
206+
builder.field(CREDENTIAL_FIELD, credential);
207+
}
203208
}
204209
if (actions != null) {
205210
builder.field(ACTIONS_FIELD, actions);

common/src/test/java/org/opensearch/ml/common/connector/HttpConnectorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class HttpConnectorTest {
5252

5353
String TEST_CONNECTOR_JSON_STRING = "{\"name\":\"test_connector_name\",\"version\":\"1\","
5454
+ "\"description\":\"this is a test connector\",\"protocol\":\"http\","
55-
+ "\"parameters\":{\"input\":\"test input value\"},\"credential\":{\"encrypted\":\"true\",\"key\":\"test_key_value\"},"
55+
+ "\"parameters\":{\"input\":\"test input value\"},\"credential\":{\"key\":\"test_key_value\"},"
5656
+ "\"actions\":[{\"action_type\":\"PREDICT\",\"method\":\"POST\",\"url\":\"https://test.com\","
5757
+ "\"headers\":{\"api_key\":\"${credential.key}\"},"
5858
+ "\"request_body\":\"{\\\"input\\\": \\\"${parameters.input}\\\"}\","

0 commit comments

Comments
 (0)