Skip to content

Commit

Permalink
Acquire password in cli when its stdout is a pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Praveen2112 authored and electrum committed Jun 18, 2019
1 parent 5a81eba commit 77ec764
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions presto-cli/src/main/java/io/prestosql/cli/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.prestosql.client.ClientSelectedRole;
import io.prestosql.client.ClientSession;
import io.prestosql.sql.parser.StatementSplitter;
import jline.console.ConsoleReader;
import jline.console.history.FileHistory;
import jline.console.history.History;
import jline.console.history.MemoryHistory;
Expand Down Expand Up @@ -169,14 +170,20 @@ private String getPassword()
}

java.io.Console console = System.console();
if (console == null) {
throw new RuntimeException("No console from which to read password");
if (console != null) {
char[] password = console.readPassword("Password: ");
if (password != null) {
return new String(password);
}
return "";
}
try {
ConsoleReader consoleReader = new ConsoleReader(System.in, System.err);
return consoleReader.readLine("Password: ", (char) 0);
}
char[] password = console.readPassword("Password: ");
if (password != null) {
return new String(password);
catch (IOException exception) {
throw new UncheckedIOException("Failed to read password from console", exception);
}
return "";
}

private static void runConsole(QueryRunner queryRunner, AtomicBoolean exiting)
Expand Down

0 comments on commit 77ec764

Please sign in to comment.