directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject directory-kerby git commit: DIRKRB-713 Switching to use JLine for the AdminRemoteTool and HasInitTool.
Date Wed, 09 May 2018 02:04:40 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/trunk 5ca40b243 -> a09c3432f


DIRKRB-713 Switching to use JLine for the AdminRemoteTool and HasInitTool.


Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/a09c3432
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/a09c3432
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/a09c3432

Branch: refs/heads/trunk
Commit: a09c3432f39292e0982f86b7dbefa8d014e11a7a
Parents: 5ca40b2
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Wed May 9 10:04:26 2018 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Wed May 9 10:04:26 2018 +0800

----------------------------------------------------------------------
 .../kerby/has/client/HasAuthAdminClient.java    |  3 ++
 kerby-tool/has-tool/pom.xml                     | 26 +++++++-----
 .../kerberos/tool/admin/AdminRemoteTool.java    | 42 +++++++++++++++-----
 .../kerby/kerberos/tool/init/HasInitTool.java   | 38 ++++++++++++++----
 4 files changed, 79 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a09c3432/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasAuthAdminClient.java
----------------------------------------------------------------------
diff --git a/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasAuthAdminClient.java
b/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasAuthAdminClient.java
index 04b356d..ec27fb5 100644
--- a/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasAuthAdminClient.java
+++ b/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasAuthAdminClient.java
@@ -343,6 +343,9 @@ public class HasAuthAdminClient implements Kadmin {
         } catch (IOException e) {
             throw new KrbException("IO error occurred.", e);
         }
+        if (response == null) {
+            throw new KrbException("Please initial KDC first.");
+        }
         return stringtoList(response);
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a09c3432/kerby-tool/has-tool/pom.xml
----------------------------------------------------------------------
diff --git a/kerby-tool/has-tool/pom.xml b/kerby-tool/has-tool/pom.xml
index 3401025..920174d 100644
--- a/kerby-tool/has-tool/pom.xml
+++ b/kerby-tool/has-tool/pom.xml
@@ -12,17 +12,21 @@
     <artifactId>has-tool</artifactId>
 
     <dependencies>
-      <dependency>
-        <groupId>org.apache.kerby</groupId>
-        <artifactId>has-client</artifactId>
-        <version>${project.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.apache.kerby</groupId>
-        <artifactId>has-common</artifactId>
-        <version>${project.version}</version>
-      </dependency>
+        <dependency>
+            <groupId>org.apache.kerby</groupId>
+            <artifactId>has-client</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.kerby</groupId>
+            <artifactId>has-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.jline</groupId>
+            <artifactId>jline</artifactId>
+            <version>${jline.version}</version>
+        </dependency>
     </dependencies>
 
-
 </project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a09c3432/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/AdminRemoteTool.java
----------------------------------------------------------------------
diff --git a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/AdminRemoteTool.java
b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/AdminRemoteTool.java
index abf9f25..c9330b6 100644
--- a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/AdminRemoteTool.java
+++ b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/AdminRemoteTool.java
@@ -35,9 +35,17 @@ import org.apache.kerby.kerberos.tool.admin.cmd.GetHostRolesRemoteCmd;
 import org.apache.kerby.kerberos.tool.admin.cmd.ListPrincipalsRemoteCmd;
 import org.apache.kerby.kerberos.tool.admin.cmd.RenamePrincipalRemoteCmd;
 import org.apache.kerby.util.OSUtil;
+import org.jline.reader.Completer;
+import org.jline.reader.EndOfFileException;
+import org.jline.reader.LineReader;
+import org.jline.reader.LineReaderBuilder;
+import org.jline.reader.UserInterruptException;
+import org.jline.reader.impl.completer.StringsCompleter;
+import org.jline.terminal.Terminal;
+import org.jline.terminal.TerminalBuilder;
 
 import java.io.File;
-import java.util.Scanner;
+import java.io.IOException;
 
 public class AdminRemoteTool {
 
@@ -96,19 +104,31 @@ public class AdminRemoteTool {
         }
 
         System.out.println("enter \"cmd\" to see legal commands.");
-        System.out.print(PROMPT + ": ");
 
-        try (Scanner scanner = new Scanner(System.in, "UTF-8")) {
-            String input = scanner.nextLine();
+        Completer completer = new StringsCompleter("add_principal",
+                "delete_principal", "rename_principal", "list_principals",
+                "get_hostroles", "export_keytabs", "add_principals", "enable_configure",
+                "disable_configure");
 
-            while (!(input.equals("quit") || input.equals("exit") || input.equals("q")))
{
-                try {
-                    execute(authHasAdminClient, input);
-                } catch (KrbException e) {
-                    System.err.println(e.getMessage());
+        Terminal terminal = null;
+        try {
+            terminal = TerminalBuilder.terminal();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        LineReader lineReader = LineReaderBuilder.builder().completer(completer).terminal(terminal).build();
+
+        while (true) {
+            try {
+                String line = lineReader.readLine(PROMPT + ": ");
+                if ("quit".equals(line) || "exit".equals(line) || "q".equals(line)) {
+                    break;
                 }
-                System.out.print(PROMPT + ": ");
-                input = scanner.nextLine();
+                execute(authHasAdminClient, line);
+            } catch (UserInterruptException | EndOfFileException ex) {
+                break;
+            } catch (KrbException e) {
+                System.err.println(e.getMessage());
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a09c3432/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/HasInitTool.java
----------------------------------------------------------------------
diff --git a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/HasInitTool.java
b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/HasInitTool.java
index d8abb3e..cfd8a0f 100644
--- a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/HasInitTool.java
+++ b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/HasInitTool.java
@@ -33,9 +33,17 @@ import org.apache.kerby.kerberos.tool.init.cmd.InitKdcCmd;
 import org.apache.kerby.kerberos.tool.init.cmd.SetPluginCmd;
 import org.apache.kerby.kerberos.tool.init.cmd.StartKdcCmd;
 import org.apache.kerby.util.OSUtil;
+import org.jline.reader.Completer;
+import org.jline.reader.EndOfFileException;
+import org.jline.reader.LineReader;
+import org.jline.reader.LineReaderBuilder;
+import org.jline.reader.UserInterruptException;
+import org.jline.reader.impl.completer.StringsCompleter;
+import org.jline.terminal.Terminal;
+import org.jline.terminal.TerminalBuilder;
 
 import java.io.File;
-import java.util.Scanner;
+import java.io.IOException;
 
 public class HasInitTool {
     private static final String PROMPT = HasInitTool.class.getSimpleName();
@@ -82,19 +90,33 @@ public class HasInitTool {
 
         System.out.println(LEGAL_COMMANDS);
         System.out.println("enter \"<cmd> [?][-help]\" to get cmd help.");
-        Scanner scanner = new Scanner(System.in, "UTF-8");
-        System.out.print(PROMPT + ": ");
-        String input = scanner.nextLine();
 
         HasInitClient hasInitClient = new HasInitClient(hasConfig, new File(confDirPath));
-        while (!(input.equals("quit") || input.equals("exit") || input.equals("q"))) {
+
+        Completer completer = new StringsCompleter("get_krb5conf",
+                "get_hasConf", "set_plugin", "config_kdcBackend",
+                "config_kdc", "start_kdc", "init_kdc");
+
+        Terminal terminal = null;
+        try {
+            terminal = TerminalBuilder.terminal();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        LineReader lineReader = LineReaderBuilder.builder().completer(completer).terminal(terminal).build();
+
+        while (true) {
             try {
-                execute(hasInitClient, input);
+                String line = lineReader.readLine(PROMPT + ": ");
+                if ("quit".equals(line) || "exit".equals(line) || "q".equals(line)) {
+                    break;
+                }
+                execute(hasInitClient, line);
+            } catch (UserInterruptException | EndOfFileException ex) {
+                break;
             } catch (KrbException e) {
                 System.err.println(e.getMessage());
             }
-            System.out.print(PROMPT + ": ");
-            input = scanner.nextLine();
         }
     }
 


Mime
View raw message