Skip to content

Commit

Permalink
Use common code from Search Client
Browse files Browse the repository at this point in the history
  • Loading branch information
mohityadav766 committed Sep 25, 2024
1 parent c3d002c commit 12c727a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
import javax.ws.rs.core.Response;
import lombok.Getter;
import org.apache.commons.lang3.tuple.Pair;
import org.openmetadata.schema.api.searcg.SearchSettings;
import org.openmetadata.schema.dataInsight.DataInsightChartResult;
import org.openmetadata.schema.dataInsight.custom.DataInsightCustomChart;
import org.openmetadata.schema.dataInsight.custom.DataInsightCustomChartResultList;
import org.openmetadata.schema.service.configuration.elasticsearch.ElasticSearchConfiguration;
import org.openmetadata.schema.settings.SettingsType;
import org.openmetadata.schema.tests.DataQualityReport;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.service.exception.CustomExceptionMessage;
import org.openmetadata.service.resources.settings.SettingsCache;
import org.openmetadata.service.search.models.IndexMapping;
import org.openmetadata.service.search.security.RBACConditionEvaluator;
import org.openmetadata.service.security.policyevaluator.SubjectContext;
import org.openmetadata.service.util.SSLUtil;
import os.org.opensearch.action.bulk.BulkRequest;
Expand Down Expand Up @@ -272,4 +276,15 @@ default List<Map<String, String>> fetchDIChartFields() throws IOException {
}

Object getLowLevelClient();

static boolean shouldApplyRbacConditions(
SubjectContext subjectContext, RBACConditionEvaluator rbacConditionEvaluator) {
return Boolean.TRUE.equals(
SettingsCache.getSetting(SettingsType.SEARCH_SETTINGS, SearchSettings.class)
.getEnableAccessControl())
&& subjectContext != null
&& !subjectContext.isAdmin()
&& !subjectContext.isBot()
&& rbacConditionEvaluator != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,12 @@
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.jetbrains.annotations.NotNull;
import org.openmetadata.common.utils.CommonUtil;
import org.openmetadata.schema.api.searcg.SearchSettings;
import org.openmetadata.schema.dataInsight.DataInsightChartResult;
import org.openmetadata.schema.dataInsight.custom.DataInsightCustomChart;
import org.openmetadata.schema.dataInsight.custom.DataInsightCustomChartResultList;
import org.openmetadata.schema.dataInsight.custom.FormulaHolder;
import org.openmetadata.schema.entity.data.EntityHierarchy__1;
import org.openmetadata.schema.service.configuration.elasticsearch.ElasticSearchConfiguration;
import org.openmetadata.schema.settings.SettingsType;
import org.openmetadata.schema.tests.DataQualityReport;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.Include;
Expand All @@ -155,7 +153,6 @@
import org.openmetadata.service.Entity;
import org.openmetadata.service.dataInsight.DataInsightAggregatorInterface;
import org.openmetadata.service.jdbi3.DataInsightChartRepository;
import org.openmetadata.service.resources.settings.SettingsCache;
import org.openmetadata.service.search.SearchClient;
import org.openmetadata.service.search.SearchIndexUtils;
import org.openmetadata.service.search.SearchRequest;
Expand Down Expand Up @@ -2308,13 +2305,7 @@ public Object getLowLevelClient() {

private void buildSearchRBACQuery(
SubjectContext subjectContext, SearchSourceBuilder searchSourceBuilder) {
if (Boolean.TRUE.equals(
SettingsCache.getSetting(SettingsType.SEARCH_SETTINGS, SearchSettings.class)
.getEnableAccessControl())
&& subjectContext != null
&& !subjectContext.isAdmin()
&& !subjectContext.isBot()
&& rbacConditionEvaluator != null) {
if (SearchClient.shouldApplyRbacConditions(subjectContext, rbacConditionEvaluator)) {
OMQueryBuilder rbacQuery = rbacConditionEvaluator.evaluateConditions(subjectContext);
if (rbacQuery != null) {
searchSourceBuilder.query(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.jetbrains.annotations.NotNull;
import org.openmetadata.common.utils.CommonUtil;
import org.openmetadata.schema.api.searcg.SearchSettings;
import org.openmetadata.schema.dataInsight.DataInsightChartResult;
import org.openmetadata.schema.dataInsight.custom.DataInsightCustomChart;
import org.openmetadata.schema.dataInsight.custom.DataInsightCustomChartResultList;
import org.openmetadata.schema.dataInsight.custom.FormulaHolder;
import org.openmetadata.schema.entity.data.EntityHierarchy__1;
import org.openmetadata.schema.service.configuration.elasticsearch.ElasticSearchConfiguration;
import org.openmetadata.schema.settings.SettingsType;
import org.openmetadata.schema.tests.DataQualityReport;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.Include;
Expand All @@ -77,7 +75,6 @@
import org.openmetadata.service.Entity;
import org.openmetadata.service.dataInsight.DataInsightAggregatorInterface;
import org.openmetadata.service.jdbi3.DataInsightChartRepository;
import org.openmetadata.service.resources.settings.SettingsCache;
import org.openmetadata.service.search.SearchClient;
import org.openmetadata.service.search.SearchIndexUtils;
import org.openmetadata.service.search.SearchRequest;
Expand Down Expand Up @@ -2271,13 +2268,7 @@ public Object getLowLevelClient() {

private void buildSearchRBACQuery(
SubjectContext subjectContext, SearchSourceBuilder searchSourceBuilder) {
if (Boolean.TRUE.equals(
SettingsCache.getSetting(SettingsType.SEARCH_SETTINGS, SearchSettings.class)
.getEnableAccessControl())
&& subjectContext != null
&& !subjectContext.isAdmin()
&& !subjectContext.isBot()
&& rbacConditionEvaluator != null) {
if (SearchClient.shouldApplyRbacConditions(subjectContext, rbacConditionEvaluator)) {
OMQueryBuilder rbacQuery = rbacConditionEvaluator.evaluateConditions(subjectContext);
if (rbacQuery != null) {
searchSourceBuilder.query(
Expand Down

0 comments on commit 12c727a

Please sign in to comment.