Skip to content

Commit

Permalink
Merge pull request #2907 from atlanhq/transform-datamesh-policies
Browse files Browse the repository at this point in the history
Fix DaapVisibility policies
  • Loading branch information
PRATHAM2002-DS authored Apr 1, 2024
2 parents c1337fc + 0b6fc6a commit c05f2c6
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
Expand All @@ -71,6 +72,7 @@
import static org.apache.atlas.repository.util.AccessControlUtils.ATTR_POLICY_PRIORITY;
import static org.apache.atlas.repository.util.AccessControlUtils.ATTR_POLICY_SERVICE_NAME;
import static org.apache.atlas.repository.util.AccessControlUtils.ATTR_POLICY_SUB_CATEGORY;
import static org.apache.atlas.repository.util.AccessControlUtils.POLICY_CATEGORY_DATAMESH;
import static org.apache.atlas.repository.util.AccessControlUtils.POLICY_CATEGORY_PERSONA;
import static org.apache.atlas.repository.util.AccessControlUtils.POLICY_CATEGORY_PURPOSE;
import static org.apache.atlas.repository.util.AccessControlUtils.getIsPolicyEnabled;
Expand Down Expand Up @@ -239,6 +241,18 @@ private List<RangerPolicy> transformAtlasPoliciesToRangerPolicies(List<AtlasEnti
rangerPolicies.add(toRangerPolicy(transformedPolicy, serviceType));
}

}
else if (POLICY_CATEGORY_DATAMESH.equals(policyCategory)) {
RangerPolicy rangerPolicy = getRangerPolicy(atlasPolicy, serviceType);

//GET policy Item
setPolicyItems(rangerPolicy, atlasPolicy);

//GET policy Resources
setPolicyResourcesForDatameshPolicies(rangerPolicy, atlasPolicy);

rangerPolicies.add(rangerPolicy);

} else {
rangerPolicies.add(toRangerPolicy(atlasPolicy, serviceType));
}
Expand All @@ -264,6 +278,26 @@ private RangerPolicy toRangerPolicy(AtlasEntityHeader atlasPolicy, String servic
}

private void setPolicyResources(RangerPolicy rangerPolicy, AtlasEntityHeader atlasPolicy) throws IOException {
rangerPolicy.setResources(getFinalResources(atlasPolicy));
}

private void setPolicyResourcesForDatameshPolicies(RangerPolicy rangerPolicy, AtlasEntityHeader atlasPolicy) {
Map<String, RangerPolicyResource> resources = getFinalResources(atlasPolicy);

if (resources.containsKey("entity-classification")) {
RangerPolicyResource resource = new RangerPolicyResource(Arrays.asList("*"), false, false);
resources.put("entity-classification", resource);
}

if (resources.containsKey("entity-type")) {
RangerPolicyResource resource = new RangerPolicyResource(Arrays.asList("*"), false, false);
resources.put("entity-type", resource);
}

rangerPolicy.setResources(resources);
}

private Map<String, RangerPolicyResource> getFinalResources(AtlasEntityHeader atlasPolicy) {
List<String> atlasResources = (List<String>) atlasPolicy.getAttribute("policyResources");

Map<String, List<String>> resourceValuesMap = new HashMap<>();
Expand All @@ -285,7 +319,7 @@ private void setPolicyResources(RangerPolicy rangerPolicy, AtlasEntityHeader atl
resources.put(key, resource);
}

rangerPolicy.setResources(resources);
return resources;
}

private <T> T getResourceAsObject(String resourceName, Class<T> clazz) throws IOException {
Expand Down

0 comments on commit c05f2c6

Please sign in to comment.