Skip to content

Commit

Permalink
FIX #17042 - Allow non admin/bot to read profiler global config (#18292)
Browse files Browse the repository at this point in the history
* fix: custom properties folder name in generation to match expected package name (i.e. customProperties -- uppercase P)

* fix: allow non admin/bot to read profiler global config with the right permission

* style: ran java linting

* fix: custom properties import casing
  • Loading branch information
TeddyCr authored and harshach committed Nov 3, 2024
1 parent a014cf5 commit 00b6427
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
import org.openmetadata.schema.type.csv.CsvFile;
import org.openmetadata.schema.type.csv.CsvHeader;
import org.openmetadata.schema.type.csv.CsvImportResult;
import org.openmetadata.schema.type.customproperties.TableConfig;
import org.openmetadata.schema.type.customProperties.TableConfig;
import org.openmetadata.service.Entity;
import org.openmetadata.service.TypeRegistry;
import org.openmetadata.service.jdbi3.EntityRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
import org.openmetadata.schema.type.api.BulkOperationResult;
import org.openmetadata.schema.type.api.BulkResponse;
import org.openmetadata.schema.type.csv.CsvImportResult;
import org.openmetadata.schema.type.customproperties.TableConfig;
import org.openmetadata.schema.type.customProperties.TableConfig;
import org.openmetadata.schema.utils.EntityInterfaceUtil;
import org.openmetadata.service.Entity;
import org.openmetadata.service.OpenMetadataApplicationConfig;
Expand Down Expand Up @@ -1493,15 +1493,15 @@ private String getFormattedDateTimeField(
private void validateTableType(JsonNode fieldValue, String propertyConfig, String fieldName) {
TableConfig tableConfig =
JsonUtils.convertValue(JsonUtils.readTree(propertyConfig), TableConfig.class);
org.openmetadata.schema.type.customproperties.Table tableValue =
org.openmetadata.schema.type.customProperties.Table tableValue =
JsonUtils.convertValue(
JsonUtils.readTree(String.valueOf(fieldValue)),
org.openmetadata.schema.type.customproperties.Table.class);
org.openmetadata.schema.type.customProperties.Table.class);
Set<String> configColumns = tableConfig.getColumns();

try {
JsonUtils.validateJsonSchema(
tableValue, org.openmetadata.schema.type.customproperties.Table.class);
tableValue, org.openmetadata.schema.type.customProperties.Table.class);

Set<String> fieldColumns = new HashSet<>();
fieldValue.get("columns").forEach(column -> fieldColumns.add(column.asText()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.Include;
import org.openmetadata.schema.type.Relationship;
import org.openmetadata.schema.type.customproperties.EnumConfig;
import org.openmetadata.schema.type.customproperties.TableConfig;
import org.openmetadata.schema.type.customProperties.EnumConfig;
import org.openmetadata.schema.type.customProperties.TableConfig;
import org.openmetadata.service.Entity;
import org.openmetadata.service.TypeRegistry;
import org.openmetadata.service.exception.CatalogExceptionMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ protected List<MetadataOperation> getEntitySpecificOperations() {
MetadataOperation.VIEW_DATA_PROFILE,
MetadataOperation.VIEW_SAMPLE_DATA,
MetadataOperation.VIEW_USAGE,
MetadataOperation.VIEW_PROFILER_GLOBAL_CONFIGURATION,
MetadataOperation.EDIT_TESTS,
MetadataOperation.EDIT_QUERIES,
MetadataOperation.EDIT_DATA_PROFILE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.openmetadata.schema.settings.SettingsType;
import org.openmetadata.schema.system.ValidationResponse;
import org.openmetadata.schema.type.Include;
import org.openmetadata.schema.type.MetadataOperation;
import org.openmetadata.schema.util.EntitiesCount;
import org.openmetadata.schema.util.ServicesCount;
import org.openmetadata.sdk.PipelineServiceClientInterface;
Expand All @@ -46,6 +47,8 @@
import org.openmetadata.service.resources.Collection;
import org.openmetadata.service.security.Authorizer;
import org.openmetadata.service.security.JwtFilter;
import org.openmetadata.service.security.policyevaluator.OperationContext;
import org.openmetadata.service.security.policyevaluator.ResourceContext;
import org.openmetadata.service.util.ResultList;
import org.openmetadata.service.util.email.EmailUtil;

Expand Down Expand Up @@ -145,8 +148,18 @@ public Settings getSettingByName(
schema = @Schema(implementation = Settings.class)))
})
public Settings getProfilerConfigurationSetting(
@Context UriInfo uriInfo, @Context SecurityContext securityContext) {
authorizer.authorizeAdminOrBot(securityContext);
@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Parameter(
description = "Entity type for which to get the global profiler configuration",
schema = @Schema(type = "string"))
@QueryParam("entityType")
@DefaultValue("table")
String entityType) {
ResourceContext resourceContext = new ResourceContext(entityType);
OperationContext operationContext =
new OperationContext(entityType, MetadataOperation.VIEW_PROFILER_GLOBAL_CONFIGURATION);
authorizer.authorize(securityContext, operationContext, resourceContext);
return systemRepository.getConfigWithKey(SettingsType.PROFILER_CONFIGURATION.value());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
import org.openmetadata.schema.type.TagLabel.TagSource;
import org.openmetadata.schema.type.TaskStatus;
import org.openmetadata.schema.type.csv.CsvImportResult;
import org.openmetadata.schema.type.customproperties.TableConfig;
import org.openmetadata.schema.type.customProperties.TableConfig;
import org.openmetadata.service.Entity;
import org.openmetadata.service.exception.CatalogExceptionMessage;
import org.openmetadata.service.jdbi3.EntityRepository.EntityUpdater;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
import org.openmetadata.schema.type.ChangeDescription;
import org.openmetadata.schema.type.CustomPropertyConfig;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.customproperties.EnumConfig;
import org.openmetadata.schema.type.customproperties.TableConfig;
import org.openmetadata.schema.type.customProperties.EnumConfig;
import org.openmetadata.schema.type.customProperties.TableConfig;
import org.openmetadata.service.Entity;
import org.openmetadata.service.resources.EntityResourceTest;
import org.openmetadata.service.resources.types.TypeResource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"ViewTests",
"ViewQueries",
"ViewDataProfile",
"ViewProfilerGlobalConfiguration",
"ViewSampleData",
"ViewTestCaseFailedRowsSample",
"EditAll",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"title": "Table",
"description": "A table-type custom property having rows and columns where all column data types are strings.",
"type": "object",
"javaType": "org.openmetadata.schema.type.customproperties.Table",
"javaType": "org.openmetadata.schema.type.customProperties.Table",
"properties": {
"columns": {
"type": "array",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "EnumConfig",
"type": "object",
"javaType": "org.openmetadata.schema.type.customproperties.EnumConfig",
"javaType": "org.openmetadata.schema.type.customProperties.EnumConfig",
"description": "Applies to Enum type, this config is used to define list of enum values",
"properties": {
"multiSelect": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "TableConfig",
"description": "Custom property configuration for table-type property where all column data types are strings.",
"type": "object",
"javaType": "org.openmetadata.schema.type.customproperties.TableConfig",
"javaType": "org.openmetadata.schema.type.customProperties.TableConfig",
"properties": {
"columns": {
"type": "array",
Expand Down

0 comments on commit 00b6427

Please sign in to comment.