Skip to content

Commit

Permalink
Made TransportGetRemoteIndexesAction a SecureTransportAction.
Browse files Browse the repository at this point in the history
Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
  • Loading branch information
AWSHurneyt committed Jan 25, 2024
1 parent db602ca commit ada6e7e
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import org.opensearch.alerting.action.GetRemoteIndexesRequest
import org.opensearch.alerting.action.GetRemoteIndexesResponse
import org.opensearch.alerting.action.GetRemoteIndexesResponse.ClusterIndexes
import org.opensearch.alerting.action.GetRemoteIndexesResponse.ClusterIndexes.ClusterIndex
import org.opensearch.alerting.opensearchapi.convertToMap
import org.opensearch.alerting.opensearchapi.suspendUntil
import org.opensearch.alerting.settings.AlertingSettings
import org.opensearch.alerting.util.AlertingException
import org.opensearch.alerting.util.CrossClusterMonitorUtils
import org.opensearch.client.Client
Expand Down Expand Up @@ -51,24 +53,35 @@ class TransportGetRemoteIndexesAction @Inject constructor(
transportService,
actionFilters,
::GetRemoteIndexesRequest
) {
),
SecureTransportAction {

@Volatile
override var filterByEnabled = AlertingSettings.FILTER_BY_BACKEND_ROLES.get(settings)

override fun doExecute(
task: Task,
request: GetRemoteIndexesRequest,
listener: ActionListener<GetRemoteIndexesResponse>
actionListener: ActionListener<GetRemoteIndexesResponse>
) {
log.info("hurneyt TransportGetRemoteIndexesAction START")
val user = readUserFromThreadContext(client)

if (!validateUserBackendRoles(user, actionListener)) {
return
}

client.threadPool().threadContext.stashContext().use {
scope.launch {
val clusterIndexesList = mutableListOf<ClusterIndexes>()

var resolveIndexResponse: ResolveIndexAction.Response? = null
try {
resolveIndexResponse = getRemoteClusters(CrossClusterMonitorUtils.parseIndexesForRemoteSearch(request.indexes, clusterService))
log.info("hurneyt TransportGetRemoteIndexesAction::resolveIndexResponse = {}", resolveIndexResponse)
log.info("hurneyt TransportGetRemoteIndexesAction::resolveIndexResponse = {}", resolveIndexResponse.convertToMap())
} catch (e: Exception) {
log.error("Failed to retrieve indexes for request $request", e)
listener.onFailure(AlertingException.wrap(e))
actionListener.onFailure(AlertingException.wrap(e))
}

val resolvedIndexes = resolveIndexResponse?.indices?.map { it.name } ?: emptyList()
Expand All @@ -88,7 +101,7 @@ class TransportGetRemoteIndexesAction @Inject constructor(
clusterHealthResponse = getHealthStatuses(targetClient, indexes)
} catch (e: Exception) {
log.error("Failed to retrieve health statuses for request $request", e)
listener.onFailure(AlertingException.wrap(e))
actionListener.onFailure(AlertingException.wrap(e))
}
val endTime = Instant.now()

Expand All @@ -102,7 +115,7 @@ class TransportGetRemoteIndexesAction @Inject constructor(
mappingsResponse = getIndexMappings(targetClient, indexes)
} catch (e: Exception) {
log.error("Failed to retrieve mappings for request $request", e)
listener.onFailure(AlertingException.wrap(e))
actionListener.onFailure(AlertingException.wrap(e))
}
}

Expand All @@ -129,7 +142,7 @@ class TransportGetRemoteIndexesAction @Inject constructor(
}
log.info("hurneyt TransportGetRemoteIndexesAction::clusterIndexesList = {}", clusterIndexesList)
log.info("hurneyt TransportGetRemoteIndexesAction END")
listener.onResponse(GetRemoteIndexesResponse(clusterIndexes = clusterIndexesList))
actionListener.onResponse(GetRemoteIndexesResponse(clusterIndexes = clusterIndexesList))
}
}
}
Expand Down

0 comments on commit ada6e7e

Please sign in to comment.