Skip to content

Commit 3fdb7ef

Browse files
committed
HPCC4J-637 DFSClient: FileUtility add credential prompting
- Added prompting for credentials if not specified via command line Signed-off-by: James McMullan [email protected]
1 parent 1fbbb35 commit 3fdb7ef

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

dfsclient/src/main/java/org/hpccsystems/dfs/client/FileUtility.java

+37-8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.ArrayList;
2424
import java.util.Arrays;
2525
import java.io.BufferedInputStream;
26+
import java.io.Console;
2627
import java.io.File;
2728
import java.io.FileInputStream;
2829
import java.io.FileOutputStream;
@@ -322,6 +323,28 @@ public JSONArray generateResultsMessage()
322323
}
323324
};
324325

326+
private static String[] getCredentials(CommandLine cmd)
327+
{
328+
Console console = System.console();
329+
330+
String user = cmd.getOptionValue("user");
331+
boolean userIsEmpty = user == null || user.isEmpty();
332+
if (userIsEmpty)
333+
{
334+
user = new String(console.readLine("Enter username: "));
335+
userIsEmpty = user == null || user.isEmpty();
336+
}
337+
338+
String pass = cmd.getOptionValue("pass");
339+
boolean passIsEmpty = pass == null || pass.isEmpty();
340+
if (!userIsEmpty && passIsEmpty)
341+
{
342+
pass = new String(console.readPassword("Enter password for " + user + ": "));
343+
}
344+
345+
return new String[] {user, pass};
346+
}
347+
325348
private static enum FileFormat
326349
{
327350
THOR,
@@ -1198,8 +1221,10 @@ private static void performRead(String[] args, TaskContext context)
11981221
}
11991222

12001223
String connString = cmd.getOptionValue("url");
1201-
String user = cmd.getOptionValue("user");
1202-
String pass = cmd.getOptionValue("pass");
1224+
1225+
String[] creds = getCredentials(cmd);
1226+
String user = creds[0];
1227+
String pass = creds[1];
12031228

12041229
String outputPath = cmd.getOptionValue("out",".");
12051230

@@ -1376,8 +1401,10 @@ private static void performReadTest(String[] args, TaskContext context)
13761401
}
13771402

13781403
String connString = cmd.getOptionValue("url");
1379-
String user = cmd.getOptionValue("user");
1380-
String pass = cmd.getOptionValue("pass");
1404+
1405+
String[] creds = getCredentials(cmd);
1406+
String user = creds[0];
1407+
String pass = creds[1];
13811408

13821409
String outputPath = cmd.getOptionValue("out",".");
13831410

@@ -1560,8 +1587,9 @@ private static void performCopy(String[] args, TaskContext context)
15601587
+ numThreadsStr + ", must be an integer. Defaulting to: " + NUM_DEFAULT_THREADS + " threads.");
15611588
}
15621589

1563-
String user = cmd.getOptionValue("user");
1564-
String pass = cmd.getOptionValue("pass");
1590+
String[] creds = getCredentials(cmd);
1591+
String user = creds[0];
1592+
String pass = creds[1];
15651593

15661594
String destClusterName = cmd.getOptionValue("dest_cluster");
15671595

@@ -1741,8 +1769,9 @@ private static void performWrite(String[] args, TaskContext context)
17411769
+ numThreadsStr + ", must be an integer. Defaulting to: " + NUM_DEFAULT_THREADS + " threads.");
17421770
}
17431771

1744-
String user = cmd.getOptionValue("user");
1745-
String pass = cmd.getOptionValue("pass");
1772+
String[] creds = getCredentials(cmd);
1773+
String user = creds[0];
1774+
String pass = creds[1];
17461775

17471776
String destClusterName = cmd.getOptionValue("dest_cluster");
17481777

0 commit comments

Comments
 (0)