Skip to content

Commit

Permalink
adding addiional params findingIds, startTime and endTime
Browse files Browse the repository at this point in the history
Signed-off-by: Riya Saxena <[email protected]>
  • Loading branch information
riysaxen-amzn committed Feb 29, 2024
1 parent f03e2bc commit 99e3114
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.opensearch.commons.alerting.model.Table
import org.opensearch.core.common.io.stream.StreamInput
import org.opensearch.core.common.io.stream.StreamOutput
import java.io.IOException
import java.time.Instant

class GetFindingsRequest : ActionRequest {
val findingId: String?
Expand All @@ -15,6 +16,9 @@ class GetFindingsRequest : ActionRequest {
val findingIndex: String?
val severity: String?
val detectionType: String?
val findingIds: List<String>?
val startTime: Instant?
val endTime: Instant?

constructor(
findingId: String?,
Expand All @@ -23,7 +27,10 @@ class GetFindingsRequest : ActionRequest {
findingIndexName: String? = null,
monitorIds: List<String>? = null,
severity: String? = null,
detectionType: String? = null
detectionType: String? = null ,
findingIds: List<String>? = null,
startTime: Instant? = null,
endTime: Instant? = null
) : super() {
this.findingId = findingId
this.table = table
Expand All @@ -32,6 +39,9 @@ class GetFindingsRequest : ActionRequest {
this.monitorIds = monitorIds
this.severity = severity
this.detectionType = detectionType
this.findingIds = findingIds
this.startTime = startTime
this.endTime = endTime
}

@Throws(IOException::class)
Expand All @@ -42,7 +52,10 @@ class GetFindingsRequest : ActionRequest {
findingIndexName = sin.readOptionalString(),
monitorIds = sin.readOptionalStringList(),
severity = sin.readOptionalString(),
detectionType = sin.readOptionalString()
detectionType = sin.readOptionalString(),
findingIds = sin.readOptionalStringList(),
startTime = sin.readOptionalInstant(),
endTime = sin.readOptionalInstant()
)

override fun validate(): ActionRequestValidationException? {
Expand All @@ -58,5 +71,8 @@ class GetFindingsRequest : ActionRequest {
out.writeOptionalStringCollection(monitorIds)
out.writeOptionalString(severity)
out.writeOptionalString(detectionType)
out.writeOptionalStringCollection(findingIds)
out.writeOptionalInstant(startTime)
out.writeOptionalInstant(endTime)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import org.junit.jupiter.api.Test
import org.opensearch.common.io.stream.BytesStreamOutput
import org.opensearch.commons.alerting.model.Table
import org.opensearch.core.common.io.stream.StreamInput
import java.time.Instant

internal class GetFindingsRequestTests {


@Test
fun `test get findings request`() {
val table = Table("asc", "sortString", null, 1, 0, "")

val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2"), "severity", "detectionType")
val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2"), "severity", "detectionType", listOf("id1", "id2", ), Instant.now(), Instant.now().plusSeconds(30000))
assertNotNull(req)

val out = BytesStreamOutput()
Expand All @@ -31,13 +33,16 @@ internal class GetFindingsRequestTests {
assertEquals(table, newReq.table)
assertTrue(newReq.monitorIds!!.contains("1"))
assertTrue(newReq.monitorIds!!.contains("2"))
assertTrue(newReq.findingIds!!.contains("id1"))
assertTrue(newReq.findingIds!!.contains("id2"))
assertTrue(newReq.startTime!! < newReq.endTime, "startTime less than endTime")
}

@Test
fun `test validate returns null`() {
val table = Table("asc", "sortString", null, 1, 0, "")

val req = GetFindingsRequest("2121", table, "1", "active", listOf("1", "2"), "severity", "detectionType")
val req = GetFindingsRequest("2121", table, "1", "active", listOf("1", "2"), "severity", "detectionType", listOf("id1", "id2", ), Instant.now(), Instant.now().plusSeconds(30000))
assertNotNull(req)
assertNull(req.validate())
}
Expand Down

0 comments on commit 99e3114

Please sign in to comment.