Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPCC4J-637 DFSClient: FileUtility add credential prompting #744

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",".");

Expand Down Expand Up @@ -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",".");

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand Down
Loading