Skip to content

Commit 6f1cbf0

Browse files
jowg-amazonAWSHurneyt
authored andcommitted
[Backport 2.x] Update dependency com.pinterest:ktlint to 0.47.1 and fix CVE-2023-6378 for common-utils (opensearch-project#588)
* add logback-classic for CVE-2023-6378 Signed-off-by: Joanne Wang <jowg@amazon.com> * updated com.pinterest:ktlint to v0.47.1 Signed-off-by: jowg-amazon <jowg@amazon.com> * ran ./gradlew ktlintformat Signed-off-by: jowg-amazon <jowg@amazon.com> --------- Signed-off-by: Joanne Wang <jowg@amazon.com> Signed-off-by: jowg-amazon <jowg@amazon.com> Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
1 parent 0fd0e2e commit 6f1cbf0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+264
-117
lines changed

build.gradle

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ apply plugin: 'opensearch.repositories'
6666
apply from: 'build-tools/opensearchplugin-coverage.gradle'
6767

6868
configurations {
69-
ktlint
69+
ktlint {
70+
resolutionStrategy {
71+
force "ch.qos.logback:logback-classic:1.3.14"
72+
force "ch.qos.logback:logback-core:1.3.14"
73+
}
74+
}
7075
}
7176

7277
dependencies {
@@ -86,7 +91,7 @@ dependencies {
8691
testImplementation "commons-validator:commons-validator:1.7"
8792
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
8893

89-
ktlint "com.pinterest:ktlint:0.44.0"
94+
ktlint "com.pinterest:ktlint:0.47.1"
9095
}
9196

9297
test {
@@ -226,4 +231,4 @@ task updateVersion {
226231
// Include the required files that needs to be updated with new Version
227232
ant.replaceregexp(file:'build.gradle', match: '"opensearch.version", "\\d.*"', replace: '"opensearch.version", "' + newVersion.tokenize('-')[0] + '-SNAPSHOT"', flags:'g', byline:true)
228233
}
229-
}
234+
}

src/main/kotlin/org/opensearch/commons/alerting/action/AcknowledgeChainedAlertRequest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AcknowledgeChainedAlertRequest : ActionRequest {
1919

2020
constructor(
2121
workflowId: String,
22-
alertIds: List<String>,
22+
alertIds: List<String>
2323
) : super() {
2424
this.workflowId = workflowId
2525
this.alertIds = alertIds
@@ -28,7 +28,7 @@ class AcknowledgeChainedAlertRequest : ActionRequest {
2828
@Throws(IOException::class)
2929
constructor(sin: StreamInput) : this(
3030
sin.readString(), // workflowId
31-
Collections.unmodifiableList(sin.readStringList()), // alertIds
31+
Collections.unmodifiableList(sin.readStringList()) // alertIds
3232
)
3333

3434
override fun validate(): ActionRequestValidationException? {

src/main/kotlin/org/opensearch/commons/alerting/action/AlertingActions.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ object AlertingActions {
2929
@JvmField
3030
val INDEX_WORKFLOW_ACTION_TYPE =
3131
ActionType(INDEX_WORKFLOW_ACTION_NAME, ::IndexWorkflowResponse)
32+
3233
@JvmField
3334
val GET_ALERTS_ACTION_TYPE =
3435
ActionType(GET_ALERTS_ACTION_NAME, ::GetAlertsResponse)
@@ -48,6 +49,7 @@ object AlertingActions {
4849
@JvmField
4950
val DELETE_WORKFLOW_ACTION_TYPE =
5051
ActionType(DELETE_WORKFLOW_ACTION_NAME, ::DeleteWorkflowResponse)
52+
5153
@JvmField
5254
val GET_FINDINGS_ACTION_TYPE =
5355
ActionType(GET_FINDINGS_ACTION_NAME, ::GetFindingsResponse)

src/main/kotlin/org/opensearch/commons/alerting/action/DeleteWorkflowRequest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import java.io.IOException
99
class DeleteWorkflowRequest : ActionRequest {
1010

1111
val workflowId: String
12+
1213
/**
1314
* Flag that indicates whether the delegate monitors should be deleted or not.
1415
* If the flag is set to true, Delegate monitors will be deleted only in the case when they are part of the specified workflow and no other.

src/main/kotlin/org/opensearch/commons/alerting/action/GetMonitorRequest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class GetMonitorRequest : ActionRequest {
3838
sin.readEnum(RestRequest.Method::class.java), // method
3939
if (sin.readBoolean()) {
4040
FetchSourceContext(sin) // srcContext
41-
} else null
41+
} else {
42+
null
43+
}
4244
)
4345

4446
override fun validate(): ActionRequestValidationException? {

src/main/kotlin/org/opensearch/commons/alerting/action/GetMonitorResponse.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class GetMonitorResponse : BaseResponse {
3232
seqNo: Long,
3333
primaryTerm: Long,
3434
monitor: Monitor?,
35-
associatedCompositeMonitors: List<AssociatedWorkflow>?,
35+
associatedCompositeMonitors: List<AssociatedWorkflow>?
3636
) : super() {
3737
this.id = id
3838
this.version = version
@@ -50,8 +50,10 @@ class GetMonitorResponse : BaseResponse {
5050
primaryTerm = sin.readLong(), // primaryTerm
5151
monitor = if (sin.readBoolean()) {
5252
Monitor.readFrom(sin) // monitor
53-
} else null,
54-
associatedCompositeMonitors = sin.readList((AssociatedWorkflow)::readFrom),
53+
} else {
54+
null
55+
},
56+
associatedCompositeMonitors = sin.readList((AssociatedWorkflow)::readFrom)
5557
)
5658

5759
@Throws(IOException::class)

src/main/kotlin/org/opensearch/commons/alerting/action/GetWorkflowAlertsRequest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class GetWorkflowAlertsRequest : ActionRequest {
2727
monitorIds: List<String>? = null,
2828
workflowIds: List<String>? = null,
2929
alertIds: List<String>? = null,
30-
getAssociatedAlerts: Boolean,
30+
getAssociatedAlerts: Boolean
3131
) : super() {
3232
this.table = table
3333
this.severityLevel = severityLevel

src/main/kotlin/org/opensearch/commons/alerting/action/GetWorkflowAlertsResponse.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import java.util.Collections
1212
class GetWorkflowAlertsResponse : BaseResponse {
1313
val alerts: List<Alert>
1414
val associatedAlerts: List<Alert>
15+
1516
// totalAlerts is not the same as the size of alerts because there can be 30 alerts from the request, but
1617
// the request only asked for 5 alerts, so totalAlerts will be 30, but alerts will only contain 5 alerts
1718
val totalAlerts: Int?

src/main/kotlin/org/opensearch/commons/alerting/action/GetWorkflowResponse.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ class GetWorkflowResponse : BaseResponse {
5151
sin.readEnum(RestStatus::class.java), // RestStatus
5252
if (sin.readBoolean()) {
5353
Workflow.readFrom(sin) // monitor
54-
} else null
54+
} else {
55+
null
56+
}
5557
)
5658

5759
@Throws(IOException::class)
@@ -76,8 +78,9 @@ class GetWorkflowResponse : BaseResponse {
7678
.field(_VERSION, version)
7779
.field(_SEQ_NO, seqNo)
7880
.field(_PRIMARY_TERM, primaryTerm)
79-
if (workflow != null)
81+
if (workflow != null) {
8082
builder.field("workflow", workflow)
83+
}
8184

8285
return builder.endObject()
8386
}

src/main/kotlin/org/opensearch/commons/alerting/action/IndexWorkflowRequest.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,55 +57,61 @@ class IndexWorkflowRequest : ActionRequest {
5757

5858
if (workflow.inputs.isEmpty()) {
5959
validationException = ValidateActions.addValidationError(
60-
"Input list can not be empty.", validationException
60+
"Input list can not be empty.",
61+
validationException
6162
)
6263
return validationException
6364
}
6465
if (workflow.inputs.size > 1) {
6566
validationException = ValidateActions.addValidationError(
66-
"Input list can contain only one element.", validationException
67+
"Input list can contain only one element.",
68+
validationException
6769
)
6870
return validationException
6971
}
7072
if (workflow.inputs[0] !is CompositeInput) {
7173
validationException = ValidateActions.addValidationError(
72-
"When creating a workflow input must be CompositeInput", validationException
74+
"When creating a workflow input must be CompositeInput",
75+
validationException
7376
)
7477
}
7578
val compositeInput = workflow.inputs[0] as CompositeInput
7679
val monitorIds = compositeInput.sequence.delegates.stream().map { it.monitorId }.collect(Collectors.toList())
7780

7881
if (monitorIds.isNullOrEmpty()) {
7982
validationException = ValidateActions.addValidationError(
80-
"Delegates list can not be empty.", validationException
83+
"Delegates list can not be empty.",
84+
validationException
8185
)
8286
// Break the flow because next checks are dependant on non-null monitorIds
8387
return validationException
8488
}
8589

8690
if (monitorIds.size > MAX_DELEGATE_SIZE) {
8791
validationException = ValidateActions.addValidationError(
88-
"Delegates list can not be larger then $MAX_DELEGATE_SIZE.", validationException
92+
"Delegates list can not be larger then $MAX_DELEGATE_SIZE.",
93+
validationException
8994
)
9095
}
9196

9297
if (monitorIds.toSet().size != monitorIds.size) {
9398
validationException = ValidateActions.addValidationError(
94-
"Duplicate delegates not allowed", validationException
99+
"Duplicate delegates not allowed",
100+
validationException
95101
)
96102
}
97103
val delegates = compositeInput.sequence.delegates
98104
val orderSet = delegates.stream().filter { it.order > 0 }.map { it.order }.collect(Collectors.toSet())
99105
if (orderSet.size != delegates.size) {
100106
validationException = ValidateActions.addValidationError(
101-
"Sequence ordering of delegate monitor shouldn't contain duplicate order values", validationException
107+
"Sequence ordering of delegate monitor shouldn't contain duplicate order values",
108+
validationException
102109
)
103110
}
104111

105112
val monitorIdOrderMap: Map<String, Int> = delegates.associate { it.monitorId to it.order }
106113
delegates.forEach {
107114
if (it.chainedMonitorFindings != null) {
108-
109115
if (it.chainedMonitorFindings.monitorId != null) {
110116
if (monitorIdOrderMap.containsKey(it.chainedMonitorFindings.monitorId) == false) {
111117
validationException = ValidateActions.addValidationError(

0 commit comments

Comments
 (0)