kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lind...@apache.org
Subject [kafka] branch trunk updated: Revert 4e311 KAFKA-5690 since KIP-357 has not passed vote
Date Sun, 16 Sep 2018 07:17:37 GMT
This is an automated email from the ASF dual-hosted git repository.

lindong pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 3a8ab32  Revert 4e311 KAFKA-5690 since KIP-357 has not passed vote
3a8ab32 is described below

commit 3a8ab3258f8b461239bc7c0202f81c611745eee9
Author: Dong Lin <lindong28@gmail.com>
AuthorDate: Sun Sep 16 00:17:07 2018 -0700

    Revert 4e311 KAFKA-5690 since KIP-357 has not passed vote
---
 core/src/main/scala/kafka/admin/AclCommand.scala | 64 ++++--------------------
 1 file changed, 11 insertions(+), 53 deletions(-)

diff --git a/core/src/main/scala/kafka/admin/AclCommand.scala b/core/src/main/scala/kafka/admin/AclCommand.scala
index ad375d2..c2dda33 100644
--- a/core/src/main/scala/kafka/admin/AclCommand.scala
+++ b/core/src/main/scala/kafka/admin/AclCommand.scala
@@ -138,22 +138,10 @@ object AclCommand extends Logging {
     def listAcls(): Unit = {
       withAdminClient(opts) { adminClient =>
         val filters = getResourceFilter(opts, dieIfNoResourceFound = false)
-        val listPrincipals = getPrincipals(opts, opts.listPrincipalsOpt)
         val resourceToAcls = getAcls(adminClient, filters)
 
-        if (listPrincipals.isEmpty) {
-          for ((resource, acls) <- resourceToAcls)
-            println(s"Current ACLs for resource `$resource`: $Newline ${acls.map("\t" + _).mkString(Newline)}
$Newline")
-        } else {
-          listPrincipals.foreach(principal => {
-            println(s"ACLs for principal `$principal`")
-            val filteredResourceToAcls =  resourceToAcls.mapValues(acls =>
-              acls.filter(acl => principal.toString.equals(acl.principal))).filter(entry
=> entry._2.nonEmpty)
-
-            for ((resource, acls) <- filteredResourceToAcls)
-              println(s"Current ACLs for resource `$resource`: $Newline ${acls.map("\t" +
_).mkString(Newline)} $Newline")
-          })
-        }
+        for ((resource, acls) <- resourceToAcls)
+          println(s"Current ACLs for resource `$resource`: $Newline ${acls.map("\t" + _).mkString(Newline)}
$Newline")
       }
     }
 
@@ -249,20 +237,13 @@ object AclCommand extends Logging {
     def listAcls(): Unit = {
       withAuthorizer() { authorizer =>
         val filters = getResourceFilter(opts, dieIfNoResourceFound = false)
-        val listPrincipals = getPrincipals(opts, opts.listPrincipalsOpt)
 
-        if (listPrincipals.isEmpty) {
-          val resourceToAcls =  getFilteredResourceToAcls(authorizer, filters)
-          for ((resource, acls) <- resourceToAcls)
-            println(s"Current ACLs for resource `$resource`: $Newline ${acls.map("\t" + _).mkString(Newline)}
$Newline")
-        } else {
-          listPrincipals.foreach(principal => {
-            println(s"ACLs for principal `$principal`")
-            val resourceToAcls =  getFilteredResourceToAcls(authorizer, filters, Some(principal))
-            for ((resource, acls) <- resourceToAcls)
-              println(s"Current ACLs for resource `$resource`: $Newline ${acls.map("\t" +
_).mkString(Newline)} $Newline")
-          })
-        }
+        val resourceToAcls: Iterable[(Resource, Set[Acl])] =
+          if (filters.isEmpty) authorizer.getAcls()
+          else filters.flatMap(filter => getAcls(authorizer, filter))
+
+        for ((resource, acls) <- resourceToAcls)
+          println(s"Current ACLs for resource `$resource`: $Newline ${acls.map("\t" + _).mkString(Newline)}
$Newline")
       }
     }
 
@@ -275,23 +256,9 @@ object AclCommand extends Logging {
         )
     }
 
-    private def getFilteredResourceToAcls(authorizer: Authorizer, filters: Set[ResourcePatternFilter],
-                                          listPrincipal: Option[KafkaPrincipal] = None):
Iterable[(Resource, Set[Acl])] = {
-      if (filters.isEmpty)
-        if (listPrincipal.isEmpty)
-          authorizer.getAcls()
-        else
-          authorizer.getAcls(listPrincipal.get)
-      else filters.flatMap(filter => getAcls(authorizer, filter, listPrincipal))
-    }
-
-    private def getAcls(authorizer: Authorizer, filter: ResourcePatternFilter,
-                        listPrincipal: Option[KafkaPrincipal] = None): Map[Resource, Set[Acl]]
=
-      if (listPrincipal.isEmpty)
-        authorizer.getAcls().filter { case (resource, acl) => filter.matches(resource.toPattern)
}
-      else
-        authorizer.getAcls(listPrincipal.get).filter { case (resource, acl) => filter.matches(resource.toPattern)
}
-
+    private def getAcls(authorizer: Authorizer, filter: ResourcePatternFilter): Map[Resource,
Set[Acl]] =
+      authorizer.getAcls()
+        .filter { case (resource, acl) => filter.matches(resource.toPattern) }
   }
 
   private def getResourceToAcls(opts: AclCommandOptions): Map[Resource, Set[Acl]] = {
@@ -554,12 +521,6 @@ object AclCommand extends Logging {
       .describedAs("deny-principal")
       .ofType(classOf[String])
 
-    val listPrincipalsOpt = parser.accepts("principal", "List ACLs for the specified principal.
principal is in principalType:name format." +
-      " Note that principalType must be supported by the Authorizer being used. Multiple
--principal option can be passed.")
-      .withOptionalArg()
-      .describedAs("principal")
-      .ofType(classOf[String])
-
     val allowHostsOpt = parser.accepts("allow-host", "Host from which principals listed in
--allow-principal will have access. " +
       "If you have specified --allow-principal then the default for this option will be set
to * which allows access from all hosts.")
       .withRequiredArg
@@ -607,9 +568,6 @@ object AclCommand extends Logging {
       CommandLineUtils.checkInvalidArgs(parser, options, producerOpt, Set(operationsOpt,
denyPrincipalsOpt, denyHostsOpt))
       CommandLineUtils.checkInvalidArgs(parser, options, consumerOpt, Set(operationsOpt,
denyPrincipalsOpt, denyHostsOpt))
 
-      if (options.has(listPrincipalsOpt) && !options.has(listOpt))
-        CommandLineUtils.printUsageAndDie(parser, "The --principal option is only available
if --list is set")
-
       if (options.has(producerOpt) && !options.has(topicOpt))
         CommandLineUtils.printUsageAndDie(parser, "With --producer you must specify a --topic")
 


Mime
View raw message