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

Not returning access details for non-admin users #202

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ internal object ReportDefinitionActions {
if (!UserAccessManager.doesUserHasAccess(user, reportDefinitionDetails.access)) {
throw ElasticsearchStatusException("Permission denied for Report Definition ${request.reportDefinitionId}", RestStatus.FORBIDDEN)
}
return GetReportDefinitionResponse(reportDefinitionDetails)
return GetReportDefinitionResponse(reportDefinitionDetails, UserAccessManager.hasAllInfoAccess(user))
}

/**
Expand Down Expand Up @@ -138,6 +138,6 @@ internal object ReportDefinitionActions {
val reportDefinitionsList = ReportDefinitionsIndex.getAllReportDefinitions(UserAccessManager.getSearchAccessInfo(user),
request.fromIndex,
request.maxItems)
return GetAllReportDefinitionsResponse(reportDefinitionsList)
return GetAllReportDefinitionsResponse(reportDefinitionsList, UserAccessManager.hasAllInfoAccess(user))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ internal object ReportInstanceActions {
val docId = ReportInstancesIndex.createReportInstance(reportInstance)
docId ?: throw ElasticsearchStatusException("Report Instance Creation failed", RestStatus.INTERNAL_SERVER_ERROR)
val reportInstanceCopy = reportInstance.copy(id = docId)
return InContextReportCreateResponse(reportInstanceCopy)
return InContextReportCreateResponse(reportInstanceCopy, UserAccessManager.hasAllInfoAccess(user))
}

/**
Expand Down Expand Up @@ -101,7 +101,7 @@ internal object ReportInstanceActions {
val docId = ReportInstancesIndex.createReportInstance(reportInstance)
docId ?: throw ElasticsearchStatusException("Report Instance Creation failed", RestStatus.INTERNAL_SERVER_ERROR)
val reportInstanceCopy = reportInstance.copy(id = docId)
return OnDemandReportCreateResponse(reportInstanceCopy)
return OnDemandReportCreateResponse(reportInstanceCopy, UserAccessManager.hasAllInfoAccess(user))
}

/**
Expand Down Expand Up @@ -145,7 +145,7 @@ internal object ReportInstanceActions {
if (!UserAccessManager.doesUserHasAccess(user, reportInstance.access)) {
throw ElasticsearchStatusException("Permission denied for Report Definition ${request.reportInstanceId}", RestStatus.FORBIDDEN)
}
return GetReportInstanceResponse(reportInstance)
return GetReportInstanceResponse(reportInstance, UserAccessManager.hasAllInfoAccess(user))
}

/**
Expand All @@ -159,7 +159,7 @@ internal object ReportInstanceActions {
val reportInstanceList = ReportInstancesIndex.getAllReportInstances(UserAccessManager.getSearchAccessInfo(user),
request.fromIndex,
request.maxItems)
return GetAllReportInstancesResponse(reportInstanceList)
return GetAllReportInstancesResponse(reportInstanceList, UserAccessManager.hasAllInfoAccess(user))
}

fun poll(user: User?): PollReportInstanceResponse {
Expand All @@ -168,7 +168,7 @@ internal object ReportInstanceActions {
val currentTime = Instant.now()
val reportInstances = ReportInstancesIndex.getPendingReportInstances()
return if (reportInstances.isEmpty()) {
PollReportInstanceResponse(getRetryAfterTime(), null)
PollReportInstanceResponse(getRetryAfterTime())
} else {
// Shuffle list so that when multiple requests are made, chances of lock conflict is less
reportInstances.shuffle()
Expand All @@ -186,9 +186,9 @@ internal object ReportInstanceActions {
ReportInstancesIndex.updateReportInstanceDoc(updatedInstance)
}
if (lockedJob == null) {
PollReportInstanceResponse(PluginSettings.minPollingDurationSeconds, null)
PollReportInstanceResponse(PluginSettings.minPollingDurationSeconds)
} else {
PollReportInstanceResponse(0, lockedJob.reportInstance)
PollReportInstanceResponse(0, lockedJob.reportInstance, UserAccessManager.hasAllInfoAccess(user))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ internal object ReportDefinitionsIndex {
fun createReportDefinition(reportDefinitionDetails: ReportDefinitionDetails): String? {
createIndex()
val indexRequest = IndexRequest(REPORT_DEFINITIONS_INDEX_NAME)
.source(reportDefinitionDetails.toXContent(false))
.source(reportDefinitionDetails.toXContent())
.create(true)
val actionFuture = client.index(indexRequest)
val response = actionFuture.actionGet(PluginSettings.operationTimeoutMs)
Expand All @@ -134,7 +134,7 @@ internal object ReportDefinitionsIndex {
val actionFuture = client.get(getRequest)
val response = actionFuture.actionGet(PluginSettings.operationTimeoutMs)
return if (response.sourceAsString == null) {
log.warn("$LOG_PREFIX:getReportDefinition - item not found; response:$response")
log.warn("$LOG_PREFIX:getReportDefinition - $id not found; response:$response")
null
} else {
val parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY,
Expand Down Expand Up @@ -185,12 +185,12 @@ internal object ReportDefinitionsIndex {
val updateRequest = UpdateRequest()
.index(REPORT_DEFINITIONS_INDEX_NAME)
.id(id)
.doc(reportDefinitionDetails.toXContent(false))
.doc(reportDefinitionDetails.toXContent())
.fetchSource(true)
val actionFuture = client.update(updateRequest)
val response = actionFuture.actionGet(PluginSettings.operationTimeoutMs)
if (response.result != DocWriteResponse.Result.UPDATED) {
log.warn("$LOG_PREFIX:updateReportDefinition failed; response:$response")
log.warn("$LOG_PREFIX:updateReportDefinition failed for $id; response:$response")
}
return response.result == DocWriteResponse.Result.UPDATED
}
Expand All @@ -208,7 +208,7 @@ internal object ReportDefinitionsIndex {
val actionFuture = client.delete(deleteRequest)
val response = actionFuture.actionGet(PluginSettings.operationTimeoutMs)
if (response.result != DocWriteResponse.Result.DELETED) {
log.warn("$LOG_PREFIX:deleteReportDefinition failed; response:$response")
log.warn("$LOG_PREFIX:deleteReportDefinition failed for $id; response:$response")
}
return response.result == DocWriteResponse.Result.DELETED
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ internal object ReportInstancesIndex {
fun createReportInstance(reportInstance: ReportInstance): String? {
createIndex()
val indexRequest = IndexRequest(REPORT_INSTANCES_INDEX_NAME)
.source(reportInstance.toXContent(false))
.source(reportInstance.toXContent())
.create(true)
val actionFuture = client.index(indexRequest)
val response = actionFuture.actionGet(PluginSettings.operationTimeoutMs)
Expand All @@ -138,7 +138,7 @@ internal object ReportInstancesIndex {
val actionFuture = client.get(getRequest)
val response = actionFuture.actionGet(PluginSettings.operationTimeoutMs)
return if (response.sourceAsString == null) {
log.warn("$LOG_PREFIX:getReportInstance - item not found; response:$response")
log.warn("$LOG_PREFIX:getReportInstance - $id not found; response:$response")
null
} else {
val parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY,
Expand Down Expand Up @@ -188,12 +188,12 @@ internal object ReportInstancesIndex {
val updateRequest = UpdateRequest()
.index(REPORT_INSTANCES_INDEX_NAME)
.id(reportInstance.id)
.doc(reportInstance.toXContent(false))
.doc(reportInstance.toXContent())
.fetchSource(true)
val actionFuture = client.update(updateRequest)
val response = actionFuture.actionGet(PluginSettings.operationTimeoutMs)
if (response.result != DocWriteResponse.Result.UPDATED) {
log.warn("$LOG_PREFIX:updateReportInstance failed; response:$response")
log.warn("$LOG_PREFIX:updateReportInstance failed for ${reportInstance.id}; response:$response")
}
return response.result == DocWriteResponse.Result.UPDATED
}
Expand All @@ -210,12 +210,12 @@ internal object ReportInstancesIndex {
.id(reportInstanceDoc.reportInstance.id)
.setIfSeqNo(reportInstanceDoc.seqNo)
.setIfPrimaryTerm(reportInstanceDoc.primaryTerm)
.doc(reportInstanceDoc.reportInstance.toXContent(false))
.doc(reportInstanceDoc.reportInstance.toXContent())
.fetchSource(true)
val actionFuture = client.update(updateRequest)
val response = actionFuture.actionGet(PluginSettings.operationTimeoutMs)
if (response.result != DocWriteResponse.Result.UPDATED) {
log.warn("$LOG_PREFIX:updateReportInstanceDoc failed; response:$response")
log.warn("$LOG_PREFIX:updateReportInstanceDoc failed for ${reportInstanceDoc.reportInstance.id}; response:$response")
}
return response.result == DocWriteResponse.Result.UPDATED
}
Expand All @@ -233,7 +233,7 @@ internal object ReportInstancesIndex {
val actionFuture = client.delete(deleteRequest)
val response = actionFuture.actionGet(PluginSettings.operationTimeoutMs)
if (response.result != DocWriteResponse.Result.DELETED) {
log.warn("$LOG_PREFIX:deleteReportInstance failed; response:$response")
log.warn("$LOG_PREFIX:deleteReportInstance failed for $id; response:$response")
}
return response.result == DocWriteResponse.Result.DELETED
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ internal abstract class BaseResponse : ActionResponse(), ToXContentObject {
/**
* {@inheritDoc}
*/
fun toXContent(): XContentBuilder {
return toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)
fun toXContent(params: ToXContent.Params = ToXContent.EMPTY_PARAMS): XContentBuilder {
return toXContent(XContentFactory.jsonBuilder(), params)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ internal class CreateReportDefinitionRequest : ActionRequest, ToXContentObject {

/**
* create XContentBuilder from this object using [XContentFactory.jsonBuilder()]
* @param params XContent parameters
* @return created XContentBuilder object
*/
fun toXContent(): XContentBuilder? {
return toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)
fun toXContent(params: ToXContent.Params = ToXContent.EMPTY_PARAMS): XContentBuilder? {
return toXContent(XContentFactory.jsonBuilder(), params)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ internal class DeleteReportDefinitionRequest(

/**
* create XContentBuilder from this object using [XContentFactory.jsonBuilder()]
* @param params XContent parameters
* @return created XContentBuilder object
*/
fun toXContent(): XContentBuilder? {
return toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)
fun toXContent(params: ToXContent.Params = ToXContent.EMPTY_PARAMS): XContentBuilder? {
return toXContent(XContentFactory.jsonBuilder(), params)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ internal class GetAllReportDefinitionsRequest(

/**
* create XContentBuilder from this object using [XContentFactory.jsonBuilder()]
* @param params XContent parameters
* @return created XContentBuilder object
*/
fun toXContent(): XContentBuilder? {
return toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)
fun toXContent(params: ToXContent.Params = ToXContent.EMPTY_PARAMS): XContentBuilder? {
return toXContent(XContentFactory.jsonBuilder(), params)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ import java.io.IOException
*/
internal class GetAllReportDefinitionsResponse : BaseResponse {
val reportDefinitionList: ReportDefinitionDetailsSearchResults
private val filterSensitiveInfo: Boolean

constructor(reportDefinitionList: ReportDefinitionDetailsSearchResults) : super() {
constructor(reportDefinitionList: ReportDefinitionDetailsSearchResults, filterSensitiveInfo: Boolean) : super() {
this.reportDefinitionList = reportDefinitionList
this.filterSensitiveInfo = filterSensitiveInfo
}

@Throws(IOException::class)
Expand All @@ -55,6 +57,7 @@ internal class GetAllReportDefinitionsResponse : BaseResponse {
*/
constructor(parser: XContentParser) : super() {
reportDefinitionList = ReportDefinitionDetailsSearchResults(parser)
this.filterSensitiveInfo = false // Sensitive info Must have filtered when created json object
}

/**
Expand All @@ -69,6 +72,11 @@ internal class GetAllReportDefinitionsResponse : BaseResponse {
* {@inheritDoc}
*/
override fun toXContent(builder: XContentBuilder?, params: ToXContent.Params?): XContentBuilder {
return reportDefinitionList.toXContent(builder, params)
val xContentParams = if (filterSensitiveInfo) {
RestTag.FILTERED_REST_OUTPUT_PARAMS
} else {
RestTag.REST_OUTPUT_PARAMS
}
return reportDefinitionList.toXContent(builder, xContentParams)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ internal data class GetAllReportInstancesRequest(

/**
* create XContentBuilder from this object using [XContentFactory.jsonBuilder()]
* @param params XContent parameters
* @return created XContentBuilder object
*/
fun toXContent(): XContentBuilder? {
return toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)
fun toXContent(params: ToXContent.Params = ToXContent.EMPTY_PARAMS): XContentBuilder? {
return toXContent(XContentFactory.jsonBuilder(), params)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ import java.io.IOException
*/
internal class GetAllReportInstancesResponse : BaseResponse {
val reportInstanceList: ReportInstanceSearchResults
private val filterSensitiveInfo: Boolean

constructor(reportInstanceList: ReportInstanceSearchResults) : super() {
constructor(reportInstanceList: ReportInstanceSearchResults, filterSensitiveInfo: Boolean) : super() {
this.reportInstanceList = reportInstanceList
this.filterSensitiveInfo = filterSensitiveInfo
}

@Throws(IOException::class)
Expand All @@ -55,6 +57,7 @@ internal class GetAllReportInstancesResponse : BaseResponse {
*/
constructor(parser: XContentParser) : super() {
this.reportInstanceList = ReportInstanceSearchResults(parser)
this.filterSensitiveInfo = false // Sensitive info Must have filtered when created json object
}

/**
Expand All @@ -69,6 +72,11 @@ internal class GetAllReportInstancesResponse : BaseResponse {
* {@inheritDoc}
*/
override fun toXContent(builder: XContentBuilder?, params: ToXContent.Params?): XContentBuilder {
return reportInstanceList.toXContent(builder, params)
val xContentParams = if (filterSensitiveInfo) {
RestTag.FILTERED_REST_OUTPUT_PARAMS
} else {
RestTag.REST_OUTPUT_PARAMS
}
return reportInstanceList.toXContent(builder, xContentParams)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ internal class GetReportDefinitionRequest(

/**
* create XContentBuilder from this object using [XContentFactory.jsonBuilder()]
* @param params XContent parameters
* @return created XContentBuilder object
*/
fun toXContent(): XContentBuilder? {
return toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)
fun toXContent(params: ToXContent.Params = ToXContent.EMPTY_PARAMS): XContentBuilder? {
return toXContent(XContentFactory.jsonBuilder(), params)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.amazon.opendistroforelasticsearch.reportsscheduler.model

import com.amazon.opendistroforelasticsearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX
import com.amazon.opendistroforelasticsearch.reportsscheduler.model.RestTag.REPORT_DEFINITION_DETAILS_FIELD
import com.amazon.opendistroforelasticsearch.reportsscheduler.util.createJsonParser
import com.amazon.opendistroforelasticsearch.reportsscheduler.util.logger
import org.elasticsearch.common.io.stream.StreamInput
Expand All @@ -43,13 +42,15 @@ import java.io.IOException
*/
internal class GetReportDefinitionResponse : BaseResponse {
val reportDefinitionDetails: ReportDefinitionDetails
private val filterSensitiveInfo: Boolean

companion object {
private val log by logger(GetReportDefinitionResponse::class.java)
}

constructor(reportDefinition: ReportDefinitionDetails) : super() {
constructor(reportDefinition: ReportDefinitionDetails, filterSensitiveInfo: Boolean) : super() {
this.reportDefinitionDetails = reportDefinition
this.filterSensitiveInfo = filterSensitiveInfo
}

@Throws(IOException::class)
Expand All @@ -66,7 +67,7 @@ internal class GetReportDefinitionResponse : BaseResponse {
val fieldName = parser.currentName()
parser.nextToken()
when (fieldName) {
REPORT_DEFINITION_DETAILS_FIELD -> reportDefinition = ReportDefinitionDetails.parse(parser)
RestTag.REPORT_DEFINITION_DETAILS_FIELD -> reportDefinition = ReportDefinitionDetails.parse(parser)
else -> {
parser.skipChildren()
log.info("$LOG_PREFIX:Skipping Unknown field $fieldName")
Expand All @@ -75,6 +76,7 @@ internal class GetReportDefinitionResponse : BaseResponse {
}
reportDefinition ?: throw IllegalArgumentException("${RestTag.REPORT_DEFINITION_FIELD} field absent")
this.reportDefinitionDetails = reportDefinition
this.filterSensitiveInfo = false // Sensitive info Must have filtered when created json object
}

/**
Expand All @@ -89,9 +91,14 @@ internal class GetReportDefinitionResponse : BaseResponse {
* {@inheritDoc}
*/
override fun toXContent(builder: XContentBuilder?, params: ToXContent.Params?): XContentBuilder {
val xContentParams = if (filterSensitiveInfo) {
RestTag.FILTERED_REST_OUTPUT_PARAMS
} else {
RestTag.REST_OUTPUT_PARAMS
}
builder!!.startObject()
.field(REPORT_DEFINITION_DETAILS_FIELD)
reportDefinitionDetails.toXContent(builder, ToXContent.EMPTY_PARAMS, true)
.field(RestTag.REPORT_DEFINITION_DETAILS_FIELD)
reportDefinitionDetails.toXContent(builder, xContentParams)
return builder.endObject()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ internal class GetReportInstanceRequest(

/**
* create XContentBuilder from this object using [XContentFactory.jsonBuilder()]
* @param params XContent parameters
* @return created XContentBuilder object
*/
fun toXContent(): XContentBuilder? {
return toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)
fun toXContent(params: ToXContent.Params = ToXContent.EMPTY_PARAMS): XContentBuilder? {
return toXContent(XContentFactory.jsonBuilder(), params)
}

/**
Expand Down
Loading