mneethiraj commented on code in PR #766:
URL: https://github.com/apache/ranger/pull/766#discussion_r2608547891


##########
plugin-ozone/src/main/java/org/apache/ranger/authorization/ozone/authorizer/RangerOzoneAuthorizer.java:
##########
@@ -221,4 +295,88 @@ private String mapToRangerAccessType(ACLType operation) {
 
         return rangerAccessType;
     }
+
+    private static RangerInlinePolicy.Grant 
toRangerGrant(AssumeRoleRequest.OzoneGrant ozoneGrant, RangerBasePlugin plugin) 
{
+        RangerInlinePolicy.Grant ret;
+
+        if (CollectionUtils.isEmpty(ozoneGrant.getObjects()) && 
CollectionUtils.isEmpty(ozoneGrant.getPermissions())) {
+            ret = null;
+        } else {
+            ret = new RangerInlinePolicy.Grant();
+
+            if (ozoneGrant.getObjects() != null) {
+                ret.setResources(ozoneGrant.getObjects().stream().map(o -> 
toRrn(o, plugin)).filter(Objects::nonNull).collect(Collectors.toSet()));
+            }
+
+            if (ozoneGrant.getPermissions() != null) {
+                
ret.setPermissions(ozoneGrant.getPermissions().stream().map(RangerOzoneAuthorizer::toRangerPermission).filter(Objects::nonNull).collect(Collectors.toSet()));
+            }
+        }
+
+        LOG.debug("toRangerGrant(ozoneGrant={}): ret={}", ozoneGrant, ret);
+
+        return ret;
+    }
+
+    private static String toRrn(IOzoneObj obj, RangerBasePlugin plugin) {
+        OzoneObj            ozoneObj = (OzoneObj) obj;
+        Map<String, String> resource = new HashMap<>();
+        String              resType  = null;
+
+        switch (ozoneObj.getResourceType()) {
+            case VOLUME:
+                resType = KEY_RESOURCE_VOLUME;
+
+                resource.put(KEY_RESOURCE_VOLUME, ozoneObj.getVolumeName());
+                break;
+
+            case BUCKET:
+                resType = KEY_RESOURCE_BUCKET;
+
+                resource.put(KEY_RESOURCE_VOLUME, ozoneObj.getStoreType() == 
OzoneObj.StoreType.S3 ? "s3Vol" : ozoneObj.getVolumeName());
+                resource.put(KEY_RESOURCE_BUCKET, ozoneObj.getBucketName());
+                break;
+
+            case KEY:
+                resType = KEY_RESOURCE_KEY;
+
+                resource.put(KEY_RESOURCE_VOLUME, ozoneObj.getStoreType() == 
OzoneObj.StoreType.S3 ? "s3Vol" : ozoneObj.getVolumeName());
+                resource.put(KEY_RESOURCE_BUCKET, ozoneObj.getBucketName());
+                resource.put(KEY_RESOURCE_KEY, ozoneObj.getKeyName());
+                break;
+        }
+
+        RangerResourceNameParser rrnParser = resType != null ? 
plugin.getServiceDefHelper().getRrnParser(resType) : null;
+        String                   ret       = rrnParser != null ? (resType + 
RangerResourceNameParser.RRN_RESOURCE_TYPE_SEP + 
rrnParser.toResourceName(resource)) : null;
+
+        LOG.debug("toRrn(ozoneObj={}): ret={}", ozoneObj, ret);
+
+        return ret;
+    }
+
+    private static String toRangerPermission(ACLType acl) {

Review Comment:
   I think `switch` might be a better choice as it will allow detection of 
unhandled enums by code scanner - when `ACLType` is updated with new entries. 
Also, I think `switch` will likely to be more efficient that a map look up :-)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to