From dd5a2dc074be30c2006483beb3623381d656e82a Mon Sep 17 00:00:00 2001 From: zhichao-aws Date: Mon, 18 Dec 2023 11:54:53 +0800 Subject: [PATCH] ktlint change (#830) Signed-off-by: zhichao-aws --- .../spi/model/destination/ChimeDestination.kt | 2 +- .../destination/MicrosoftTeamsDestination.kt | 2 +- .../spi/model/destination/SlackDestination.kt | 2 +- .../spi/model/destination/SnsDestination.kt | 2 +- .../spi/utils/ValidationHelpersTests.kt | 1 + .../core/NotificationCorePlugin.kt | 1 + .../core/client/DestinationHttpClient.kt | 12 +++++-- .../core/setting/PluginSettings.kt | 35 +++++++++++++------ .../destinations/ChimeDestinationTests.kt | 2 +- .../CustomWebhookDestinationTests.kt | 3 +- .../MicrosoftTeamsDestinationTests.kt | 2 +- .../destinations/SlackDestinationTests.kt | 2 +- .../notifications/core/smtp/SmtpEmailTests.kt | 4 +-- .../send/SendMessageActionHelper.kt | 1 + .../send/SendTestMessageRestHandlerIT.kt | 2 ++ .../send/SendTestMessageWithMockServerIT.kt | 5 ++- .../index/ConfigIndexingActionsTests.kt | 12 +++++-- .../index/NotificationConfigIndexTests.kt | 3 +- 18 files changed, 64 insertions(+), 29 deletions(-) diff --git a/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/ChimeDestination.kt b/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/ChimeDestination.kt index a1b5c5f7..8d167381 100644 --- a/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/ChimeDestination.kt +++ b/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/ChimeDestination.kt @@ -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) diff --git a/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/MicrosoftTeamsDestination.kt b/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/MicrosoftTeamsDestination.kt index 7200795f..3d3b4d42 100644 --- a/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/MicrosoftTeamsDestination.kt +++ b/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/MicrosoftTeamsDestination.kt @@ -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) diff --git a/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/SlackDestination.kt b/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/SlackDestination.kt index eb99e83c..bd9a3e76 100644 --- a/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/SlackDestination.kt +++ b/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/SlackDestination.kt @@ -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) diff --git a/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/SnsDestination.kt b/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/SnsDestination.kt index 5b2ca208..d9b3ba36 100644 --- a/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/SnsDestination.kt +++ b/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/SnsDestination.kt @@ -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] diff --git a/notifications/core-spi/src/test/kotlin/org/opensearch/notifications/spi/utils/ValidationHelpersTests.kt b/notifications/core-spi/src/test/kotlin/org/opensearch/notifications/spi/utils/ValidationHelpersTests.kt index 57f4e129..bfc0290b 100644 --- a/notifications/core-spi/src/test/kotlin/org/opensearch/notifications/spi/utils/ValidationHelpersTests.kt +++ b/notifications/core-spi/src/test/kotlin/org/opensearch/notifications/spi/utils/ValidationHelpersTests.kt @@ -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)) diff --git a/notifications/core/src/main/kotlin/org/opensearch/notifications/core/NotificationCorePlugin.kt b/notifications/core/src/main/kotlin/org/opensearch/notifications/core/NotificationCorePlugin.kt index cfffb924..ada97fc1 100644 --- a/notifications/core/src/main/kotlin/org/opensearch/notifications/core/NotificationCorePlugin.kt +++ b/notifications/core/src/main/kotlin/org/opensearch/notifications/core/NotificationCorePlugin.kt @@ -41,6 +41,7 @@ class NotificationCorePlugin : ReloadablePlugin, Plugin(), ExtensiblePlugin { const val PLUGIN_NAME = "opensearch-notifications-core" const val LOG_PREFIX = "notifications-core" } + /** * {@inheritDoc} */ diff --git a/notifications/core/src/main/kotlin/org/opensearch/notifications/core/client/DestinationHttpClient.kt b/notifications/core/src/main/kotlin/org/opensearch/notifications/core/client/DestinationHttpClient.kt index e186eefe..406d242a 100644 --- a/notifications/core/src/main/kotlin/org/opensearch/notifications/core/client/DestinationHttpClient.kt +++ b/notifications/core/src/main/kotlin/org/opensearch/notifications/core/client/DestinationHttpClient.kt @@ -49,6 +49,7 @@ class DestinationHttpClient { constructor() { this.httpClient = createHttpClient() } + @OpenForTesting constructor(httpClient: CloseableHttpClient) { this.httpClient = httpClient @@ -56,15 +57,20 @@ class DestinationHttpClient { 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 ) ) diff --git a/notifications/core/src/main/kotlin/org/opensearch/notifications/core/setting/PluginSettings.kt b/notifications/core/src/main/kotlin/org/opensearch/notifications/core/setting/PluginSettings.kt index 75bbeb1b..bd32ead3 100644 --- a/notifications/core/src/main/kotlin/org/opensearch/notifications/core/setting/PluginSettings.kt +++ b/notifications/core/src/main/kotlin/org/opensearch/notifications/core/setting/PluginSettings.kt @@ -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 = Setting.intSetting( EMAIL_MINIMUM_HEADER_LENGTH_KEY, defaultSettings[EMAIL_MINIMUM_HEADER_LENGTH_KEY]!!.toInt(), - NodeScope, Dynamic + NodeScope, + Dynamic ) val MAX_CONNECTIONS: Setting = Setting.intSetting( MAX_CONNECTIONS_KEY, defaultSettings[MAX_CONNECTIONS_KEY]!!.toInt(), - NodeScope, Dynamic + NodeScope, + Dynamic ) val MAX_CONNECTIONS_PER_ROUTE: Setting = Setting.intSetting( MAX_CONNECTIONS_PER_ROUTE_KEY, defaultSettings[MAX_CONNECTIONS_PER_ROUTE_KEY]!!.toInt(), - NodeScope, Dynamic + NodeScope, + Dynamic ) val CONNECTION_TIMEOUT_MILLISECONDS: Setting = Setting.intSetting( CONNECTION_TIMEOUT_MILLISECONDS_KEY, defaultSettings[CONNECTION_TIMEOUT_MILLISECONDS_KEY]!!.toInt(), - NodeScope, Dynamic + NodeScope, + Dynamic ) val SOCKET_TIMEOUT_MILLISECONDS: Setting = Setting.intSetting( SOCKET_TIMEOUT_MILLISECONDS_KEY, defaultSettings[SOCKET_TIMEOUT_MILLISECONDS_KEY]!!.toInt(), - NodeScope, Dynamic + NodeScope, + Dynamic ) val ALLOWED_CONFIG_TYPES: Setting> = Setting.listSetting( ALLOWED_CONFIG_TYPE_KEY, DEFAULT_ALLOWED_CONFIG_TYPES, { it }, - NodeScope, Dynamic + NodeScope, + Dynamic ) val TOOLTIP_SUPPORT: Setting = Setting.boolSetting( TOOLTIP_SUPPORT_KEY, defaultSettings[TOOLTIP_SUPPORT_KEY]!!.toBoolean(), - NodeScope, Dynamic + NodeScope, + Dynamic ) val LEGACY_ALERTING_HOST_DENY_LIST: Setting> = 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> = Setting.listSetting( ALERTING_HOST_DENY_LIST_KEY, LEGACY_ALERTING_HOST_DENY_LIST, { it }, - NodeScope, Final + NodeScope, + Final ) val HOST_DENY_LIST: Setting> = Setting.listSetting( HOST_DENY_LIST_KEY, ALERTING_HOST_DENY_LIST, { it }, - NodeScope, Dynamic + NodeScope, + Dynamic ) private val LEGACY_EMAIL_USERNAME: Setting.AffixSetting = Setting.affixKeySetting( @@ -415,6 +427,7 @@ internal object PluginSettings { EMAIL_PASSWORD ) } + /** * Update the setting variables to setting values from local settings * @param clusterService cluster service instance diff --git a/notifications/core/src/test/kotlin/org/opensearch/notifications/core/destinations/ChimeDestinationTests.kt b/notifications/core/src/test/kotlin/org/opensearch/notifications/core/destinations/ChimeDestinationTests.kt index 1a036ad5..1ef6fa99 100644 --- a/notifications/core/src/test/kotlin/org/opensearch/notifications/core/destinations/ChimeDestinationTests.kt +++ b/notifications/core/src/test/kotlin/org/opensearch/notifications/core/destinations/ChimeDestinationTests.kt @@ -41,7 +41,7 @@ internal class ChimeDestinationTests { Arguments.of("\t", """\t"""), Arguments.of("\b", """\b"""), Arguments.of("\r", """\r"""), - Arguments.of("\"", """\""""), + Arguments.of("\"", """\"""") ) } diff --git a/notifications/core/src/test/kotlin/org/opensearch/notifications/core/destinations/CustomWebhookDestinationTests.kt b/notifications/core/src/test/kotlin/org/opensearch/notifications/core/destinations/CustomWebhookDestinationTests.kt index cb9d70ca..26aac9e8 100644 --- a/notifications/core/src/test/kotlin/org/opensearch/notifications/core/destinations/CustomWebhookDestinationTests.kt +++ b/notifications/core/src/test/kotlin/org/opensearch/notifications/core/destinations/CustomWebhookDestinationTests.kt @@ -45,6 +45,7 @@ internal class CustomWebhookDestinationTests { Arguments.of("PUT", HttpPut::class.java), Arguments.of("PATCH", HttpPatch::class.java) ) + @JvmStatic fun escapeSequenceToRaw(): Stream = Stream.of( @@ -52,7 +53,7 @@ internal class CustomWebhookDestinationTests { Arguments.of("\t", """\t"""), Arguments.of("\b", """\b"""), Arguments.of("\r", """\r"""), - Arguments.of("\"", """\""""), + Arguments.of("\"", """\"""") ) } diff --git a/notifications/core/src/test/kotlin/org/opensearch/notifications/core/destinations/MicrosoftTeamsDestinationTests.kt b/notifications/core/src/test/kotlin/org/opensearch/notifications/core/destinations/MicrosoftTeamsDestinationTests.kt index 1fffa8da..54ec06c5 100644 --- a/notifications/core/src/test/kotlin/org/opensearch/notifications/core/destinations/MicrosoftTeamsDestinationTests.kt +++ b/notifications/core/src/test/kotlin/org/opensearch/notifications/core/destinations/MicrosoftTeamsDestinationTests.kt @@ -43,7 +43,7 @@ internal class MicrosoftTeamsDestinationTests { Arguments.of("\t", """\t"""), Arguments.of("\b", """\b"""), Arguments.of("\r", """\r"""), - Arguments.of("\"", """\""""), + Arguments.of("\"", """\"""") ) } diff --git a/notifications/core/src/test/kotlin/org/opensearch/notifications/core/destinations/SlackDestinationTests.kt b/notifications/core/src/test/kotlin/org/opensearch/notifications/core/destinations/SlackDestinationTests.kt index edb21378..0175bf06 100644 --- a/notifications/core/src/test/kotlin/org/opensearch/notifications/core/destinations/SlackDestinationTests.kt +++ b/notifications/core/src/test/kotlin/org/opensearch/notifications/core/destinations/SlackDestinationTests.kt @@ -43,7 +43,7 @@ internal class SlackDestinationTests { Arguments.of("\t", """\t"""), Arguments.of("\b", """\b"""), Arguments.of("\r", """\r"""), - Arguments.of("\"", """\""""), + Arguments.of("\"", """\"""") ) } diff --git a/notifications/core/src/test/kotlin/org/opensearch/notifications/core/smtp/SmtpEmailTests.kt b/notifications/core/src/test/kotlin/org/opensearch/notifications/core/smtp/SmtpEmailTests.kt index 66f400c6..8fead489 100644 --- a/notifications/core/src/test/kotlin/org/opensearch/notifications/core/smtp/SmtpEmailTests.kt +++ b/notifications/core/src/test/kotlin/org/opensearch/notifications/core/smtp/SmtpEmailTests.kt @@ -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") @@ -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") diff --git a/notifications/notifications/src/main/kotlin/org/opensearch/notifications/send/SendMessageActionHelper.kt b/notifications/notifications/src/main/kotlin/org/opensearch/notifications/send/SendMessageActionHelper.kt index 083c01b0..5fdc3813 100644 --- a/notifications/notifications/src/main/kotlin/org/opensearch/notifications/send/SendMessageActionHelper.kt +++ b/notifications/notifications/src/main/kotlin/org/opensearch/notifications/send/SendMessageActionHelper.kt @@ -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 diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageRestHandlerIT.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageRestHandlerIT.kt index 9754494a..ce27c992 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageRestHandlerIT.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageRestHandlerIT.kt @@ -46,6 +46,7 @@ internal class SendTestMessageRestHandlerIT : PluginRestTestCase() { val error = sendResponse.get("error").asJsonObject Assert.assertNotNull(error.get("reason").asString) } + @Suppress("EmptyFunctionBlock") fun `test send test slack message`() { // Create webhook notification config @@ -78,6 +79,7 @@ internal class SendTestMessageRestHandlerIT : PluginRestTestCase() { val error = sendResponse.get("error").asJsonObject Assert.assertNotNull(error.get("reason").asString) } + @Suppress("EmptyFunctionBlock") fun `test send test microsoft teams message`() { // Create webhook notification config diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageWithMockServerIT.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageWithMockServerIT.kt index 74ed2d94..29a90714 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageWithMockServerIT.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageWithMockServerIT.kt @@ -46,7 +46,10 @@ internal class SendTestMessageWithMockServerIT : PluginRestTestCase() { // send test message val sendResponse = executeRequest( - RestRequest.Method.POST.name, "$PLUGIN_BASE_URI/feature/test/$configId", "", RestStatus.OK.status + RestRequest.Method.POST.name, + "$PLUGIN_BASE_URI/feature/test/$configId", + "", + RestStatus.OK.status ) logger.info(sendResponse) diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/notifications/index/ConfigIndexingActionsTests.kt b/notifications/notifications/src/test/kotlin/org/opensearch/notifications/index/ConfigIndexingActionsTests.kt index 2e510108..f4f25578 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/notifications/index/ConfigIndexingActionsTests.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/notifications/index/ConfigIndexingActionsTests.kt @@ -92,13 +92,19 @@ class ConfigIndexingActionsTests { fun initialize() { /* use reflection to get private method */ validateMicrosoftTeamsConfig = ConfigIndexingActions::class.java.getDeclaredMethod( - "validateMicrosoftTeamsConfig", MicrosoftTeams::class.java, User::class.java + "validateMicrosoftTeamsConfig", + MicrosoftTeams::class.java, + User::class.java ) validateSlackConfig = ConfigIndexingActions::class.java.getDeclaredMethod( - "validateSlackConfig", Slack::class.java, User::class.java + "validateSlackConfig", + Slack::class.java, + User::class.java ) validateChimeConfig = ConfigIndexingActions::class.java.getDeclaredMethod( - "validateChimeConfig", Chime::class.java, User::class.java + "validateChimeConfig", + Chime::class.java, + User::class.java ) validateMicrosoftTeamsConfig.isAccessible = true diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/notifications/index/NotificationConfigIndexTests.kt b/notifications/notifications/src/test/kotlin/org/opensearch/notifications/index/NotificationConfigIndexTests.kt index 6cb8c60a..51bf4251 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/notifications/index/NotificationConfigIndexTests.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/notifications/index/NotificationConfigIndexTests.kt @@ -62,7 +62,8 @@ class NotificationConfigIndexTests { fun initialize() { /* use reflection to get private method */ getSchemaVersionFromIndexMapping = NotificationConfigIndex::class.java.getDeclaredMethod( - "getSchemaVersionFromIndexMapping", Map::class.java + "getSchemaVersionFromIndexMapping", + Map::class.java ) getSchemaVersionFromIndexMapping.isAccessible = true