Skip to content

Commit

Permalink
Update dependency com.pinterest:ktlint to 0.47.1 and fix CVE-2023-6378
Browse files Browse the repository at this point in the history
Signed-off-by: Megha Goyal <[email protected]>
  • Loading branch information
goyamegh committed Mar 14, 2024
1 parent 31322e1 commit 3623bc3
Show file tree
Hide file tree
Showing 21 changed files with 74 additions and 36 deletions.
1 change: 1 addition & 0 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ To build from the command line, use `./gradlew`.
./gradlew clean
./gradlew build
./gradlew publishToMavenLocal
./gradlew build --refresh-dependencies
```

### Using IntelliJ IDEA
Expand Down
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ apply plugin: 'opensearch.repositories'
apply from: 'build-tools/opensearchplugin-coverage.gradle'

configurations {
ktlint
ktlint {
resolutionStrategy {
force "ch.qos.logback:logback-classic:1.3.14"
force "ch.qos.logback:logback-core:1.3.14"
}
}
}

dependencies {
Expand All @@ -86,7 +91,7 @@ dependencies {
testImplementation "commons-validator:commons-validator:1.7"
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'

ktlint "com.pinterest:ktlint:0.44.0"
ktlint "com.pinterest:ktlint:0.47.1"
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ object AlertingActions {
@JvmField
val ACKNOWLEDGE_ALERTS_ACTION_TYPE =
ActionType(ACKNOWLEDGE_ALERTS_ACTION_NAME, ::AcknowledgeAlertResponse)

@JvmField
val SUBSCRIBE_FINDINGS_ACTION_TYPE =
ActionType(SUBSCRIBE_FINDINGS_ACTION_NAME, ::SubscribeFindingsResponse)
Expand Down
10 changes: 7 additions & 3 deletions src/main/kotlin/org/opensearch/commons/alerting/model/Alert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ data class Alert(
) : Writeable, ToXContent {

init {
if (errorMessage != null) require(state == State.DELETED || state == State.ERROR) {
"Attempt to create an alert with an error in state: $state"
if (errorMessage != null) {
require(state == State.DELETED || state == State.ERROR) {
"Attempt to create an alert with an error in state: $state"
}
}
}

Expand Down Expand Up @@ -157,7 +159,9 @@ data class Alert(
monitorVersion = sin.readLong(),
monitorUser = if (sin.readBoolean()) {
User(sin)
} else null,
} else {
null
},
triggerId = sin.readString(),
triggerName = sin.readString(),
findingIds = sin.readStringList(),
Expand Down
18 changes: 13 additions & 5 deletions src/main/kotlin/org/opensearch/commons/alerting/model/Monitor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ data class Monitor(
monitorType = sin.readEnum(MonitorType::class.java),
user = if (sin.readBoolean()) {
User(sin)
} else null,
} else {
null
},
schemaVersion = sin.readInt(),
inputs = sin.readList((Input)::readFrom),
triggers = sin.readList((Trigger)::readFrom),
Expand Down Expand Up @@ -184,8 +186,11 @@ data class Monitor(
// Outputting type with each Input so that the generic Input.readFrom() can read it
out.writeVInt(inputs.size)
inputs.forEach {
if (it is SearchInput) out.writeEnum(Input.Type.SEARCH_INPUT)
else out.writeEnum(Input.Type.DOCUMENT_LEVEL_INPUT)
if (it is SearchInput) {
out.writeEnum(Input.Type.SEARCH_INPUT)
} else {
out.writeEnum(Input.Type.DOCUMENT_LEVEL_INPUT)
}
it.writeTo(out)
}
// Outputting type with each Trigger so that the generic Trigger.readFrom() can read it
Expand Down Expand Up @@ -295,8 +300,11 @@ data class Monitor(
ENABLED_TIME_FIELD -> enabledTime = xcp.instant()
LAST_UPDATE_TIME_FIELD -> lastUpdateTime = xcp.instant()
UI_METADATA_FIELD -> uiMetadata = xcp.map()
DATA_SOURCES_FIELD -> dataSources = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) DataSources()
else DataSources.parse(xcp)
DATA_SOURCES_FIELD -> dataSources = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) {
DataSources()
} else {
DataSources.parse(xcp)
}
OWNER_FIELD -> owner = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) owner else xcp.text()
else -> {
xcp.skipChildren()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ data class NoOpTrigger(
override val id: String = UUIDs.base64UUID(),
override val name: String = "NoOp trigger",
override val severity: String = "",
override val actions: List<Action> = listOf(),
override val actions: List<Action> = listOf()
) : Trigger {

@Throws(IOException::class)
Expand Down Expand Up @@ -48,11 +48,13 @@ data class NoOpTrigger(
const val ID_FIELD = "id"
const val NOOP_TRIGGER_FIELD = "noop_trigger"
val XCONTENT_REGISTRY = NamedXContentRegistry.Entry(
Trigger::class.java, ParseField(NOOP_TRIGGER_FIELD),
Trigger::class.java,
ParseField(NOOP_TRIGGER_FIELD),
CheckedFunction { parseInner(it) }
)

@JvmStatic @Throws(IOException::class)
@JvmStatic
@Throws(IOException::class)
fun parseInner(xcp: XContentParser): NoOpTrigger {
var id = UUIDs.base64UUID()
if (xcp.currentToken() == XContentParser.Token.START_OBJECT) xcp.nextToken()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ data class Action(
NAME_FIELD -> name = xcp.textOrNull()
DESTINATION_ID_FIELD -> destinationId = xcp.textOrNull()
SUBJECT_TEMPLATE_FIELD -> {
subjectTemplate = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) null else {
subjectTemplate = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) {
null
} else {
Script.parse(xcp, Script.DEFAULT_TEMPLATE_LANG)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AlertTests {
assertEquals(
templateArgs[Alert.PARENTS_BUCKET_PATH],
alert.aggregationResultBucket?.parentBucketPath,
"Template args parentBucketPath does not match",
"Template args parentBucketPath does not match"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ fun randomDocumentLevelTrigger(
condition = condition,
actions = if (actions.isEmpty() && destinationId.isNotBlank()) {
(0..RandomNumbers.randomIntBetween(Random(), 0, 10)).map { randomAction(destinationId = destinationId) }
} else actions
} else {
actions
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class AcknowledgeAlertResponseTests {

@Test
fun `test acknowledge alert response`() {

val acknowledged = mutableListOf(
Alert(
"1234", 0L, 1, "monitor-1234", "test-monitor", 0L, randomUser(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class DeleteMonitorRequestTests {

@Test
fun `test delete monitor request`() {

val req = DeleteMonitorRequest("1234", WriteRequest.RefreshPolicy.IMMEDIATE)
Assert.assertNotNull(req)
Assert.assertEquals("1234", req.monitorId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ internal class GetAlertsRequestTests {

@Test
fun `test get alerts request`() {

val table = Table("asc", "sortString", null, 1, 0, "")

val req = GetAlertsRequest(table, "1", "active", null, null, listOf("1", "2"), listOf("alert1", "alert2"))
Expand All @@ -36,7 +35,6 @@ internal class GetAlertsRequestTests {

@Test
fun `test get alerts request with filter`() {

val table = Table("asc", "sortString", null, 1, 0, "")
val req = GetAlertsRequest(table, "1", "active", null, null)
assertNotNull(req)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ 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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ internal class GetFindingsResponseTests {

@Test
fun `test get findings response`() {

// Alerting GetFindingsResponse mock #1
val finding1 = Finding(
"1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ class IndexMonitorRequestTests {

@Test
fun `test index monitor post request`() {

val req = IndexMonitorRequest(
"1234", 1L, 2L, WriteRequest.RefreshPolicy.IMMEDIATE, RestRequest.Method.POST,
"1234",
1L,
2L,
WriteRequest.RefreshPolicy.IMMEDIATE,
RestRequest.Method.POST,
randomQueryLevelMonitor().copy(inputs = listOf(SearchInput(emptyList(), SearchSourceBuilder())))
)
Assertions.assertNotNull(req)
Expand All @@ -41,7 +44,11 @@ class IndexMonitorRequestTests {
@Test
fun `test index bucket monitor post request`() {
val req = IndexMonitorRequest(
"1234", 1L, 2L, WriteRequest.RefreshPolicy.IMMEDIATE, RestRequest.Method.POST,
"1234",
1L,
2L,
WriteRequest.RefreshPolicy.IMMEDIATE,
RestRequest.Method.POST,
randomBucketLevelMonitor()
)
Assertions.assertNotNull(req)
Expand All @@ -61,7 +68,11 @@ class IndexMonitorRequestTests {
@Test
fun `Index bucket monitor serialize and deserialize transport object should be equal`() {
val bucketLevelMonitorRequest = IndexMonitorRequest(
"1234", 1L, 2L, WriteRequest.RefreshPolicy.IMMEDIATE, RestRequest.Method.POST,
"1234",
1L,
2L,
WriteRequest.RefreshPolicy.IMMEDIATE,
RestRequest.Method.POST,
randomBucketLevelMonitor()
)

Expand All @@ -80,9 +91,12 @@ class IndexMonitorRequestTests {

@Test
fun `test index monitor put request`() {

val req = IndexMonitorRequest(
"1234", 1L, 2L, WriteRequest.RefreshPolicy.IMMEDIATE, RestRequest.Method.PUT,
"1234",
1L,
2L,
WriteRequest.RefreshPolicy.IMMEDIATE,
RestRequest.Method.PUT,
randomQueryLevelMonitor().copy(inputs = listOf(SearchInput(emptyList(), SearchSourceBuilder())))
)
Assertions.assertNotNull(req)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class FindingTests {
assertEquals(
templateArgs[Finding.MONITOR_NAME_FIELD],
finding.monitorName,
"Template args 'monitorName' field does not match:",
"Template args 'monitorName' field does not match:"
)
assertEquals(
templateArgs[Finding.QUERIES_FIELD],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,11 @@ class XContentTests {
fun `test alert parsing with noop trigger`() {
val monitor = randomQueryLevelMonitor()
val alert = Alert(
monitor = monitor, trigger = NoOpTrigger(), startTime = Instant.now().truncatedTo(ChronoUnit.MILLIS),
errorMessage = "some error", lastNotificationTime = Instant.now()
monitor = monitor,
trigger = NoOpTrigger(),
startTime = Instant.now().truncatedTo(ChronoUnit.MILLIS),
errorMessage = "some error",
lastNotificationTime = Instant.now()
)
assertEquals("Round tripping alert doesn't work", alert.triggerName, "NoOp trigger")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ internal class NotificationsPluginInterfaceTests {
}.whenever(client).execute(any(ActionType::class.java), any(), any())

NotificationsPluginInterface.sendNotification(
client, notificationInfo, channelMessage, listOf("channelId1", "channelId2"), listener
client,
notificationInfo,
channelMessage,
listOf("channelId1", "channelId2"),
listener
)
verify(listener, times(1)).onResponse(eq(response))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ internal class SendNotificationResponseTests {

@Test
fun `Create response serialize and deserialize transport object should be equal`() {

val sampleEvent = getSampleEvent()

val recreatedObject = recreateObject(sampleEvent) { SendNotificationResponse(it) }
Expand All @@ -31,7 +30,6 @@ internal class SendNotificationResponseTests {

@Test
fun `Create response serialize and deserialize using json object should be equal`() {

val sampleEvent = getSampleEvent()

val jsonString = getJsonString(sampleEvent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ internal class NotificationConfigTests {
}

@Test

fun `Config should safely ignore unknown config type in json object`() {
val sampleSlack = Slack("https://domain.com/sample_slack_url#1234567890")
val sampleConfig = NotificationConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ internal class SmtpAccountTests {
fun `SmtpAccount should safely ignore extra field in json object`() {
val sampleSmtpAccount = SmtpAccount(
"domain.com",
1234, MethodType.START_TLS,
1234,
MethodType.START_TLS,
"[email protected]"
)
val jsonString = """
Expand Down

0 comments on commit 3623bc3

Please sign in to comment.