Skip to content

Commit

Permalink
Bump ktlint version to fix CVE (#850)
Browse files Browse the repository at this point in the history
Signed-off-by: Chase Engelbrecht <[email protected]>
  • Loading branch information
engechas authored Feb 6, 2024
1 parent b0196d4 commit cfe5e69
Show file tree
Hide file tree
Showing 25 changed files with 113 additions and 55 deletions.
2 changes: 1 addition & 1 deletion notifications/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ configurations {
}

dependencies {
add("ktlint", "com.pinterest:ktlint:0.44.0") {
add("ktlint", "com.pinterest:ktlint:0.47.1") {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ package org.opensearch.notifications.spi.model.destination
* This class holds the contents of a Chime destination
*/
class ChimeDestination(
url: String,
url: String
) : WebhookDestination(url, DestinationType.CHIME)
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ package org.opensearch.notifications.spi.model.destination
* This class holds the contents of a Microsoft Teams destination
*/
class MicrosoftTeamsDestination(
url: String,
url: String
) : WebhookDestination(url, DestinationType.MICROSOFT_TEAMS)
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ package org.opensearch.notifications.spi.model.destination
* This class holds the contents of a Slack destination
*/
class SlackDestination(
url: String,
url: String
) : WebhookDestination(url, DestinationType.SLACK)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package org.opensearch.notifications.spi.model.destination
*/
data class SnsDestination(
val topicArn: String,
val roleArn: String? = null,
val roleArn: String? = null
) : BaseDestination(DestinationType.SNS) {
// sample topic arn -> arn:aws:sns:us-west-2:075315751589:test-notification
val region: String = topicArn.split(":".toRegex()).toTypedArray()[3]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ internal class ValidationHelpersTests {
fun `validator identifies chime url as valid`() {
assert(isValidUrl(CHIME_URL))
}

@Test
fun `validator identifies microsoft teams url as valid`() {
assert(isValidUrl(MICROSOFT_TEAMS_WEBHOOK_URL))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class NotificationCorePlugin : ReloadablePlugin, Plugin(), ExtensiblePlugin {
const val PLUGIN_NAME = "opensearch-notifications-core"
const val LOG_PREFIX = "notifications-core"
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,28 @@ class DestinationHttpClient {
constructor() {
this.httpClient = createHttpClient()
}

@OpenForTesting
constructor(httpClient: CloseableHttpClient) {
this.httpClient = httpClient
}

companion object {
private val log by logger(DestinationHttpClient::class.java)

/**
* all valid response status
*/
private val VALID_RESPONSE_STATUS = Collections.unmodifiableSet(
HashSet(
listOf(
RestStatus.OK.status, RestStatus.CREATED.status, RestStatus.ACCEPTED.status,
RestStatus.NON_AUTHORITATIVE_INFORMATION.status, RestStatus.NO_CONTENT.status,
RestStatus.RESET_CONTENT.status, RestStatus.PARTIAL_CONTENT.status,
RestStatus.OK.status,
RestStatus.CREATED.status,
RestStatus.ACCEPTED.status,
RestStatus.NON_AUTHORITATIVE_INFORMATION.status,
RestStatus.NO_CONTENT.status,
RestStatus.RESET_CONTENT.status,
RestStatus.PARTIAL_CONTENT.status,
RestStatus.MULTI_STATUS.status
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,71 +294,83 @@ internal object PluginSettings {
EMAIL_SIZE_LIMIT_KEY,
defaultSettings[EMAIL_SIZE_LIMIT_KEY]!!.toInt(),
MINIMUM_EMAIL_SIZE_LIMIT,
NodeScope, Dynamic
NodeScope,
Dynamic
)

val EMAIL_MINIMUM_HEADER_LENGTH: Setting<Int> = Setting.intSetting(
EMAIL_MINIMUM_HEADER_LENGTH_KEY,
defaultSettings[EMAIL_MINIMUM_HEADER_LENGTH_KEY]!!.toInt(),
NodeScope, Dynamic
NodeScope,
Dynamic
)

val MAX_CONNECTIONS: Setting<Int> = Setting.intSetting(
MAX_CONNECTIONS_KEY,
defaultSettings[MAX_CONNECTIONS_KEY]!!.toInt(),
NodeScope, Dynamic
NodeScope,
Dynamic
)

val MAX_CONNECTIONS_PER_ROUTE: Setting<Int> = Setting.intSetting(
MAX_CONNECTIONS_PER_ROUTE_KEY,
defaultSettings[MAX_CONNECTIONS_PER_ROUTE_KEY]!!.toInt(),
NodeScope, Dynamic
NodeScope,
Dynamic
)

val CONNECTION_TIMEOUT_MILLISECONDS: Setting<Int> = Setting.intSetting(
CONNECTION_TIMEOUT_MILLISECONDS_KEY,
defaultSettings[CONNECTION_TIMEOUT_MILLISECONDS_KEY]!!.toInt(),
NodeScope, Dynamic
NodeScope,
Dynamic
)

val SOCKET_TIMEOUT_MILLISECONDS: Setting<Int> = Setting.intSetting(
SOCKET_TIMEOUT_MILLISECONDS_KEY,
defaultSettings[SOCKET_TIMEOUT_MILLISECONDS_KEY]!!.toInt(),
NodeScope, Dynamic
NodeScope,
Dynamic
)

val ALLOWED_CONFIG_TYPES: Setting<List<String>> = Setting.listSetting(
ALLOWED_CONFIG_TYPE_KEY,
DEFAULT_ALLOWED_CONFIG_TYPES,
{ it },
NodeScope, Dynamic
NodeScope,
Dynamic
)

val TOOLTIP_SUPPORT: Setting<Boolean> = Setting.boolSetting(
TOOLTIP_SUPPORT_KEY,
defaultSettings[TOOLTIP_SUPPORT_KEY]!!.toBoolean(),
NodeScope, Dynamic
NodeScope,
Dynamic
)

val LEGACY_ALERTING_HOST_DENY_LIST: Setting<List<String>> = Setting.listSetting(
LEGACY_ALERTING_HOST_DENY_LIST_KEY,
DEFAULT_HOST_DENY_LIST,
{ it },
NodeScope, Final, Deprecated
NodeScope,
Final,
Deprecated
)

val ALERTING_HOST_DENY_LIST: Setting<List<String>> = Setting.listSetting(
ALERTING_HOST_DENY_LIST_KEY,
LEGACY_ALERTING_HOST_DENY_LIST,
{ it },
NodeScope, Final
NodeScope,
Final
)

val HOST_DENY_LIST: Setting<List<String>> = Setting.listSetting(
HOST_DENY_LIST_KEY,
ALERTING_HOST_DENY_LIST,
{ it },
NodeScope, Dynamic
NodeScope,
Dynamic
)

private val LEGACY_EMAIL_USERNAME: Setting.AffixSetting<SecureString> = Setting.affixKeySetting(
Expand Down Expand Up @@ -415,6 +427,7 @@ internal object PluginSettings {
EMAIL_PASSWORD
)
}

/**
* Update the setting variables to setting values from local settings
* @param clusterService cluster service instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal class ChimeDestinationTests {
Arguments.of("\t", """\t"""),
Arguments.of("\b", """\b"""),
Arguments.of("\r", """\r"""),
Arguments.of("\"", """\""""),
Arguments.of("\"", """\"""")
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ internal class CustomWebhookDestinationTests {
Arguments.of("PUT", HttpPut::class.java),
Arguments.of("PATCH", HttpPatch::class.java)
)

@JvmStatic
fun escapeSequenceToRaw(): Stream<Arguments> =
Stream.of(
Arguments.of("\n", """\n"""),
Arguments.of("\t", """\t"""),
Arguments.of("\b", """\b"""),
Arguments.of("\r", """\r"""),
Arguments.of("\"", """\""""),
Arguments.of("\"", """\"""")
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal class MicrosoftTeamsDestinationTests {
Arguments.of("\t", """\t"""),
Arguments.of("\b", """\b"""),
Arguments.of("\r", """\r"""),
Arguments.of("\"", """\""""),
Arguments.of("\"", """\"""")
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal class SlackDestinationTests {
Arguments.of("\t", """\t"""),
Arguments.of("\b", """\b"""),
Arguments.of("\r", """\r"""),
Arguments.of("\"", """\""""),
Arguments.of("\"", """\"""")
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SmtpEmailTests {
"opensearch.data",
"base64",
"VGVzdCBtZXNzYWdlCgo=",
"application/octet-stream",
"application/octet-stream"
)
DestinationTransportProvider.destinationTransportMap = mapOf(DestinationType.SMTP to SmtpDestinationTransport())
val response = NotificationCoreImpl.sendMessage(smtpDestination, message, "ref")
Expand All @@ -77,7 +77,7 @@ class SmtpEmailTests {
"opensearch.data",
"base64",
"VGVzdCBtZXNzYWdlCgo=",
"application/octet-stream",
"application/octet-stream"
)
DestinationTransportProvider.destinationTransportMap = mapOf(DestinationType.SMTP to SmtpDestinationTransport())
val response = NotificationCoreImpl.sendMessage(smtpDestination, message, "ref")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ enum class Metrics(val metricName: String, val counter: Counter<*>) {
RollingCounter()
),
NOTIFICATIONS_EXCEPTIONS_VERSION_CONFLICT_ENGINE_EXCEPTION(
"exception.version_conflict_engine", RollingCounter()
"exception.version_conflict_engine",
RollingCounter()
),
NOTIFICATIONS_EXCEPTIONS_INDEX_NOT_FOUND_EXCEPTION(
"exception.index_not_found",
Expand Down Expand Up @@ -84,20 +85,24 @@ enum class Metrics(val metricName: String, val counter: Counter<*>) {
RollingCounter()
),
NOTIFICATIONS_CONFIG_UPDATE_USER_ERROR_INVALID_CONFIG_ID(
"notifications_config.update.user_error.invalid_config_id", RollingCounter()
"notifications_config.update.user_error.invalid_config_id",
RollingCounter()
),
NOTIFICATIONS_CONFIG_UPDATE_SYSTEM_ERROR(
"notifications_config.update.system_error",
RollingCounter()
), // Notification config general user error
NOTIFICATIONS_CONFIG_USER_ERROR_INVALID_EMAIL_ACCOUNT_ID(
"notifications_config.user_error.invalid_email_account_id", RollingCounter()
"notifications_config.user_error.invalid_email_account_id",
RollingCounter()
),
NOTIFICATIONS_CONFIG_USER_ERROR_INVALID_EMAIL_GROUP_ID(
"notifications_config.user_error.invalid_email_group_id", RollingCounter()
"notifications_config.user_error.invalid_email_group_id",
RollingCounter()
),
NOTIFICATIONS_CONFIG_USER_ERROR_NEITHER_EMAIL_NOR_GROUP(
"notifications_config.user_error.neither_email_nor_group", RollingCounter()
"notifications_config.user_error.neither_email_nor_group",
RollingCounter()
), // DELETE _plugins/_notifications/configs/{configId}, Delete a notification config
NOTIFICATIONS_CONFIG_DELETE_TOTAL(
"notifications_config.delete.total",
Expand All @@ -108,10 +113,12 @@ enum class Metrics(val metricName: String, val counter: Counter<*>) {
RollingCounter()
),
NOTIFICATIONS_CONFIG_DELETE_USER_ERROR_INVALID_CONFIG_ID(
"notifications_config.delete.user_error.invalid_config_id", RollingCounter()
"notifications_config.delete.user_error.invalid_config_id",
RollingCounter()
),
NOTIFICATIONS_CONFIG_DELETE_USER_ERROR_SET_NOT_FOUND(
"notifications_config.delete.user_error.set_not_found", RollingCounter()
"notifications_config.delete.user_error.set_not_found",
RollingCounter()
),
NOTIFICATIONS_CONFIG_DELETE_SYSTEM_ERROR(
"notifications_config.delete.system_error",
Expand All @@ -126,20 +133,25 @@ enum class Metrics(val metricName: String, val counter: Counter<*>) {
RollingCounter()
), // add specific user errors for config GET operations
NOTIFICATIONS_CONFIG_INFO_USER_ERROR_INVALID_CONFIG_ID(
"notifications_config.info.user_error.invalid_config_id", RollingCounter()
"notifications_config.info.user_error.invalid_config_id",
RollingCounter()
),
NOTIFICATIONS_CONFIG_INFO_USER_ERROR_SET_NOT_FOUND(
"notifications_config.info.user_error.set_not_found", RollingCounter()
"notifications_config.info.user_error.set_not_found",
RollingCounter()
),

// Feature Channels Endpoints
// GET _plugins/_notifications/channels
NOTIFICATIONS_CHANNELS_INFO_TOTAL(
"notifications_channels.info.total",
BasicCounter()
),
NOTIFICATIONS_CHANNELS_INFO_INTERVAL_COUNT(
"notifications_channels.info.count", RollingCounter()
"notifications_channels.info.count",
RollingCounter()
),

// Features Endpoints
// GET _plugins/_notifications/features
NOTIFICATIONS_FEATURES_INFO_TOTAL(
Expand All @@ -150,6 +162,7 @@ enum class Metrics(val metricName: String, val counter: Counter<*>) {
"notifications_features.info.count",
RollingCounter()
),

// Send Message Endpoints
// POST _plugins/_notifications/send
NOTIFICATIONS_SEND_MESSAGE_TOTAL(
Expand All @@ -161,7 +174,8 @@ enum class Metrics(val metricName: String, val counter: Counter<*>) {
RollingCounter()
), // user errors for send message?
NOTIFICATIONS_SEND_MESSAGE_USER_ERROR_NOT_FOUND(
"notifications.send_message.user_error.not_found", RollingCounter()
"notifications.send_message.user_error.not_found",
RollingCounter()
),
NOTIFICATIONS_MESSAGE_DESTINATION_SLACK(
"notifications.message_destination.slack",
Expand All @@ -184,26 +198,31 @@ enum class Metrics(val metricName: String, val counter: Counter<*>) {
BasicCounter()
),
NOTIFICATIONS_MESSAGE_DESTINATION_SES_ACCOUNT(
"notifications.message_destination.ses_account", BasicCounter()
"notifications.message_destination.ses_account",
BasicCounter()
),
NOTIFICATIONS_MESSAGE_DESTINATION_SMTP_ACCOUNT(
"notifications.message_destination.smtp_account", BasicCounter()
"notifications.message_destination.smtp_account",
BasicCounter()
),
NOTIFICATIONS_MESSAGE_DESTINATION_EMAIL_GROUP(
"notifications.message_destination.email_group", BasicCounter()
"notifications.message_destination.email_group",
BasicCounter()
), // TODO: add after implementation added
NOTIFICATIONS_MESSAGE_DESTINATION_SNS(
"notifications.message_destination.sns",
BasicCounter()
),

// Send Test Message Endpoints
// GET _plugins/_notifications/feature/test/{configId}
NOTIFICATIONS_SEND_TEST_MESSAGE_TOTAL(
"notifications.send_test_message.total",
BasicCounter()
),
NOTIFICATIONS_SEND_TEST_MESSAGE_INTERVAL_COUNT(
"notifications.send_test_message.interval_count", RollingCounter()
"notifications.send_test_message.interval_count",
RollingCounter()
), // Send test message exceptions are thrown by the Send Message Action
NOTIFICATIONS_SECURITY_USER_ERROR(
"security_user_error",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ object SendMessageActionHelper {
DestinationMessageResponse(RestStatus.FAILED_DEPENDENCY.status, "Failed to send notification")
}
}

/**
* Collects all child configs of the channel configurations (like email)
* @param channels list of NotificationConfigDocInfo
Expand Down
Loading

0 comments on commit cfe5e69

Please sign in to comment.