From 403f1dcd4fde7dcb91eb1111824afac4dd703d3a Mon Sep 17 00:00:00 2001 From: bohlski Date: Tue, 14 Jun 2022 15:03:17 +0200 Subject: [PATCH 1/3] Fixed PutFileCmd showing -p argument --- .../bitrepository/commandline/CommandLineClient.java | 5 ----- .../org/bitrepository/commandline/DeleteFileCmd.java | 5 +++++ .../bitrepository/commandline/GetChecksumsCmd.java | 5 +++++ .../org/bitrepository/commandline/GetFileCmd.java | 6 ++++++ .../org/bitrepository/commandline/GetFileIDsCmd.java | 11 +++++++++++ .../org/bitrepository/commandline/ReplaceFileCmd.java | 5 +++++ 6 files changed, 32 insertions(+), 5 deletions(-) diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/CommandLineClient.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/CommandLineClient.java index 647d84359..eff5dba1d 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/CommandLineClient.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/CommandLineClient.java @@ -145,11 +145,6 @@ protected void createOptionsForCmdArgumentHandler() { Option fileIDOption = new Option(Constants.FILE_ID_ARG, Constants.HAS_ARGUMENT, "The id for the file to perform the operation on."); fileIDOption.setRequired(isFileIDArgumentRequired()); cmdHandler.addOption(fileIDOption); - - Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The id of the " + - "pillar where the operation should be performed. If undefined the operation is performed on all pillars."); - pillarOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); - cmdHandler.addOption(pillarOption); } /** diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/DeleteFileCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/DeleteFileCmd.java index d7f5929c5..b1c9b3fb5 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/DeleteFileCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/DeleteFileCmd.java @@ -73,6 +73,11 @@ protected boolean isFileIDArgumentRequired() { protected void createOptionsForCmdArgumentHandler() { super.createOptionsForCmdArgumentHandler(); + Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The id of the " + + "pillar where the operation should be performed. If undefined the operation is performed on all pillars."); + pillarOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + cmdHandler.addOption(pillarOption); + Option checksumOption = new Option(Constants.CHECKSUM_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The checksum of the file to be deleted."); checksumOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetChecksumsCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetChecksumsCmd.java index c9986d9f3..1cc16efce 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetChecksumsCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetChecksumsCmd.java @@ -72,6 +72,11 @@ protected boolean isFileIDArgumentRequired() { protected void createOptionsForCmdArgumentHandler() { super.createOptionsForCmdArgumentHandler(); + Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The id of the " + + "pillar where the operation should be performed. If undefined the operation is performed on all pillars."); + pillarOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + cmdHandler.addOption(pillarOption); + Option checksumTypeOption = new Option(Constants.REQUEST_CHECKSUM_TYPE_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The algorithm of checksum to request in the response from the pillars. " + "If no such argument is given, then the default from settings is retrieved."); diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileCmd.java index b5c92fe55..62ac389b4 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileCmd.java @@ -74,6 +74,12 @@ protected boolean isFileIDArgumentRequired() { @Override protected void createOptionsForCmdArgumentHandler() { super.createOptionsForCmdArgumentHandler(); + + Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The id of the " + + "pillar where the operation should be performed. If undefined the operation is performed on all pillars."); + pillarOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + cmdHandler.addOption(pillarOption); + Option checksumOption = new Option(Constants.LOCATION, Constants.HAS_ARGUMENT, "[OPTIONAL] The location where the file should be placed (either total path or directory). " + "If no argument, then the file is placed in the directory where the script is located."); diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileIDsCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileIDsCmd.java index bb9b447c9..54263f81b 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileIDsCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileIDsCmd.java @@ -21,6 +21,7 @@ */ package org.bitrepository.commandline; +import org.apache.commons.cli.Option; import org.bitrepository.access.AccessComponentFactory; import org.bitrepository.access.getfileids.GetFileIDsClient; import org.bitrepository.commandline.clients.PagingGetFileIDsClient; @@ -65,6 +66,16 @@ protected GetFileIDsCmd(String... args) { pagingClient = new PagingGetFileIDsClient(client, getTimeout(), pageSize, outputFormatter, output); } + @Override + protected void createOptionsForCmdArgumentHandler() { + super.createOptionsForCmdArgumentHandler(); + + Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The id of the " + + "pillar where the operation should be performed. If undefined the operation is performed on all pillars."); + pillarOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + cmdHandler.addOption(pillarOption); + } + @Override protected boolean isFileIDArgumentRequired() { return false; diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/ReplaceFileCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/ReplaceFileCmd.java index f14cd08bd..518e44c58 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/ReplaceFileCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/ReplaceFileCmd.java @@ -84,6 +84,11 @@ protected boolean isFileIDArgumentRequired() { protected void createOptionsForCmdArgumentHandler() { super.createOptionsForCmdArgumentHandler(); + Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The id of the " + + "pillar where the operation should be performed. If undefined the operation is performed on all pillars."); + pillarOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + cmdHandler.addOption(pillarOption); + Option checksumOption = new Option(CHECKSUM_ARG, HAS_ARGUMENT, "[OPTIONAL] The checksum of the file to be replaced."); checksumOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(checksumOption); From 2a0d1e6d0b8e4f4b5537b4f9252e52bfad4dd3c9 Mon Sep 17 00:00:00 2001 From: bohlski Date: Wed, 15 Jun 2022 09:31:17 +0200 Subject: [PATCH 2/3] Fixed -p argument showing as optional for Replace- and DeleteFileCmd when it's not --- .../bitrepository/commandline/Constants.java | 6 +++++- .../commandline/DeleteFileCmd.java | 5 ++--- .../commandline/GetChecksumsCmd.java | 4 ++-- .../bitrepository/commandline/GetFileCmd.java | 10 +++++----- .../commandline/GetFileIDsCmd.java | 4 ++-- .../commandline/ReplaceFileCmd.java | 17 ++++++++++++----- 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/Constants.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/Constants.java index 5b72d3f55..415efcc2f 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/Constants.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/Constants.java @@ -92,7 +92,11 @@ private Constants() {} /** * The argument for the location of the results. */ - public static final String LOCATION = "l"; + public static final String LOCATION_ARG = "l"; + + public static final String PILLAR_DESC = + "The id of the pillar where the operation should be performed. " + + "If undefined the operation is performed on all pillars."; public static final int EXIT_SUCCESS = 0; public static final int EXIT_ARGUMENT_FAILURE = 1; diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/DeleteFileCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/DeleteFileCmd.java index b1c9b3fb5..2957ae71b 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/DeleteFileCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/DeleteFileCmd.java @@ -73,9 +73,8 @@ protected boolean isFileIDArgumentRequired() { protected void createOptionsForCmdArgumentHandler() { super.createOptionsForCmdArgumentHandler(); - Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The id of the " + - "pillar where the operation should be performed. If undefined the operation is performed on all pillars."); - pillarOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, Constants.PILLAR_DESC); + pillarOption.setRequired(Constants.ARGUMENT_IS_REQUIRED); cmdHandler.addOption(pillarOption); Option checksumOption = new Option(Constants.CHECKSUM_ARG, Constants.HAS_ARGUMENT, diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetChecksumsCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetChecksumsCmd.java index 1cc16efce..a73fec1b3 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetChecksumsCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetChecksumsCmd.java @@ -72,8 +72,8 @@ protected boolean isFileIDArgumentRequired() { protected void createOptionsForCmdArgumentHandler() { super.createOptionsForCmdArgumentHandler(); - Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The id of the " + - "pillar where the operation should be performed. If undefined the operation is performed on all pillars."); + Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, + "[OPTIONAL] " + Constants.PILLAR_DESC); pillarOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(pillarOption); diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileCmd.java index 62ac389b4..e7101f148 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileCmd.java @@ -75,12 +75,12 @@ protected boolean isFileIDArgumentRequired() { protected void createOptionsForCmdArgumentHandler() { super.createOptionsForCmdArgumentHandler(); - Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The id of the " + - "pillar where the operation should be performed. If undefined the operation is performed on all pillars."); + Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, + "[OPTIONAL] " + Constants.PILLAR_DESC); pillarOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(pillarOption); - Option checksumOption = new Option(Constants.LOCATION, Constants.HAS_ARGUMENT, + Option checksumOption = new Option(Constants.LOCATION_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The location where the file should be placed (either total path or directory). " + "If no argument, then the file is placed in the directory where the script is located."); checksumOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); @@ -134,8 +134,8 @@ private OperationEvent performConversation() { private void downloadFile() { output.debug("Downloading the file."); File outputFile; - if (cmdHandler.hasOption(Constants.LOCATION)) { - File location = new File(cmdHandler.getOptionValue(Constants.LOCATION)); + if (cmdHandler.hasOption(Constants.LOCATION_ARG)) { + File location = new File(cmdHandler.getOptionValue(Constants.LOCATION_ARG)); if (location.isDirectory()) { outputFile = new File(location, cmdHandler.getOptionValue(Constants.FILE_ID_ARG)); } else { diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileIDsCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileIDsCmd.java index 54263f81b..db2f6744e 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileIDsCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/GetFileIDsCmd.java @@ -70,8 +70,8 @@ protected GetFileIDsCmd(String... args) { protected void createOptionsForCmdArgumentHandler() { super.createOptionsForCmdArgumentHandler(); - Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The id of the " + - "pillar where the operation should be performed. If undefined the operation is performed on all pillars."); + Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, + "[OPTIONAL] " + Constants.PILLAR_DESC); pillarOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(pillarOption); } diff --git a/bitrepository-client/src/main/java/org/bitrepository/commandline/ReplaceFileCmd.java b/bitrepository-client/src/main/java/org/bitrepository/commandline/ReplaceFileCmd.java index 518e44c58..a6f5a04b9 100644 --- a/bitrepository-client/src/main/java/org/bitrepository/commandline/ReplaceFileCmd.java +++ b/bitrepository-client/src/main/java/org/bitrepository/commandline/ReplaceFileCmd.java @@ -34,6 +34,7 @@ import java.net.URL; import static org.bitrepository.commandline.Constants.ARGUMENT_IS_NOT_REQUIRED; +import static org.bitrepository.commandline.Constants.ARGUMENT_IS_REQUIRED; import static org.bitrepository.commandline.Constants.CHECKSUM_ARG; import static org.bitrepository.commandline.Constants.DELETE_FILE_ARG; import static org.bitrepository.commandline.Constants.EXIT_ARGUMENT_FAILURE; @@ -84,22 +85,26 @@ protected boolean isFileIDArgumentRequired() { protected void createOptionsForCmdArgumentHandler() { super.createOptionsForCmdArgumentHandler(); - Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, "[OPTIONAL] The id of the " + - "pillar where the operation should be performed. If undefined the operation is performed on all pillars."); - pillarOption.setRequired(Constants.ARGUMENT_IS_NOT_REQUIRED); + Option pillarOption = new Option(Constants.PILLAR_ARG, Constants.HAS_ARGUMENT, Constants.PILLAR_DESC); + pillarOption.setRequired(Constants.ARGUMENT_IS_REQUIRED); cmdHandler.addOption(pillarOption); - Option checksumOption = new Option(CHECKSUM_ARG, HAS_ARGUMENT, "[OPTIONAL] The checksum of the file to be replaced."); + Option checksumOption = new Option(CHECKSUM_ARG, HAS_ARGUMENT, + "The checksum of the file to be replaced."); + // Setting can allow -C to be non-required, so set it as so. checksumOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(checksumOption); + Option fileOption = new Option(FILE_ARG, HAS_ARGUMENT, "The path to the new file for the replacement. Required unless using the URL argument."); fileOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(fileOption); + Option urlOption = new Option(URL_ARG, HAS_ARGUMENT, "The URL for the file to be retrieved. Is required, unless the actual file is given."); urlOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(urlOption); + Option replaceChecksumOption = new Option(REPLACE_CHECKSUM_ARG, HAS_ARGUMENT, "The checksum for the file to replace with. Required when using the URL argument."); replaceChecksumOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); @@ -109,8 +114,10 @@ protected void createOptionsForCmdArgumentHandler() { "[OPTIONAL] The algorithm of checksum to request in the response from the pillars."); checksumTypeOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(checksumTypeOption); + Option checksumSaltOption = new Option(REQUEST_CHECKSUM_SALT_ARG, HAS_ARGUMENT, - "[OPTIONAL] The salt of checksum to request in the response. Requires the ChecksumType argument."); + "[OPTIONAL] The salt of checksum to request in the response. " + + "Requires the ChecksumType argument."); checksumSaltOption.setRequired(ARGUMENT_IS_NOT_REQUIRED); cmdHandler.addOption(checksumSaltOption); From 860376f1722e724c9ba674518113fabfe1baa617 Mon Sep 17 00:00:00 2001 From: bohlski Date: Wed, 15 Jun 2022 10:18:05 +0200 Subject: [PATCH 3/3] Removed PutFile tests that tested the now removed pillar argument --- .../commandline/PutFileCmdTest.java | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/bitrepository-client/src/test/java/org/bitrepository/commandline/PutFileCmdTest.java b/bitrepository-client/src/test/java/org/bitrepository/commandline/PutFileCmdTest.java index d3a1b9a0e..09f429e0a 100644 --- a/bitrepository-client/src/test/java/org/bitrepository/commandline/PutFileCmdTest.java +++ b/bitrepository-client/src/test/java/org/bitrepository/commandline/PutFileCmdTest.java @@ -72,32 +72,6 @@ public void missingCollectionArgumentTest() throws Exception { new PutFileCmd(args); } - @Test(groups = { "regressiontest" }) - public void specificPillarArgumentTest() throws Exception { - addDescription("Test argument for a specific pillar"); - String[] args = new String[]{"-s" + SETTINGS_DIR, - "-k" + KEY_FILE, - "-u" + DEFAULT_UPLOAD_FILE_ADDRESS, - "-C" + DEFAULT_CHECKSUM, - "-c" + DEFAULT_COLLECTION_ID, - "-p" + PILLAR1_ID, - "-i" + DEFAULT_FILE_ID}; - new PutFileCmd(args); - } - - @Test(groups = { "regressiontest" }, expectedExceptions = IllegalArgumentException.class) - public void unknownPillarArgumentTest() throws Exception { - addDescription("Testing against a non-existing pillar id -> Should fail"); - String[] args = new String[]{"-s" + SETTINGS_DIR, - "-k" + KEY_FILE, - "-u" + DEFAULT_UPLOAD_FILE_ADDRESS, - "-C" + DEFAULT_CHECKSUM, - "-c" + DEFAULT_COLLECTION_ID, - "-p" + "Random" + (new Date()).getTime() + "pillar", - "-i" + DEFAULT_FILE_ID}; - new PutFileCmd(args); - } - @Test(groups = { "regressiontest" }, expectedExceptions = IllegalArgumentException.class) public void missingFileOrURLArgumentTest() throws Exception { addDescription("Tests the scenario, where no arguments for file or url is given.");