Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Governance preferences attributes deny asset filters #2375

Merged
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
12 changes: 11 additions & 1 deletion addons/models/0000-Area0/0010-base_model.json
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@
],
"description": "Atlan Type representing parent model for Persona, Purpose",
"serviceType": "atlan",
"typeVersion": "1.1",
"typeVersion": "1.2",
"attributeDefs": [
{
"name": "isAccessControlEnabled",
Expand Down Expand Up @@ -914,6 +914,16 @@
"skipScrubbing": true,
"includeInNotification": false
},
{
"name": "denyAssetFilters",
"typeName": "array<string>",
"cardinality": "SET",
"isIndexable": false,
"isOptional": true,
"isUnique": false,
"skipScrubbing": true,
"includeInNotification": false
},
{
"name": "channelLink",
"typeName": "string",
Expand Down
30 changes: 21 additions & 9 deletions webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static org.apache.atlas.AtlasErrorCode.BAD_REQUEST;
import static org.apache.atlas.AtlasErrorCode.DEPRECATED_API;
Expand All @@ -93,6 +91,10 @@ public class EntityREST {
public static final String PREFIX_ATTR_ = "attr_";
public static final String QUALIFIED_NAME = "qualifiedName";
private static final int HUNDRED_THOUSAND = 100000;
private static final int TWO_MILLION = HUNDRED_THOUSAND * 10 * 2;
private static final Set<String> ATTRS_WITH_TWO_MILLION_LIMIT = new HashSet<String>() {{
add("rawQueryText");
}};


private final AtlasTypeRegistry typeRegistry;
Expand Down Expand Up @@ -899,15 +901,25 @@ public EntityMutationResponse createOrUpdate(AtlasEntitiesWithExtInfo entities,
}

public static void validateAttributeLength(final List<AtlasEntity> entities) throws AtlasBaseException {
//Predicate to check attribute value exceeding length
Predicate<Map.Entry<String, Object>> predicateOfAttributeLengthExceedingLimit = attribute ->
attribute.getValue() instanceof String && ((String) attribute.getValue()).length() > HUNDRED_THOUSAND;
List<String> errorMessages = new ArrayList<>();

for (final AtlasEntity atlasEntity : entities) {
Set<String> attributeKeys = org.apache.commons.collections4.MapUtils.emptyIfNull(atlasEntity.getAttributes())
.entrySet().stream().filter(predicateOfAttributeLengthExceedingLimit).map(Map.Entry::getKey).collect(Collectors.toSet());
if (!attributeKeys.isEmpty()) {
throw new AtlasBaseException("Attribute(s) " + String.join(",", attributeKeys) + " exceeds limit of "+HUNDRED_THOUSAND+" characters");
for (Map.Entry<String, Object> attribute : atlasEntity.getAttributes().entrySet()) {

if (attribute.getValue() instanceof String && ((String) attribute.getValue()).length() > HUNDRED_THOUSAND) {

if (ATTRS_WITH_TWO_MILLION_LIMIT.contains(attribute.getKey())) {
if (((String) attribute.getValue()).length() > TWO_MILLION) {
errorMessages.add("Attribute " + attribute.getKey() + " exceeds limit of " + TWO_MILLION + " characters");
}
} else {
errorMessages.add("Attribute " + attribute.getKey() + " exceeds limit of " + HUNDRED_THOUSAND + " characters");
}
}
}

if (errorMessages.size() > 0) {
throw new AtlasBaseException(AtlasType.toJson(errorMessages));
}
}
}
Expand Down