Skip to content

Commit

Permalink
Added support for SesAccount (#54)
Browse files Browse the repository at this point in the history
Also updated Feature to be simple string for future plugin easy addition

[Tests]
Added unit tests for SesAccount
Updated Unit tests for changes

Signed-off-by: @akbhatta
  • Loading branch information
akbhatta committed Aug 13, 2021
1 parent b18a489 commit d79c53d
Show file tree
Hide file tree
Showing 27 changed files with 496 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ object NotificationConstants {
const val TAGS_TAG = "tags"
const val URL_TAG = "url"
const val HEADER_PARAMS_TAG = "header_params"
const val TOPIC_ARN_FIELD = "topic_arn"
const val ROLE_ARN_FIELD = "role_arn"
const val TOPIC_ARN_TAG = "topic_arn"
const val ROLE_ARN_TAG = "role_arn"
const val REGION_TAG = "region"
const val HOST_TAG = "host"
const val PORT_TAG = "port"
const val METHOD_TAG = "method"
Expand All @@ -69,5 +70,9 @@ object NotificationConstants {
const val CONFIG_TYPE_LIST_TAG = "config_type_list"
const val PLUGIN_FEATURES_TAG = "plugin_features"

const val FEATURE_ALERTING = "alerting"
const val FEATURE_INDEX_MANAGEMENT = "index_management"
const val FEATURE_REPORTS = "reports"

const val DEFAULT_MAX_ITEMS = 1000
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import org.opensearch.common.xcontent.XContentBuilder
import org.opensearch.common.xcontent.XContentParser
import org.opensearch.common.xcontent.XContentParserUtils
import org.opensearch.commons.notifications.NotificationConstants.FEATURE_TAG
import org.opensearch.commons.notifications.model.Feature
import org.opensearch.commons.utils.logger
import java.io.IOException

Expand All @@ -48,7 +47,7 @@ import java.io.IOException
* Hence the request also contains tenant info for space isolation.
*/
class GetFeatureChannelListRequest : ActionRequest, ToXContentObject {
val feature: Feature
val feature: String

companion object {
private val log by logger(GetFeatureChannelListRequest::class.java)
Expand All @@ -65,7 +64,7 @@ class GetFeatureChannelListRequest : ActionRequest, ToXContentObject {
@JvmStatic
@Throws(IOException::class)
fun parse(parser: XContentParser): GetFeatureChannelListRequest {
var feature: Feature? = null
var feature: String? = null

XContentParserUtils.ensureExpectedToken(
XContentParser.Token.START_OBJECT,
Expand All @@ -76,7 +75,7 @@ class GetFeatureChannelListRequest : ActionRequest, ToXContentObject {
val fieldName = parser.currentName()
parser.nextToken()
when (fieldName) {
FEATURE_TAG -> feature = Feature.fromTagOrDefault(parser.text())
FEATURE_TAG -> feature = parser.text()
else -> {
parser.skipChildren()
log.info("Unexpected field: $fieldName, while parsing GetFeatureChannelListRequest")
Expand All @@ -92,7 +91,7 @@ class GetFeatureChannelListRequest : ActionRequest, ToXContentObject {
* constructor for creating the class
* @param feature the caller plugin feature
*/
constructor(feature: Feature) {
constructor(feature: String) {
this.feature = feature
}

Expand All @@ -101,7 +100,7 @@ class GetFeatureChannelListRequest : ActionRequest, ToXContentObject {
*/
@Throws(IOException::class)
constructor(input: StreamInput) : super(input) {
feature = input.readEnum(Feature::class.java)
feature = input.readString()
}

/**
Expand All @@ -110,7 +109,7 @@ class GetFeatureChannelListRequest : ActionRequest, ToXContentObject {
@Throws(IOException::class)
override fun writeTo(output: StreamOutput) {
super.writeTo(output)
output.writeEnum(feature)
output.writeString(feature)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ enum class ConfigType(val tag: String) {
return tag
}
},
SES_ACCOUNT("ses_account") {
override fun toString(): String {
return tag
}
},
SMTP_ACCOUNT("smtp_account") {
override fun toString(): String {
return tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import java.io.IOException
data class EventSource(
val title: String,
val referenceId: String,
val feature: Feature,
val feature: String,
val severity: SeverityType = SeverityType.INFO,
val tags: List<String> = listOf()
) : BaseModel {
Expand All @@ -75,7 +75,7 @@ data class EventSource(
fun parse(parser: XContentParser): EventSource {
var title: String? = null
var referenceId: String? = null
var feature: Feature? = null
var feature: String? = null
var severity: SeverityType = SeverityType.INFO
var tags: List<String> = emptyList()

Expand All @@ -90,7 +90,7 @@ data class EventSource(
when (fieldName) {
TITLE_TAG -> title = parser.text()
REFERENCE_ID_TAG -> referenceId = parser.text()
FEATURE_TAG -> feature = Feature.fromTagOrDefault(parser.text())
FEATURE_TAG -> feature = parser.text()
SEVERITY_TAG -> severity = SeverityType.fromTagOrDefault(parser.text())
TAGS_TAG -> tags = parser.stringList()
else -> {
Expand Down Expand Up @@ -121,7 +121,7 @@ data class EventSource(
return builder.startObject()
.field(TITLE_TAG, title)
.field(REFERENCE_ID_TAG, referenceId)
.field(FEATURE_TAG, feature.tag)
.field(FEATURE_TAG, feature)
.field(SEVERITY_TAG, severity.tag)
.field(TAGS_TAG, tags)
.endObject()
Expand All @@ -134,7 +134,7 @@ data class EventSource(
constructor(input: StreamInput) : this(
title = input.readString(),
referenceId = input.readString(),
feature = input.readEnum(Feature::class.java),
feature = input.readString(),
severity = input.readEnum(SeverityType::class.java),
tags = input.readStringList()
)
Expand All @@ -145,7 +145,7 @@ data class EventSource(
override fun writeTo(output: StreamOutput) {
output.writeString(title)
output.writeString(referenceId)
output.writeEnum(feature)
output.writeString(feature)
output.writeEnum(severity)
output.writeStringCollection(tags)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ import org.opensearch.commons.notifications.NotificationConstants.NAME_TAG
import org.opensearch.commons.notifications.model.config.ConfigDataProperties.createConfigData
import org.opensearch.commons.notifications.model.config.ConfigDataProperties.getReaderForConfigType
import org.opensearch.commons.notifications.model.config.ConfigDataProperties.validateConfigData
import org.opensearch.commons.utils.enumSet
import org.opensearch.commons.utils.STRING_READER
import org.opensearch.commons.utils.STRING_WRITER
import org.opensearch.commons.utils.fieldIfNotNull
import org.opensearch.commons.utils.logger
import org.opensearch.commons.utils.stringList
import java.io.IOException
import java.util.EnumSet

/**
* Data class representing Notification config.
Expand All @@ -55,7 +56,7 @@ data class NotificationConfig(
val name: String,
val description: String,
val configType: ConfigType,
val features: EnumSet<Feature>,
val features: Set<String>,
val configData: BaseConfigData?,
val isEnabled: Boolean = true
) : BaseModel {
Expand Down Expand Up @@ -89,7 +90,7 @@ data class NotificationConfig(
var name: String? = null
var description = ""
var configType: ConfigType? = null
var features: EnumSet<Feature>? = null
var features: Set<String>? = null
var isEnabled = true
var configData: BaseConfigData? = null
XContentParserUtils.ensureExpectedToken(
Expand All @@ -104,7 +105,7 @@ data class NotificationConfig(
NAME_TAG -> name = parser.text()
DESCRIPTION_TAG -> description = parser.text()
CONFIG_TYPE_TAG -> configType = ConfigType.fromTagOrDefault(parser.text())
FEATURE_LIST_TAG -> features = parser.enumSet(Feature.enumParser)
FEATURE_LIST_TAG -> features = parser.stringList().toSet()
IS_ENABLED_TAG -> isEnabled = parser.booleanValue()
else -> {
val configTypeForTag = ConfigType.fromTagOrDefault(fieldName)
Expand Down Expand Up @@ -154,7 +155,7 @@ data class NotificationConfig(
name = input.readString(),
description = input.readString(),
configType = input.readEnum(ConfigType::class.java),
features = input.readEnumSet(Feature::class.java),
features = input.readSet(STRING_READER),
isEnabled = input.readBoolean(),
configData = input.readOptionalWriteable(getReaderForConfigType(input.readEnum(ConfigType::class.java)))
)
Expand All @@ -166,7 +167,7 @@ data class NotificationConfig(
output.writeString(name)
output.writeString(description)
output.writeEnum(configType)
output.writeEnumSet(features)
output.writeCollection(features, STRING_WRITER)
output.writeBoolean(isEnabled)
// Reading config types multiple times in constructor
output.writeEnum(configType)
Expand Down
Loading

0 comments on commit d79c53d

Please sign in to comment.