ctubbsii commented on code in PR #3109:
URL: https://github.com/apache/accumulo/pull/3109#discussion_r1048981578
##########
server/manager/src/main/java/org/apache/accumulo/manager/upgrade/Upgrader9to10.java:
##########
@@ -143,43 +141,58 @@ public void upgradeZookeeper(ServerContext context) {
createScanServerNodes(context);
}
+ private static String extractAuthName(ACL acl) {
+ Objects.requireNonNull(acl, "provided ACL cannot be null");
+ try {
+ return acl.getId().getId().trim().split(":")[0];
+ } catch (Exception ex) {
+ log.debug("Invalid ACL passed, cannot parse id from '{}'", acl);
+ return "";
+ }
+ }
+
+ private static boolean canWrite(List<ACL> acls) {
+ if (ZooDefs.Ids.OPEN_ACL_UNSAFE.equals(acls)) {
+ return true;
+ }
+ ;
Review Comment:
```suggestion
```
##########
server/manager/src/main/java/org/apache/accumulo/manager/upgrade/Upgrader9to10.java:
##########
@@ -143,43 +141,58 @@ public void upgradeZookeeper(ServerContext context) {
createScanServerNodes(context);
}
+ private static String extractAuthName(ACL acl) {
+ Objects.requireNonNull(acl, "provided ACL cannot be null");
+ try {
+ return acl.getId().getId().trim().split(":")[0];
+ } catch (Exception ex) {
+ log.debug("Invalid ACL passed, cannot parse id from '{}'", acl);
+ return "";
+ }
+ }
+
+ private static boolean canWrite(List<ACL> acls) {
+ if (ZooDefs.Ids.OPEN_ACL_UNSAFE.equals(acls)) {
+ return true;
+ }
+ ;
+ for (ACL acl : acls) {
+ String name = extractAuthName(acl);
+ if (("accumulo".equals(name) || "anyone".equals(name))
+ && acl.getPerms() >= ZooDefs.Perms.WRITE) {
+ return true;
+ }
+ }
+ return false;
Review Comment:
This could be more readable with `Stream.findAny(Predicate)`. The whole
method becomes:
```java
// true if acls are open to all or if accumulo or anyone has WRITE
permission
return ZooDefs.Ids.OPEN_ACL_UNSAFE.equals(acls) ||
acls.stream().findAny(acl ->
Set.of("accumulo", "anyone").contains(extractAuthName(acl)) &&
acl.getPerms() >= ZooDefs.Perms.WRITE));
```
--
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]