Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
merge to master (#289)
Browse files Browse the repository at this point in the history
* Resolve user, backendroles, roles from threadcontext instead of /authinfo rest call (#288)
  • Loading branch information
skkosuri-amzn authored Oct 28, 2020
1 parent 9986272 commit fc974fd
Show file tree
Hide file tree
Showing 23 changed files with 136 additions and 286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import com.amazon.opendistroforelasticsearch.alerting.action.AcknowledgeAlertAct
import com.amazon.opendistroforelasticsearch.alerting.action.DeleteDestinationAction
import com.amazon.opendistroforelasticsearch.alerting.action.DeleteEmailAccountAction
import com.amazon.opendistroforelasticsearch.alerting.action.DeleteEmailGroupAction
import com.amazon.opendistroforelasticsearch.alerting.action.IndexDestinationAction
import com.amazon.opendistroforelasticsearch.alerting.action.DeleteMonitorAction
import com.amazon.opendistroforelasticsearch.alerting.action.ExecuteMonitorAction
import com.amazon.opendistroforelasticsearch.alerting.action.GetEmailAccountAction
import com.amazon.opendistroforelasticsearch.alerting.action.GetEmailGroupAction
import com.amazon.opendistroforelasticsearch.alerting.action.GetAlertsAction
import com.amazon.opendistroforelasticsearch.alerting.action.GetDestinationsAction
import com.amazon.opendistroforelasticsearch.alerting.action.GetEmailAccountAction
import com.amazon.opendistroforelasticsearch.alerting.action.GetEmailGroupAction
import com.amazon.opendistroforelasticsearch.alerting.action.GetMonitorAction
import com.amazon.opendistroforelasticsearch.alerting.action.IndexDestinationAction
import com.amazon.opendistroforelasticsearch.alerting.action.IndexEmailAccountAction
import com.amazon.opendistroforelasticsearch.alerting.action.IndexEmailGroupAction
import com.amazon.opendistroforelasticsearch.alerting.action.IndexMonitorAction
Expand All @@ -49,10 +49,10 @@ import com.amazon.opendistroforelasticsearch.alerting.resthandler.RestDeleteEmai
import com.amazon.opendistroforelasticsearch.alerting.resthandler.RestDeleteEmailGroupAction
import com.amazon.opendistroforelasticsearch.alerting.resthandler.RestDeleteMonitorAction
import com.amazon.opendistroforelasticsearch.alerting.resthandler.RestExecuteMonitorAction
import com.amazon.opendistroforelasticsearch.alerting.resthandler.RestGetEmailAccountAction
import com.amazon.opendistroforelasticsearch.alerting.resthandler.RestGetEmailGroupAction
import com.amazon.opendistroforelasticsearch.alerting.resthandler.RestGetAlertsAction
import com.amazon.opendistroforelasticsearch.alerting.resthandler.RestGetDestinationsAction
import com.amazon.opendistroforelasticsearch.alerting.resthandler.RestGetEmailAccountAction
import com.amazon.opendistroforelasticsearch.alerting.resthandler.RestGetEmailGroupAction
import com.amazon.opendistroforelasticsearch.alerting.resthandler.RestGetMonitorAction
import com.amazon.opendistroforelasticsearch.alerting.resthandler.RestIndexDestinationAction
import com.amazon.opendistroforelasticsearch.alerting.resthandler.RestIndexEmailAccountAction
Expand All @@ -68,25 +68,23 @@ import com.amazon.opendistroforelasticsearch.alerting.transport.TransportAcknowl
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportDeleteDestinationAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportDeleteEmailAccountAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportDeleteEmailGroupAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportIndexDestinationAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportDeleteMonitorAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportExecuteMonitorAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportGetAlertsAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportGetDestinationsAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportGetEmailAccountAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportGetEmailGroupAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportGetAlertsAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportGetMonitorAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportIndexDestinationAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportIndexEmailAccountAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportIndexEmailGroupAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportIndexMonitorAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportSearchEmailAccountAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportSearchEmailGroupAction
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportSearchMonitorAction
import com.amazon.opendistroforelasticsearch.commons.rest.SecureRestClientBuilder
import com.amazon.opendistroforelasticsearch.alerting.transport.TransportGetDestinationsAction
import org.elasticsearch.action.ActionRequest
import org.elasticsearch.action.ActionResponse
import org.elasticsearch.client.Client
import org.elasticsearch.client.RestClient
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver
import org.elasticsearch.cluster.node.DiscoveryNodes
import org.elasticsearch.cluster.service.ClusterService
Expand Down Expand Up @@ -145,7 +143,6 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, R
lateinit var threadPool: ThreadPool
lateinit var alertIndices: AlertIndices
lateinit var clusterService: ClusterService
lateinit var restClient: RestClient

override fun getRestHandlers(
settings: Settings,
Expand All @@ -159,7 +156,7 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, R
return listOf(RestGetMonitorAction(),
RestDeleteMonitorAction(),
RestIndexMonitorAction(),
RestSearchMonitorAction(settings, clusterService, restClient),
RestSearchMonitorAction(settings, clusterService),
RestExecuteMonitorAction(),
RestAcknowledgeAlertAction(),
RestScheduledJobStatsHandler("_alerting"),
Expand Down Expand Up @@ -228,8 +225,7 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, R
sweeper = JobSweeper(environment.settings(), client, clusterService, threadPool, xContentRegistry, scheduler, ALERTING_JOB_TYPES)
this.threadPool = threadPool
this.clusterService = clusterService
this.restClient = SecureRestClientBuilder(settings, environment.configFile()).build()
return listOf(sweeper, scheduler, runner, scheduledJobIndices, restClient)
return listOf(sweeper, scheduler, runner, scheduledJobIndices)
}

override fun getSettings(): List<Setting<*>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,25 @@ class GetAlertsRequest : ActionRequest {
val severityLevel: String
val alertState: String
val monitorId: String?
val authHeader: String?

constructor(
table: Table,
severityLevel: String,
alertState: String,
monitorId: String?,
authHeader: String?
monitorId: String?
) : super() {
this.table = table
this.severityLevel = severityLevel
this.alertState = alertState
this.monitorId = monitorId
this.authHeader = authHeader
}

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
table = Table.readFrom(sin),
severityLevel = sin.readString(),
alertState = sin.readString(),
monitorId = sin.readOptionalString(),
authHeader = sin.readOptionalString()
monitorId = sin.readOptionalString()
)

override fun validate(): ActionRequestValidationException? {
Expand All @@ -62,6 +58,5 @@ class GetAlertsRequest : ActionRequest {
out.writeString(severityLevel)
out.writeString(alertState)
out.writeOptionalString(monitorId)
out.writeOptionalString(authHeader)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,19 @@ class GetDestinationsRequest : ActionRequest {
val srcContext: FetchSourceContext?
val table: Table
val destinationType: String
val authHeader: String?

constructor(
destinationId: String?,
version: Long,
srcContext: FetchSourceContext?,
table: Table,
destinationType: String,
authHeader: String?
destinationType: String
) : super() {
this.destinationId = destinationId
this.version = version
this.srcContext = srcContext
this.table = table
this.destinationType = destinationType
this.authHeader = authHeader
}

@Throws(IOException::class)
Expand All @@ -55,8 +52,7 @@ class GetDestinationsRequest : ActionRequest {
FetchSourceContext(sin)
} else null,
table = Table.readFrom(sin),
destinationType = sin.readString(),
authHeader = sin.readOptionalString()
destinationType = sin.readString()
)

override fun validate(): ActionRequestValidationException? {
Expand All @@ -71,6 +67,5 @@ class GetDestinationsRequest : ActionRequest {
srcContext?.writeTo(out)
table.writeTo(out)
out.writeString(destinationType)
out.writeOptionalString(authHeader)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class IndexDestinationRequest : ActionRequest {
val primaryTerm: Long
val refreshPolicy: WriteRequest.RefreshPolicy
val method: RestRequest.Method
val authHeader: String?
var destination: Destination

constructor(
Expand All @@ -39,15 +38,13 @@ class IndexDestinationRequest : ActionRequest {
primaryTerm: Long,
refreshPolicy: WriteRequest.RefreshPolicy,
method: RestRequest.Method,
authHeader: String?,
destination: Destination
): super() {
this.destinationId = destinationId
this.seqNo = seqNo
this.primaryTerm = primaryTerm
this.refreshPolicy = refreshPolicy
this.method = method
this.authHeader = authHeader
this.destination = destination
}

Expand All @@ -58,7 +55,6 @@ class IndexDestinationRequest : ActionRequest {
this.primaryTerm = sin.readLong()
this.refreshPolicy = WriteRequest.RefreshPolicy.readFrom(sin)
this.method = sin.readEnum(RestRequest.Method::class.java)
this.authHeader = sin.readOptionalString()
this.destination = Destination.readFrom(sin)
}

Expand All @@ -73,7 +69,6 @@ class IndexDestinationRequest : ActionRequest {
out.writeLong(primaryTerm)
refreshPolicy.writeTo(out)
out.writeEnum(method)
out.writeOptionalString(authHeader)
destination.writeTo(out)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class IndexMonitorRequest : ActionRequest {
val primaryTerm: Long
val refreshPolicy: WriteRequest.RefreshPolicy
val method: RestRequest.Method
val authHeader: String?
var monitor: Monitor

constructor(
Expand All @@ -39,15 +38,13 @@ class IndexMonitorRequest : ActionRequest {
primaryTerm: Long,
refreshPolicy: WriteRequest.RefreshPolicy,
method: RestRequest.Method,
authHeader: String?,
monitor: Monitor
): super() {
this.monitorId = monitorId
this.seqNo = seqNo
this.primaryTerm = primaryTerm
this.refreshPolicy = refreshPolicy
this.method = method
this.authHeader = authHeader
this.monitor = monitor
}

Expand All @@ -58,7 +55,6 @@ class IndexMonitorRequest : ActionRequest {
primaryTerm = sin.readLong(),
refreshPolicy = WriteRequest.RefreshPolicy.readFrom(sin),
method = sin.readEnum(RestRequest.Method::class.java),
authHeader = sin.readOptionalString(),
monitor = Monitor.readFrom(sin) as Monitor
)

Expand All @@ -73,7 +69,6 @@ class IndexMonitorRequest : ActionRequest {
out.writeLong(primaryTerm)
refreshPolicy.writeTo(out)
out.writeEnum(method)
out.writeOptionalString(authHeader)
monitor.writeTo(out)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,16 @@ import java.io.IOException
class SearchMonitorRequest : ActionRequest {

val searchRequest: SearchRequest
val authHeader: String?

constructor(
searchRequest: SearchRequest,
authHeader: String?
searchRequest: SearchRequest
): super() {
this.searchRequest = searchRequest
this.authHeader = authHeader
}

@Throws(IOException::class)
constructor(sin: StreamInput): this(
searchRequest = SearchRequest(sin),
authHeader = sin.readOptionalString()
searchRequest = SearchRequest(sin)
)

override fun validate(): ActionRequestValidationException? {
Expand All @@ -48,6 +44,5 @@ class SearchMonitorRequest : ActionRequest {
@Throws(IOException::class)
override fun writeTo(out: StreamOutput) {
searchRequest.writeTo(out)
out.writeOptionalString(authHeader)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import com.amazon.opendistroforelasticsearch.alerting.AlertingPlugin
import com.amazon.opendistroforelasticsearch.alerting.action.GetAlertsAction
import com.amazon.opendistroforelasticsearch.alerting.action.GetAlertsRequest
import com.amazon.opendistroforelasticsearch.alerting.model.Table
import com.amazon.opendistroforelasticsearch.commons.ConfigConstants
import org.apache.logging.log4j.LogManager
import org.elasticsearch.client.node.NodeClient
import org.elasticsearch.rest.BaseRestHandler
Expand Down Expand Up @@ -58,7 +57,6 @@ class RestGetAlertsAction : BaseRestHandler() {
val severityLevel = request.param("severityLevel", "ALL")
val alertState = request.param("alertState", "ALL")
val monitorId: String? = request.param("monitorId")
val auth = request.header(ConfigConstants.AUTHORIZATION)
val table = Table(
sortOrder,
sortString,
Expand All @@ -68,7 +66,7 @@ class RestGetAlertsAction : BaseRestHandler() {
searchString
)

val getAlertsRequest = GetAlertsRequest(table, severityLevel, alertState, monitorId, auth)
val getAlertsRequest = GetAlertsRequest(table, severityLevel, alertState, monitorId)
return RestChannelConsumer {
channel -> client.execute(GetAlertsAction.INSTANCE, getAlertsRequest, RestToXContentListener(channel))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.amazon.opendistroforelasticsearch.alerting.action.GetDestinationsActi
import com.amazon.opendistroforelasticsearch.alerting.action.GetDestinationsRequest
import com.amazon.opendistroforelasticsearch.alerting.model.Table
import com.amazon.opendistroforelasticsearch.alerting.util.context
import com.amazon.opendistroforelasticsearch.commons.ConfigConstants
import org.apache.logging.log4j.LogManager
import org.elasticsearch.client.node.NodeClient
import org.elasticsearch.rest.BaseRestHandler
Expand Down Expand Up @@ -67,7 +66,6 @@ class RestGetDestinationsAction : BaseRestHandler() {
val startIndex = request.paramAsInt("startIndex", 0)
val searchString = request.param("searchString", "")
val destinationType = request.param("destinationType", "ALL")
val auth = request.header(ConfigConstants.AUTHORIZATION)

val table = Table(
sortOrder,
Expand All @@ -83,8 +81,7 @@ class RestGetDestinationsAction : BaseRestHandler() {
RestActions.parseVersion(request),
srcContext,
table,
destinationType,
auth
destinationType
)
return RestChannelConsumer {
channel -> client.execute(GetDestinationsAction.INSTANCE, getDestinationsRequest, RestToXContentListener(channel))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.amazon.opendistroforelasticsearch.alerting.model.destination.Destinat
import com.amazon.opendistroforelasticsearch.alerting.util.IF_PRIMARY_TERM
import com.amazon.opendistroforelasticsearch.alerting.util.IF_SEQ_NO
import com.amazon.opendistroforelasticsearch.alerting.util.REFRESH
import com.amazon.opendistroforelasticsearch.commons.ConfigConstants
import org.apache.logging.log4j.LogManager
import org.elasticsearch.action.support.WriteRequest
import org.elasticsearch.client.node.NodeClient
Expand Down Expand Up @@ -80,8 +79,7 @@ class RestIndexDestinationAction : BaseRestHandler() {
} else {
WriteRequest.RefreshPolicy.IMMEDIATE
}
val auth = request.header(ConfigConstants.AUTHORIZATION)
val indexDestinationRequest = IndexDestinationRequest(id, seqNo, primaryTerm, refreshPolicy, request.method(), auth, destination)
val indexDestinationRequest = IndexDestinationRequest(id, seqNo, primaryTerm, refreshPolicy, request.method(), destination)
return RestChannelConsumer {
channel -> client.execute(IndexDestinationAction.INSTANCE, indexDestinationRequest,
indexDestinationResponse(channel, request.method()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.amazon.opendistroforelasticsearch.alerting.model.Monitor
import com.amazon.opendistroforelasticsearch.alerting.util.IF_PRIMARY_TERM
import com.amazon.opendistroforelasticsearch.alerting.util.IF_SEQ_NO
import com.amazon.opendistroforelasticsearch.alerting.util.REFRESH
import com.amazon.opendistroforelasticsearch.commons.ConfigConstants
import org.apache.logging.log4j.LogManager
import org.elasticsearch.action.support.WriteRequest
import org.elasticsearch.client.node.NodeClient
Expand Down Expand Up @@ -82,8 +81,7 @@ class RestIndexMonitorAction : BaseRestHandler() {
} else {
WriteRequest.RefreshPolicy.IMMEDIATE
}
val auth = request.header(ConfigConstants.AUTHORIZATION)
val indexMonitorRequest = IndexMonitorRequest(id, seqNo, primaryTerm, refreshPolicy, request.method(), auth, monitor)
val indexMonitorRequest = IndexMonitorRequest(id, seqNo, primaryTerm, refreshPolicy, request.method(), monitor)

return RestChannelConsumer { channel ->
client.execute(IndexMonitorAction.INSTANCE, indexMonitorRequest, indexMonitorResponse(channel, request.method()))
Expand Down
Loading

0 comments on commit fc974fd

Please sign in to comment.