Repository: kafka Updated Branches: refs/heads/trunk fee6f6f92 -> 5653249e0
KAFKA-3732: Add an auto accept option to kafka-acls.sh Added a new argument to AclCommand: --yes. When set, automatically answer yes to prompts Author: Mickael Maison <[email protected]> Reviewers: Gwen Shapira Closes #1406 from mimaison/KAFKA-3732 Project: http://git-wip-us.apache.org/repos/asf/kafka/repo Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/5653249e Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/5653249e Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/5653249e Branch: refs/heads/trunk Commit: 5653249e08b1050f0e2081bf1dcc50324b3ec409 Parents: fee6f6f Author: Mickael Maison <[email protected]> Authored: Wed May 25 11:25:04 2016 -0700 Committer: Gwen Shapira <[email protected]> Committed: Wed May 25 11:25:04 2016 -0700 ---------------------------------------------------------------------- core/src/main/scala/kafka/admin/AclCommand.scala | 10 +++++++--- core/src/test/scala/unit/kafka/admin/AclCommandTest.scala | 4 +--- docs/security.html | 6 ++++++ 3 files changed, 14 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kafka/blob/5653249e/core/src/main/scala/kafka/admin/AclCommand.scala ---------------------------------------------------------------------- diff --git a/core/src/main/scala/kafka/admin/AclCommand.scala b/core/src/main/scala/kafka/admin/AclCommand.scala index 01e95ca..b697fac 100644 --- a/core/src/main/scala/kafka/admin/AclCommand.scala +++ b/core/src/main/scala/kafka/admin/AclCommand.scala @@ -99,10 +99,10 @@ object AclCommand { for ((resource, acls) <- resourceToAcl) { if (acls.isEmpty) { - if (confirmAction(s"Are you sure you want to delete all ACLs for resource `${resource}`? (y/n)")) + if (confirmAction(opts, s"Are you sure you want to delete all ACLs for resource `${resource}`? (y/n)")) authorizer.removeAcls(resource) } else { - if (confirmAction(s"Are you sure you want to remove ACLs: $Newline ${acls.map("\t" + _).mkString(Newline)} $Newline from resource `${resource}`? (y/n)")) + if (confirmAction(opts, s"Are you sure you want to remove ACLs: $Newline ${acls.map("\t" + _).mkString(Newline)} $Newline from resource `${resource}`? (y/n)")) authorizer.removeAcls(acls, resource) } } @@ -241,7 +241,9 @@ object AclCommand { resources } - private def confirmAction(msg: String): Boolean = { + private def confirmAction(opts: AclCommandOptions, msg: String): Boolean = { + if (opts.options.has(opts.yesOpt)) + return true println(msg) Console.readLine().equalsIgnoreCase("y") } @@ -329,6 +331,8 @@ object AclCommand { val helpOpt = parser.accepts("help", "Print usage information.") + val yesOpt = parser.accepts("yes", "Assume Yes to all queries and do not prompt.") + val options = parser.parse(args: _*) def checkArgs() { http://git-wip-us.apache.org/repos/asf/kafka/blob/5653249e/core/src/test/scala/unit/kafka/admin/AclCommandTest.scala ---------------------------------------------------------------------- diff --git a/core/src/test/scala/unit/kafka/admin/AclCommandTest.scala b/core/src/test/scala/unit/kafka/admin/AclCommandTest.scala index d43d0d4..f2d963c 100644 --- a/core/src/test/scala/unit/kafka/admin/AclCommandTest.scala +++ b/core/src/test/scala/unit/kafka/admin/AclCommandTest.scala @@ -116,12 +116,10 @@ class AclCommandTest extends ZooKeeperTestHarness with Logging { private def testRemove(resources: Set[Resource], resourceCmd: Array[String], args: Array[String], brokerProps: Properties) { for (resource <- resources) { - Console.withIn(new StringReader(s"y${AclCommand.Newline}" * resources.size)) { - AclCommand.main(args ++ resourceCmd :+ "--remove") + AclCommand.main(args ++ resourceCmd :+ "--remove" :+ "--yes") withAuthorizer(brokerProps) { authorizer => TestUtils.waitAndVerifyAcls(Set.empty[Acl], authorizer, resource) } - } } } http://git-wip-us.apache.org/repos/asf/kafka/blob/5653249e/docs/security.html ---------------------------------------------------------------------- diff --git a/docs/security.html b/docs/security.html index 2459f54..e913ffa 100644 --- a/docs/security.html +++ b/docs/security.html @@ -576,6 +576,12 @@ Kafka Authorization management CLI can be found under bin directory with all the <td></td> <td>Convenience</td> </tr> + <tr> + <td>--yes</td> + <td> Convenience option to assume yes to all queries and do not prompt.</td> + <td></td> + <td>Convenience</td> + </tr> </tbody></table> <h4><a id="security_authz_examples" href="#security_authz_examples">Examples</a></h4>
