Technoboy- commented on code in PR #23372:
URL: https://github.com/apache/pulsar/pull/23372#discussion_r1794708486


##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authorization/PulsarAuthorizationProvider.java:
##########
@@ -251,6 +254,68 @@ public CompletableFuture<Void> 
grantPermissionAsync(TopicName topicName, Set<Aut
         });
     }
 
+    public CompletableFuture<Void> 
grantPermissionAsync(List<GrantTopicPermissionOptions> options) {
+        return getPoliciesReadOnlyAsync().thenCompose(readonly -> {
+            if (readonly) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Policies are read-only. Broker cannot do 
read-write operations");
+                }
+                throw new IllegalStateException("policies are in readonly 
mode");
+            }
+            TopicName topicName = TopicName.get(options.get(0).getTopic());
+            return pulsarResources.getNamespaceResources()
+                    .setPoliciesAsync(topicName.getNamespaceObject(), policies 
-> {
+                        options.stream().forEach(o -> {
+                            final String topicUri = 
TopicName.get(o.getTopic()).toString();
+                            policies.auth_policies.getTopicAuthentication()
+                                    .computeIfAbsent(topicUri, __ -> new 
HashMap<>())
+                                    .put(o.getRole(), o.getActions());
+                        });
+                        return policies;
+                    }).whenComplete((__, ex) -> {
+                        if (ex != null) {
+                            log.error("Failed to grant permissions for {}", 
options);
+                        } else {
+                            log.info("Successfully granted access for {}", 
options);
+                        }
+                    });
+        });
+    }
+
+    @Override
+    public CompletableFuture<Void> 
revokePermissionAsync(List<RevokeTopicPermissionOptions> options) {
+        return getPoliciesReadOnlyAsync().thenCompose(readonly -> {
+            if (readonly) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Policies are read-only. Broker cannot do 
read-write operations");
+                }
+                throw new IllegalStateException("policies are in readonly 
mode");
+            }
+            TopicName topicName = TopicName.get(options.get(0).getTopic());
+            return pulsarResources.getNamespaceResources()
+                    .setPoliciesAsync(topicName.getNamespaceObject(), policies 
-> {

Review Comment:
   addressed



-- 
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