|
23 | 23 | import java.util.ArrayList;
|
24 | 24 | import java.util.Arrays;
|
25 | 25 | import java.io.BufferedInputStream;
|
| 26 | +import java.io.Console; |
26 | 27 | import java.io.File;
|
27 | 28 | import java.io.FileInputStream;
|
28 | 29 | import java.io.FileOutputStream;
|
@@ -322,6 +323,28 @@ public JSONArray generateResultsMessage()
|
322 | 323 | }
|
323 | 324 | };
|
324 | 325 |
|
| 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 | + |
325 | 348 | private static enum FileFormat
|
326 | 349 | {
|
327 | 350 | THOR,
|
@@ -1198,8 +1221,10 @@ private static void performRead(String[] args, TaskContext context)
|
1198 | 1221 | }
|
1199 | 1222 |
|
1200 | 1223 | 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]; |
1203 | 1228 |
|
1204 | 1229 | String outputPath = cmd.getOptionValue("out",".");
|
1205 | 1230 |
|
@@ -1376,8 +1401,10 @@ private static void performReadTest(String[] args, TaskContext context)
|
1376 | 1401 | }
|
1377 | 1402 |
|
1378 | 1403 | 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]; |
1381 | 1408 |
|
1382 | 1409 | String outputPath = cmd.getOptionValue("out",".");
|
1383 | 1410 |
|
@@ -1560,8 +1587,9 @@ private static void performCopy(String[] args, TaskContext context)
|
1560 | 1587 | + numThreadsStr + ", must be an integer. Defaulting to: " + NUM_DEFAULT_THREADS + " threads.");
|
1561 | 1588 | }
|
1562 | 1589 |
|
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]; |
1565 | 1593 |
|
1566 | 1594 | String destClusterName = cmd.getOptionValue("dest_cluster");
|
1567 | 1595 |
|
@@ -1741,8 +1769,9 @@ private static void performWrite(String[] args, TaskContext context)
|
1741 | 1769 | + numThreadsStr + ", must be an integer. Defaulting to: " + NUM_DEFAULT_THREADS + " threads.");
|
1742 | 1770 | }
|
1743 | 1771 |
|
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]; |
1746 | 1775 |
|
1747 | 1776 | String destClusterName = cmd.getOptionValue("dest_cluster");
|
1748 | 1777 |
|
|
0 commit comments