Skip to content

Commit fed6838

Browse files
authored
[Backport 2.x] Update dependency com.pinterest:ktlint to 0.47.1 and fix CVE-2023-6378 for common-utils (#588)
* add logback-classic for CVE-2023-6378 Signed-off-by: Joanne Wang <[email protected]> * updated com.pinterest:ktlint to v0.47.1 Signed-off-by: jowg-amazon <[email protected]> * ran ./gradlew ktlintformat Signed-off-by: jowg-amazon <[email protected]> --------- Signed-off-by: Joanne Wang <[email protected]> Signed-off-by: jowg-amazon <[email protected]>
1 parent 6a579cd commit fed6838

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

+8-3
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

+2-2
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

+2
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

+1
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

+3-1
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

+5-3
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

+1-1
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

+1
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

+5-2
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

+14-8
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(

src/main/kotlin/org/opensearch/commons/alerting/aggregation/bucketselectorext/BucketSelectorExtAggregator.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class BucketSelectorExtAggregator : SiblingPipelineAggregator {
3333
script: Script,
3434
gapPolicy: BucketHelpers.GapPolicy,
3535
filter: BucketSelectorExtFilter?,
36-
metadata: Map<String, Any>?,
36+
metadata: Map<String, Any>?
3737
) : super(name, bucketsPathsMap.values.toTypedArray(), metadata) {
3838
this.bucketsPathsMap = bucketsPathsMap
3939
this.parentBucketPath = parentBucketPath
@@ -132,7 +132,7 @@ class BucketSelectorExtAggregator : SiblingPipelineAggregator {
132132
name(),
133133
parentBucketPath,
134134
selectedBucketsIndex,
135-
originalAgg.metadata,
135+
originalAgg.metadata
136136
)
137137
}
138138

src/main/kotlin/org/opensearch/commons/alerting/model/Alert.kt

+13-6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ data class Alert(
4343
val aggregationResultBucket: AggregationResultBucket? = null,
4444
val executionId: String? = null,
4545
val associatedAlertIds: List<String>,
46-
val clusters: List<String>? = null,
46+
val clusters: List<String>? = null
4747
) : Writeable, ToXContent {
4848

4949
init {
50-
if (errorMessage != null) require(state == State.DELETED || state == State.ERROR || state == State.AUDIT) {
51-
"Attempt to create an alert with an error in state: $state"
50+
if (errorMessage != null) {
51+
require(state == State.DELETED || state == State.ERROR || state == State.AUDIT) {
52+
"Attempt to create an alert with an error in state: $state"
53+
}
5254
}
5355
}
5456

@@ -308,7 +310,9 @@ data class Alert(
308310
monitorVersion = sin.readLong(),
309311
monitorUser = if (sin.readBoolean()) {
310312
User(sin)
311-
} else null,
313+
} else {
314+
null
315+
},
312316
triggerId = sin.readString(),
313317
triggerName = sin.readString(),
314318
findingIds = sin.readStringList(),
@@ -439,8 +443,11 @@ data class Alert(
439443
MONITOR_NAME_FIELD -> monitorName = xcp.text()
440444
MONITOR_VERSION_FIELD -> monitorVersion = xcp.longValue()
441445
MONITOR_USER_FIELD ->
442-
monitorUser = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) null
443-
else User.parse(xcp)
446+
monitorUser = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) {
447+
null
448+
} else {
449+
User.parse(xcp)
450+
}
444451
TRIGGER_ID_FIELD -> triggerId = xcp.text()
445452
FINDING_IDS -> {
446453
ensureExpectedToken(XContentParser.Token.START_ARRAY, xcp.currentToken(), xcp)

src/main/kotlin/org/opensearch/commons/alerting/model/ChainedMonitorFindings.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import java.util.Collections
1717
// TODO - Remove the class and move the monitorId to Delegate (as a chainedMonitorId property) if this class won't be updated by adding new properties
1818
data class ChainedMonitorFindings(
1919
val monitorId: String? = null,
20-
val monitorIds: List<String> = emptyList(), // if monitorId field is non-null it would be given precendence for BWC
20+
val monitorIds: List<String> = emptyList() // if monitorId field is non-null it would be given precendence for BWC
2121
) : BaseModel {
2222

2323
init {
@@ -75,8 +75,9 @@ data class ChainedMonitorFindings(
7575

7676
when (fieldName) {
7777
MONITOR_ID_FIELD -> {
78-
if (!xcp.currentToken().equals(XContentParser.Token.VALUE_NULL))
78+
if (!xcp.currentToken().equals(XContentParser.Token.VALUE_NULL)) {
7979
monitorId = xcp.text()
80+
}
8081
}
8182

8283
MONITOR_IDS_FIELD -> {

src/main/kotlin/org/opensearch/commons/alerting/model/ClusterMetricsInput.kt

+20-10
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ data class ClusterMetricsInput(
4545
"Invalid URI constructed from the path and path_params inputs, or the url input."
4646
}
4747

48-
if (url.isNotEmpty() && validateFieldsNotEmpty())
48+
if (url.isNotEmpty() && validateFieldsNotEmpty()) {
4949
require(constructedUri == constructUrlFromInputs()) {
5050
"The provided URL and URI fields form different URLs."
5151
}
52+
}
5253

5354
require(constructedUri.host.lowercase() == SUPPORTED_HOST) {
5455
"Only host '$SUPPORTED_HOST' is supported."
@@ -109,7 +110,8 @@ data class ClusterMetricsInput(
109110
/**
110111
* This parse function uses [XContentParser] to parse JSON input and store corresponding fields to create a [ClusterMetricsInput] object
111112
*/
112-
@JvmStatic @Throws(IOException::class)
113+
@JvmStatic
114+
@Throws(IOException::class)
113115
fun parseInner(xcp: XContentParser): ClusterMetricsInput {
114116
var path = ""
115117
var pathParams = ""
@@ -175,17 +177,20 @@ data class ClusterMetricsInput(
175177
if (pathParams.isNotEmpty()) {
176178
pathParams = pathParams.trim('/')
177179
ILLEGAL_PATH_PARAMETER_CHARACTERS.forEach { character ->
178-
if (pathParams.contains(character))
180+
if (pathParams.contains(character)) {
179181
throw IllegalArgumentException(
180182
"The provided path parameters contain invalid characters or spaces. Please omit: " + ILLEGAL_PATH_PARAMETER_CHARACTERS.joinToString(" ")
181183
)
184+
}
182185
}
183186
}
184187

185-
if (apiType.requiresPathParams && pathParams.isEmpty())
188+
if (apiType.requiresPathParams && pathParams.isEmpty()) {
186189
throw IllegalArgumentException("The API requires path parameters.")
187-
if (!apiType.supportsPathParams && pathParams.isNotEmpty())
190+
}
191+
if (!apiType.supportsPathParams && pathParams.isNotEmpty()) {
188192
throw IllegalArgumentException("The API does not use path parameters.")
193+
}
189194

190195
return pathParams
191196
}
@@ -201,11 +206,13 @@ data class ClusterMetricsInput(
201206
ClusterMetricType.values()
202207
.filter { option -> option != ClusterMetricType.BLANK }
203208
.forEach { option ->
204-
if (uriPath.startsWith(option.prependPath) || uriPath.startsWith(option.defaultPath))
209+
if (uriPath.startsWith(option.prependPath) || uriPath.startsWith(option.defaultPath)) {
205210
apiType = option
211+
}
206212
}
207-
if (apiType.isBlank())
213+
if (apiType.isBlank()) {
208214
throw IllegalArgumentException("The API could not be determined from the provided URI.")
215+
}
209216
return apiType
210217
}
211218

@@ -238,12 +245,15 @@ data class ClusterMetricsInput(
238245
* If [path] and [pathParams] are empty, populates them with values from [url].
239246
*/
240247
private fun parseEmptyFields() {
241-
if (pathParams.isEmpty())
248+
if (pathParams.isEmpty()) {
242249
pathParams = this.parsePathParams()
243-
if (path.isEmpty())
250+
}
251+
if (path.isEmpty()) {
244252
path = if (pathParams.isEmpty()) clusterMetricType.defaultPath else clusterMetricType.prependPath
245-
if (url.isEmpty())
253+
}
254+
if (url.isEmpty()) {
246255
url = constructedUri.toString()
256+
}
247257
}
248258

249259
/**

src/main/kotlin/org/opensearch/commons/alerting/model/CompositeInput.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.opensearch.core.xcontent.XContentParserUtils
1212
import java.io.IOException
1313

1414
data class CompositeInput(
15-
val sequence: Sequence,
15+
val sequence: Sequence
1616
) : WorkflowInput {
1717
@Throws(IOException::class)
1818
constructor(sin: StreamInput) : this(
@@ -53,7 +53,8 @@ data class CompositeInput(
5353

5454
val XCONTENT_REGISTRY = NamedXContentRegistry.Entry(
5555
WorkflowInput::class.java,
56-
ParseField(COMPOSITE_INPUT_FIELD), CheckedFunction { CompositeInput.parse(it) }
56+
ParseField(COMPOSITE_INPUT_FIELD),
57+
CheckedFunction { CompositeInput.parse(it) }
5758
)
5859

5960
@JvmStatic

0 commit comments

Comments
 (0)