Skip to content

Commit f91ead4

Browse files
committed
Remove validation that made keys starting or ending with . - or _ invalid, catch all exceptions in the parse json processor
Signed-off-by: Taylor Gray <tylgry@amazon.com>
1 parent 1dd8bd3 commit f91ead4

5 files changed

Lines changed: 100 additions & 40 deletions

File tree

data-prepper-api/src/main/java/org/opensearch/dataprepper/model/event/JacksonEvent.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -373,19 +373,9 @@ private String trimKey(final String key) {
373373
}
374374

375375
private boolean isValidKey(final String key) {
376-
char previous = ' ';
377-
char next = ' ';
378376
for (int i = 0; i < key.length(); i++) {
379377
char c = key.charAt(i);
380378

381-
if (i < key.length() - 1) {
382-
next = key.charAt(i + 1);
383-
}
384-
385-
if ((i == 0 || i == key.length() - 1 || previous == '/' || next == '/') && (c == '_' || c == '.' || c == '-')) {
386-
return false;
387-
}
388-
389379
if (!(c >= 48 && c <= 57
390380
|| c >= 65 && c <= 90
391381
|| c >= 97 && c <= 122
@@ -397,7 +387,6 @@ private boolean isValidKey(final String key) {
397387

398388
return false;
399389
}
400-
previous = c;
401390
}
402391
return true;
403392
}

data-prepper-api/src/test/java/org/opensearch/dataprepper/model/event/JacksonEventTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,8 @@ public void testIsValueAList_withNull() {
323323
}
324324

325325
@ParameterizedTest
326-
@ValueSource(strings = {"", "withSpecialChars*$%", "-withPrefixDash", "\\-withEscapeChars", "\\\\/withMultipleEscapeChars",
327-
"withDashSuffix-", "withDashSuffix-/nestedKey", "withDashPrefix/-nestedKey", "_withUnderscorePrefix", "withUnderscoreSuffix_",
328-
".withDotPrefix", "withDotSuffix.", "with,Comma", "with:Colon", "with[Bracket", "with|Brace"})
326+
@ValueSource(strings = {"", "withSpecialChars*$%", "\\-withEscapeChars", "\\\\/withMultipleEscapeChars",
327+
"with,Comma", "with:Colon", "with[Bracket", "with|Brace"})
329328
void testKey_withInvalidKey_throwsIllegalArgumentException(final String invalidKey) {
330329
assertThrowsForKeyCheck(IllegalArgumentException.class, invalidKey);
331330
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# OpenSearch Source
2+
3+
This is the Date Prepper OpenSearch source plugin that processes indices either OpenSearch, Elasticsearch,
4+
or Amazon OpenSearch Service. It is meant for migrating index data from a cluster.
5+
6+
Note: Only fully tested versions with be listed below. It is likely many more versions are supported already, but it is untested.
7+
8+
The OpenSearch source is compatible with the following OpenSearch versions:
9+
* 2.5
10+
11+
And is compatible with the following Elasticsearch versions:
12+
* 7.10
13+
14+
# Usages
15+
16+
### Amazon OpenSearch Service
17+
18+
The OpenSearch sink can also be configured for an Amazon OpenSearch Service domain. See [security](security.md) for details.
19+
20+
```yaml
21+
opensearch-source-pipeline:
22+
source:
23+
opensearch:
24+
connection:
25+
insecure: true
26+
hosts: [ "https://search-my-domain-soopywaovobopgs8ywurr3utsu.us-east-1.es.amazonaws.com" ]
27+
aws:
28+
region: "us-east-1"
29+
sts_role_arn: "arn:aws:iam::123456789012:role/my-domain-role"
30+
```
31+
32+
## Configuration
33+
34+
- `hosts`: A list of IP addresses of OpenSearch or Elasticsearch nodes.
35+
36+
37+
- `username`:
38+
39+
40+
- `password`:
41+
42+
43+
- `aws` (Optional) : AWS configurations. See [AWS Configuration](#aws_configuration) for details. SigV4 is enabled by default when this option is used.
44+
45+
46+
- `search_options` (Optional) : See [Search Configuration](#search_configuration) for details
47+
48+
49+
- `indices` (Optional): See [Indices Configurations](#indices_configuration) for filtering options.
50+
51+
52+
- `scheduling` (Optional): See [Scheduling Configuration](#scheduling_configuration) for details
53+
54+
55+
- `connection` (Optional): See []
56+
57+
### <a name="aws_configuration">AWS Configuration</a>
58+
59+
* `region` (Optional) : The AWS region to use for credentials. Defaults to [standard SDK behavior to determine the region](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/region-selection.html).
60+
* `sts_role_arn` (Optional) : The STS role to assume for requests to AWS. Defaults to null, which will use the [standard SDK behavior for credentials](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/credentials.html).
61+
* `sts_header_overrides` (Optional): A map of header overrides to make when assuming the IAM role for the source plugin.
62+
63+
### <a name="search_configuration">Search Configuration</a>
64+
65+
### <a name="scheduling_configuration">Scheduling Configuration</a>
66+
67+
### <a name="connection_configuration">Connection Configuration</a>
68+
69+
### <a name="indices_configuration">Indices Configuration</a>

data-prepper-plugins/opensearch-source/security.md

Whitespace-only changes.

data-prepper-plugins/parse-json-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/parsejson/ParseJsonProcessor.java

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,37 @@ public Collection<Record<Event>> doExecute(final Collection<Record<Event>> recor
6464
final boolean doUsePointer = Objects.nonNull(pointer);
6565

6666
for (final Record<Event> record : records) {
67-
final Event event = record.getData();
6867

69-
if (Objects.nonNull(parseWhen) && !expressionEvaluator.evaluateConditional(parseWhen, event)) {
70-
continue;
71-
}
72-
73-
final String message = event.get(source, String.class);
74-
if (Objects.isNull(message)) {
75-
continue;
76-
}
77-
78-
try {
79-
final TypeReference<HashMap<String, Object>> hashMapTypeReference = new TypeReference<HashMap<String, Object>>() {};
80-
Map<String, Object> parsedJson = objectMapper.readValue(message, hashMapTypeReference);
81-
82-
if (doUsePointer) {
83-
parsedJson = parseUsingPointer(event, parsedJson, pointer, doWriteToRoot);
84-
}
85-
86-
if (doWriteToRoot) {
87-
writeToRoot(event, parsedJson);
88-
} else {
89-
event.put(destination, parsedJson);
68+
final Event event = record.getData();
69+
try {
70+
if (Objects.nonNull(parseWhen) && !expressionEvaluator.evaluateConditional(parseWhen, event)) {
71+
continue;
72+
}
73+
74+
final String message = event.get(source, String.class);
75+
if (Objects.isNull(message)) {
76+
continue;
77+
}
78+
final TypeReference<HashMap<String, Object>> hashMapTypeReference = new TypeReference<HashMap<String, Object>>() {
79+
};
80+
Map<String, Object> parsedJson = objectMapper.readValue(message, hashMapTypeReference);
81+
82+
if (doUsePointer) {
83+
parsedJson = parseUsingPointer(event, parsedJson, pointer, doWriteToRoot);
84+
}
85+
86+
if (doWriteToRoot) {
87+
writeToRoot(event, parsedJson);
88+
} else {
89+
event.put(destination, parsedJson);
90+
}
91+
} catch (final JsonProcessingException jsonException) {
92+
event.getMetadata().addTags(tagsOnFailure);
93+
LOG.error(EVENT, "An exception occurred due to invalid JSON while reading event [{}]", event, jsonException);
94+
} catch (final Exception e) {
95+
event.getMetadata().addTags(tagsOnFailure);
96+
LOG.error(EVENT, "An exception occurred while using the parse_json processor on Event [{}]", event, e);
9097
}
91-
} catch (final JsonProcessingException jsonException) {
92-
event.getMetadata().addTags(tagsOnFailure);
93-
LOG.error(EVENT, "An exception occurred due to invalid JSON while reading event [{}]", event, jsonException);
94-
}
9598
}
9699
return records;
97100
}

0 commit comments

Comments
 (0)