diff --git a/dfsclient/src/main/java/org/hpccsystems/dfs/client/FileUtility.java b/dfsclient/src/main/java/org/hpccsystems/dfs/client/FileUtility.java index 116c37c21..c41ae0946 100644 --- a/dfsclient/src/main/java/org/hpccsystems/dfs/client/FileUtility.java +++ b/dfsclient/src/main/java/org/hpccsystems/dfs/client/FileUtility.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.io.BufferedInputStream; +import java.io.Console; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -322,6 +323,28 @@ public JSONArray generateResultsMessage() } }; + private static String[] getCredentials(CommandLine cmd) + { + Console console = System.console(); + + String user = cmd.getOptionValue("user"); + boolean userIsEmpty = user == null || user.isEmpty(); + if (userIsEmpty) + { + user = new String(console.readLine("Enter username: ")); + userIsEmpty = user == null || user.isEmpty(); + } + + String pass = cmd.getOptionValue("pass"); + boolean passIsEmpty = pass == null || pass.isEmpty(); + if (!userIsEmpty && passIsEmpty) + { + pass = new String(console.readPassword("Enter password for " + user + ": ")); + } + + return new String[] {user, pass}; + } + private static enum FileFormat { THOR, @@ -1198,8 +1221,10 @@ private static void performRead(String[] args, TaskContext context) } String connString = cmd.getOptionValue("url"); - String user = cmd.getOptionValue("user"); - String pass = cmd.getOptionValue("pass"); + + String[] creds = getCredentials(cmd); + String user = creds[0]; + String pass = creds[1]; String outputPath = cmd.getOptionValue("out","."); @@ -1376,8 +1401,10 @@ private static void performReadTest(String[] args, TaskContext context) } String connString = cmd.getOptionValue("url"); - String user = cmd.getOptionValue("user"); - String pass = cmd.getOptionValue("pass"); + + String[] creds = getCredentials(cmd); + String user = creds[0]; + String pass = creds[1]; String outputPath = cmd.getOptionValue("out","."); @@ -1560,8 +1587,9 @@ private static void performCopy(String[] args, TaskContext context) + numThreadsStr + ", must be an integer. Defaulting to: " + NUM_DEFAULT_THREADS + " threads."); } - String user = cmd.getOptionValue("user"); - String pass = cmd.getOptionValue("pass"); + String[] creds = getCredentials(cmd); + String user = creds[0]; + String pass = creds[1]; String destClusterName = cmd.getOptionValue("dest_cluster"); @@ -1741,8 +1769,9 @@ private static void performWrite(String[] args, TaskContext context) + numThreadsStr + ", must be an integer. Defaulting to: " + NUM_DEFAULT_THREADS + " threads."); } - String user = cmd.getOptionValue("user"); - String pass = cmd.getOptionValue("pass"); + String[] creds = getCredentials(cmd); + String user = creds[0]; + String pass = creds[1]; String destClusterName = cmd.getOptionValue("dest_cluster");