mimaison commented on code in PR #22501:
URL: https://github.com/apache/kafka/pull/22501#discussion_r3451018932


##########
metadata/src/main/java/org/apache/kafka/metadata/authorizer/CidrUtils.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.metadata.authorizer;
+
+import org.apache.commons.net.util.SubnetUtils;
+import org.apache.commons.net.util.SubnetUtils6;
+
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public final class CidrUtils {
+
+    private CidrUtils() {}
+
+    public static InetAddress parseCidrAddress(String cidrPattern) {

Review Comment:
   It looks like this could be private



##########
metadata/src/main/java/org/apache/kafka/metadata/authorizer/CidrUtils.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.metadata.authorizer;
+
+import org.apache.commons.net.util.SubnetUtils;
+import org.apache.commons.net.util.SubnetUtils6;
+
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public final class CidrUtils {
+
+    private CidrUtils() {}
+
+    public static InetAddress parseCidrAddress(String cidrPattern) {
+        String ipPart = cidrPattern.contains("/")
+            ? cidrPattern.substring(0, cidrPattern.indexOf('/'))
+            : cidrPattern;
+        try {
+            return InetAddress.getByName(ipPart);
+        } catch (UnknownHostException e) {
+            throw new IllegalArgumentException("Invalid IP address in CIDR 
pattern '" + cidrPattern + "': " + e.getMessage());
+        }
+    }
+
+    public static boolean isIpv6(InetAddress address) {

Review Comment:
   This could be private too



##########
metadata/src/main/java/org/apache/kafka/controller/AclControlManager.java:
##########
@@ -92,14 +95,14 @@ private AclControlManager(
         this.existingAcls = new TimelineHashSet<>(snapshotRegistry, 0);
     }
 
-    ControllerResult<List<AclCreateResult>> createAcls(List<AclBinding> acls) {
+    ControllerResult<List<AclCreateResult>> createAcls(List<AclBinding> acls, 
MetadataVersion metadataVersion) {
         Set<StandardAcl> aclsToCreate = new HashSet<>(acls.size());
         List<AclCreateResult> results = new ArrayList<>(acls.size());
         List<ApiMessageAndVersion> records =
                 BoundedList.newArrayBacked(MAX_RECORDS_PER_USER_OP);
         for (AclBinding acl : acls) {
             try {
-                validateNewAcl(acl);
+                validateNewAcl(acl, metadataVersion);

Review Comment:
   Should we directly pass `metadataVersion.isCidrAclSupported()`?



##########
metadata/src/test/java/org/apache/kafka/metadata/authorizer/CidrUtilsTest.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.metadata.authorizer;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+
+import java.net.InetAddress;
+
+import static org.apache.kafka.metadata.authorizer.CidrUtils.isInRange;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+
+@Timeout(value = 40)
+public class CidrUtilsTest {

Review Comment:
   Should we have a unit test for `CidrUtils.validate()`?



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