diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java b/beeline/src/java/org/apache/hive/beeline/BeeLine.java index 6d9494c..f29bbc2 100644 --- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java +++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java @@ -560,6 +560,8 @@ boolean initArgs(String[] args) { getOpts().setAuthType(auth); } else if (args[i].equals("-p")) { pass = args[i++ + 1]; + } else if (args[i].equals("-w")) { + pass = obtainPasswordFromFile(args[i++ + 1]); } else if (args[i].equals("-u")) { url = args[i++ + 1]; } else if (args[i].equals("-e")) { @@ -612,6 +614,18 @@ boolean initArgs(String[] args) { return true; } + /** + * Obtains a password from the passed file path. + */ + private String obtainPasswordFromFile(String passwordFilePath) { + try { + InputStream passwordIs = new FileInputStream(passwordFilePath); + byte[] passwordFileContents = org.apache.commons.io.IOUtils.toByteArray(passwordIs); + return new String(passwordFileContents, "UTF-8").trim(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } /** * Start accepting input from stdin, and dispatch it diff --git a/beeline/src/main/resources/BeeLine.properties b/beeline/src/main/resources/BeeLine.properties index bde43ba..dd32e6e 100644 --- a/beeline/src/main/resources/BeeLine.properties +++ b/beeline/src/main/resources/BeeLine.properties @@ -141,6 +141,7 @@ cmd-usage: Usage: java org.apache.hive.cli.beeline.BeeLine \n \ \ -u the JDBC URL to connect to\n \ \ -n the username to connect as\n \ \ -p the password to connect as\n \ +\ -w the password file to read the password from \n \ \ -d the driver class to use\n \ \ -e query that should be executed\n \ \ -f script file that should be executed\n \