From c692f69b410cbfea8319e4e1fca60179fa477a8f Mon Sep 17 00:00:00 2001 From: Mickael Maison Date: Thu, 19 May 2016 18:37:32 +0100 Subject: [PATCH 1/2] 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 --- core/src/main/scala/kafka/admin/AclCommand.scala | 10 +++++++--- .../test/scala/unit/kafka/admin/AclCommandTest.scala | 4 +--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/src/main/scala/kafka/admin/AclCommand.scala b/core/src/main/scala/kafka/admin/AclCommand.scala index 01e95ca45b35..b697facfc6b5 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() { diff --git a/core/src/test/scala/unit/kafka/admin/AclCommandTest.scala b/core/src/test/scala/unit/kafka/admin/AclCommandTest.scala index d43d0d48dd2e..f2d963c2c9e4 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) } - } } } From 4ded03a41bd7ab21d3cba36de90a7756fadd1079 Mon Sep 17 00:00:00 2001 From: Mickael Maison Date: Wed, 25 May 2016 10:30:48 +0100 Subject: [PATCH 2/2] KAFKA-3732: Add an auto accept option to kafka-acls.sh Updated the docs to show the new option --- docs/security.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/security.html b/docs/security.html index 2459f5493bb2..e913ffa72022 100644 --- a/docs/security.html +++ b/docs/security.html @@ -576,6 +576,12 @@

Command Line Interface Convenience + + --yes + Convenience option to assume yes to all queries and do not prompt. + + Convenience +

Examples