Skip to content

Commit

Permalink
Merge pull request #3272 from atlanhq/beta-DG-1530_2-helper
Browse files Browse the repository at this point in the history
DG-1530 PR comment Fixes, Dev testing
  • Loading branch information
hr2904 authored Jun 21, 2024
2 parents 4b317be + 71ab329 commit 0f70fb3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -213,9 +212,10 @@ private void personaPolicyToESDslClauses(List<AtlasEntity> policies,
} else if (getPolicyActions(policy).contains(ACCESS_READ_PERSONA_DOMAIN)) {

for (String asset : assets) {
asset = validateAndConvertAsset(asset);
if(!asset.equals(NEW_WILDCARD_DOMAIN_SUPER)) {
if(!isAllDomain(asset)) {
terms.add(asset);
} else {
asset = NEW_WILDCARD_DOMAIN_SUPER;
}
allowClauseList.add(mapOf("wildcard", mapOf(QUALIFIED_NAME, asset + "*")));
}
Expand Down Expand Up @@ -248,10 +248,8 @@ private void personaPolicyToESDslClauses(List<AtlasEntity> policies,
allowClauseList.add(mapOf("terms", mapOf(QUALIFIED_NAME, terms)));
}

private String validateAndConvertAsset(String asset) {
if(asset.equals("*/super") || asset.equals("*"))
asset = NEW_WILDCARD_DOMAIN_SUPER;
return asset;
private boolean isAllDomain(String asset) {
return asset.equals("*/super") || asset.equals("*") || asset.equals(NEW_WILDCARD_DOMAIN_SUPER);
}
private Map<String, Object> esClausesToFilter(List<Map<String, Object>> allowClauseList) {
if (CollectionUtils.isNotEmpty(allowClauseList)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,33 +184,18 @@ private void processCreatePolicy(AtlasStruct entity) throws AtlasBaseException {
RequestContext.get().endMetricRecord(metricRecorder);
}


private void validateAndReduce(AtlasEntity policy) {
ArrayList<String> resources = (ArrayList<String>) policy.getAttribute(ATTR_POLICY_RESOURCES);
boolean hasAllDomainPattern = false;

for (int i = 0; i < resources.size(); i++) {
String[] resourceParts = resources.get(i).split(":");
String resource = resourceParts[resourceParts.length - 1];
if (resource.equals("*") || resource.equals("*/super") || resource.equals("default/domain/*/super")) {
resources.remove(i);
hasAllDomainPattern = true;
i--;
}
}
List<String> resources = (List<String>) policy.getAttribute(ATTR_POLICY_RESOURCES);
boolean hasAllDomainPattern = resources.stream().anyMatch(resource ->
resource.equals("entity:*") ||
resource.equals("entity:*/super") ||
resource.equals("entity:default/domain/*/super")
);

if (hasAllDomainPattern) {
for (int i = 0; i < resources.size(); i++) {
String[] resourceParts = resources.get(i).split(":");
String resource = resourceParts[resourceParts.length - 1];
if (resource.matches("default/domain/.+/super(/.+)?")) {
resources.remove(i);
i--;
}
}
resources.add(ENTITY_DEFAULT_DOMAIN_SUPER);
policy.setAttribute(ATTR_POLICY_RESOURCES, Collections.singletonList("entity:default/domain/*/super"));
}

policy.setAttribute(ATTR_POLICY_RESOURCES, resources);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,14 @@ private void processCreateStakeholderTitle(AtlasEntity entity) throws AtlasBaseE
if (CollectionUtils.isEmpty(domainQualifiedNames)) {
throw new AtlasBaseException(BAD_REQUEST, "Please provide attribute " + ATTR_DOMAIN_QUALIFIED_NAMES);
}
domainQualifiedNames.replaceAll(s -> s.equals(STAR) ? NEW_STAR : s);
if (domainQualifiedNames.contains(NEW_STAR)) {
if (domainQualifiedNames.contains(NEW_STAR) || domainQualifiedNames.contains(STAR)) {
if (domainQualifiedNames.size() > 1) {

domainQualifiedNames.clear();
domainQualifiedNames.add(NEW_STAR);
entity.setAttribute(ATTR_DOMAIN_QUALIFIED_NAMES, domainQualifiedNames);
} else {
domainQualifiedNames.replaceAll(s -> s.equals(STAR) ? NEW_STAR : s);
}

String qualifiedName = format(PATTERN_QUALIFIED_NAME_ALL_DOMAINS, getUUID());
Expand Down

0 comments on commit 0f70fb3

Please sign in to comment.