Skip to content

Commit

Permalink
ktlint change (#830)
Browse files Browse the repository at this point in the history
Signed-off-by: zhichao-aws <[email protected]>
  • Loading branch information
zhichao-aws authored Dec 18, 2023
1 parent 309dcc3 commit dd5a2dc
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 29 deletions.
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 @@ -41,7 +41,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 @@ -45,14 +45,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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dd5a2dc

Please sign in to comment.