From 85161dd008fd723c505c7f52134e4236fad4fe3b Mon Sep 17 00:00:00 2001 From: James McMullan Date: Mon, 16 Dec 2024 18:08:57 -0500 Subject: [PATCH] HPCC4J-642 DFSClient FileUtilityTest failing due to credential prompting (#751) Signed-off-by: James McMullan James.McMullan@lexisnexis.com --- .../org/hpccsystems/dfs/client/FileUtility.java | 14 ++++++++++---- .../hpccsystems/dfs/client/FileUtilityTest.java | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) 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 c46ee8f92..af78b4a29 100644 --- a/dfsclient/src/main/java/org/hpccsystems/dfs/client/FileUtility.java +++ b/dfsclient/src/main/java/org/hpccsystems/dfs/client/FileUtility.java @@ -327,9 +327,11 @@ private static String[] getCredentials(CommandLine cmd) { Console console = System.console(); + boolean nonInteractive = cmd.hasOption("non_interactive"); + String user = cmd.getOptionValue("user"); boolean userIsEmpty = user == null || user.isEmpty(); - if (userIsEmpty) + if (userIsEmpty && !nonInteractive) { user = new String(console.readLine("Enter username: ")); userIsEmpty = user == null || user.isEmpty(); @@ -337,7 +339,7 @@ private static String[] getCredentials(CommandLine cmd) String pass = cmd.getOptionValue("pass"); boolean passIsEmpty = pass == null || pass.isEmpty(); - if (!userIsEmpty && passIsEmpty) + if (!userIsEmpty && passIsEmpty & !nonInteractive) { pass = new String(console.readPassword("Enter password for " + user + ": ")); } @@ -551,6 +553,7 @@ private static Options getReadOptions() options.addOption("format", true, "Specifies the output format to be used when writing files to disk. Defaults to Thor files."); options.addOption("num_threads", true, "Specifies the number of parallel to use to perform operations."); options.addOption("out", true, "Specifies the directory that the files should be written to."); + options.addOption("non_interactive", false, "Disables prompting for credentials if they are not provided."); options.addOption(Option.builder("read") .argName("files") @@ -571,6 +574,7 @@ private static Options getReadTestOptions() options.addOption("pass", true, "Specifies the password used to connect. Defaults to null."); options.addOption("num_threads", true, "Specifies the number of parallel to use to perform operations."); options.addOption("access_expiry_seconds", true, "Access token expiration seconds."); + options.addOption("non_interactive", false, "Disables prompting for credentials if they are not provided."); options.addOption(Option.builder("file_parts") .argName("_file_parts") @@ -590,6 +594,7 @@ private static Options getCopyOptions() options.addRequiredOption("dest_cluster", "Destination Cluster Name", true, "Specifies the name of the cluster to write files back to."); options.addOption("dest_url", "Destination Cluster URL", true, "Specifies the URL of the ESP to write to."); options.addOption("num_threads", true, "Specifies the number of parallel to use to perform operations."); + options.addOption("non_interactive", false, "Disables prompting for credentials if they are not provided."); options.addOption(Option.builder("copy") .argName("files") @@ -611,6 +616,7 @@ private static Options getWriteOptions() options.addOption("dest_url", "Destination Cluster URL", true, "Specifies the URL of the ESP to write to."); options.addRequiredOption("dest_cluster", "Destination Cluster Name", true, "Specifies the name of the cluster to write files back to."); options.addOption("num_threads", true, "Specifies the number of parallel to use to perform operations."); + options.addOption("non_interactive", false, "Disables prompting for credentials if they are not provided."); options.addOption(Option.builder("write") .argName("files") @@ -1738,14 +1744,14 @@ private static void performCopy(String[] args, TaskContext context) { String readArgs[] = {"-read", srcFile, "-url", srcURL, "-format", "thor", "-user", user, "-pass", pass, - "-out", "tmp-read"}; + "-out", "tmp-read", "-non_interactive"}; performRead(readArgs, context); String writeArgs[] = {"-write", "tmp-read" + File.separator + srcFile.replace(':', '_') + "*" + " " + destFile, "-url", srcURL, "-dest_url", destURL, "-dest_cluster", destClusterName, - "-user", user, "-pass", pass }; + "-user", user, "-pass", pass, "-non_interactive"}; performWrite(writeArgs, context); } diff --git a/dfsclient/src/test/java/org/hpccsystems/dfs/client/FileUtilityTest.java b/dfsclient/src/test/java/org/hpccsystems/dfs/client/FileUtilityTest.java index f62c3d39a..eeb068b8e 100644 --- a/dfsclient/src/test/java/org/hpccsystems/dfs/client/FileUtilityTest.java +++ b/dfsclient/src/test/java/org/hpccsystems/dfs/client/FileUtilityTest.java @@ -46,7 +46,7 @@ public void thorFileTests() { { String readArgs[] = {"-read", "benchmark::integer::20kb", "-url", this.connString, - "-format", "thor", "-user", this.hpccUser, "-pass", this.hpccPass }; + "-format", "thor", "-user", this.hpccUser, "-pass", this.hpccPass, "-non_interactive" }; JSONArray results = FileUtility.run(readArgs); JSONObject result = results.optJSONObject(0); @@ -58,7 +58,7 @@ public void thorFileTests() { String readArgs[] = {"-read_test", "benchmark::integer::20kb", "-url", this.connString, - "-user", this.hpccUser, "-pass", this.hpccPass, "-file_parts", "1" }; + "-user", this.hpccUser, "-pass", this.hpccPass, "-file_parts", "1", "-non_interactive" }; JSONArray results = FileUtility.run(readArgs); JSONObject result = results.optJSONObject(0); @@ -72,7 +72,7 @@ public void thorFileTests() String copyArgs[] = {"-copy", "benchmark::integer::20kb benchmark::integer::20kb-copy", "-url", this.connString, "-dest_url", this.connString, "-dest_cluster", this.thorClusterFileGroup, - "-user", this.hpccUser, "-pass", this.hpccPass }; + "-user", this.hpccUser, "-pass", this.hpccPass, "-non_interactive" }; JSONArray results = FileUtility.run(copyArgs); JSONObject result = results.optJSONObject(0); @@ -87,7 +87,7 @@ public void thorFileTests() String writeArgs[] = {"-write", localDir + "benchmark__integer__20kb* benchmark::integer::20kb_write", "-url", this.connString, "-dest_url", this.connString, "-dest_cluster", this.thorClusterFileGroup, - "-user", this.hpccUser, "-pass", this.hpccPass }; + "-user", this.hpccUser, "-pass", this.hpccPass, "-non_interactive" }; JSONArray results = FileUtility.run(writeArgs); JSONObject result = results.optJSONObject(0);