Skip to content

Commit 8d421df

Browse files
authored
[RORDEV-1575][RORDEV-1577][RORDEV-1579][RORDEV-1581] ES 9.0.5 & 8.19.2 & 8.18.5 & 8.17.10 support (#1148)
1 parent ec5907a commit 8d421df

File tree

6 files changed

+31
-8
lines changed

6 files changed

+31
-8
lines changed

ci/supported-es-versions/es8x.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
8.19.2
12
8.19.1
23
8.19.0
4+
8.18.5
35
8.18.4
46
8.18.3
57
8.18.2
68
8.18.1
79
8.18.0
10+
8.17.10
811
8.17.9
912
8.17.8
1013
8.17.7

ci/supported-es-versions/es9x.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
9.1.1
22
9.1.0
3+
9.0.5
34
9.0.4
45
9.0.3
56
9.0.2

es816x/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
latestSupportedEsVersion=8.17.9
1+
latestSupportedEsVersion=8.17.10

es818x/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
latestSupportedEsVersion=8.19.1
1+
latestSupportedEsVersion=8.19.2

es818x/src/main/scala/tech/beshu/ror/es/actions/rrauditevent/rest/RestRRAuditEventAction.scala

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,31 @@
1616
*/
1717
package tech.beshu.ror.es.actions.rrauditevent.rest
1818

19-
import java.util
20-
2119
import org.elasticsearch.ElasticsearchException
2220
import org.elasticsearch.client.internal.node.NodeClient
21+
import org.elasticsearch.common.bytes.BytesReference
2322
import org.elasticsearch.common.xcontent.XContentHelper
23+
import org.elasticsearch.rest.*
2424
import org.elasticsearch.rest.BaseRestHandler.RestChannelConsumer
2525
import org.elasticsearch.rest.RestHandler.Route
2626
import org.elasticsearch.rest.RestRequest.Method.POST
27-
import org.elasticsearch.rest.*
27+
import org.elasticsearch.xcontent.{DeprecationHandler, NamedXContentRegistry, XContentFactory, XContentParser, XContentParserConfiguration, XContentType}
2828
import org.json.JSONObject
2929
import squants.information.{Bytes, Information}
3030
import tech.beshu.ror.constants
3131
import tech.beshu.ror.es.actions.rrauditevent.{RRAuditEventActionType, RRAuditEventRequest}
3232

33+
import java.util
3334
import scala.jdk.CollectionConverters.*
34-
import scala.util.Try
35+
import scala.util.{Try, Using}
3536

3637
class RestRRAuditEventAction
3738
extends BaseRestHandler with RestHandler {
3839

40+
private val strictParserConfig = XContentParserConfiguration.EMPTY
41+
.withRegistry(NamedXContentRegistry.EMPTY)
42+
.withDeprecationHandler(DeprecationHandler.THROW_UNSUPPORTED_OPERATION)
43+
3944
override def routes(): util.List[Route] = List(
4045
new Route(POST, constants.AUDIT_EVENT_COLLECTOR_PATH)
4146
).asJava
@@ -70,12 +75,26 @@ class RestRRAuditEventAction
7075

7176
private def validateBodyJson(request: RestRequest) = Try {
7277
if (request.hasContent) {
73-
new JSONObject(XContentHelper.convertToMap(request.requiredContent(), false, request.getXContentType).v2())
78+
new JSONObject(asStrictMap(request.requiredContent(), request.getXContentType).asJava)
7479
} else {
7580
new JSONObject()
7681
}
7782
}.toEither.left.map(_ => new AuditEventBadRequest)
7883

84+
private def asStrictMap(bytes: BytesReference, contentType: XContentType): Map[String, Any] = {
85+
val map = XContentHelper.convertToMap(bytes, false, contentType).v2().asScala
86+
if (map.nonEmpty || isExactlyEmptyObject(bytes, contentType)) map.toMap
87+
else throw new IllegalArgumentException("Malformed request body")
88+
}
89+
90+
private def isExactlyEmptyObject(bytes: BytesReference, t: XContentType): Boolean = {
91+
Using.resource(XContentFactory.xContent(t).createParser(strictParserConfig, bytes.streamInput())) { p =>
92+
(p.nextToken() == XContentParser.Token.START_OBJECT) &&
93+
(p.nextToken() == XContentParser.Token.END_OBJECT) &&
94+
p.nextToken() == null // no trailing data
95+
}
96+
}
97+
7998
private class AuditEventBadRequest extends ElasticsearchException("Content malformed") {
8099
override def status(): RestStatus = RestStatus.BAD_REQUEST
81100
}

es90x/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
latestSupportedEsVersion=9.0.4
1+
latestSupportedEsVersion=9.0.5

0 commit comments

Comments
 (0)