summaryrefslogtreecommitdiffstats
path: root/base/java-tools/src/com/netscape/cmstools/cert
diff options
context:
space:
mode:
authorMatthew Harmsen <mharmsen@redhat.com>2014-04-25 19:55:35 -0700
committerMatthew Harmsen <mharmsen@redhat.com>2014-04-29 14:19:36 -0700
commit7b6b60b7d8d26799ea1bda48e6e51fa05854c80e (patch)
treee51a0d515e8a9a2b9f80dee491fca5217054adf5 /base/java-tools/src/com/netscape/cmstools/cert
parent05fea2520ae50d74f18017b26f5d58936e29af07 (diff)
downloadpki-7b6b60b7d8d26799ea1bda48e6e51fa05854c80e.tar.gz
pki-7b6b60b7d8d26799ea1bda48e6e51fa05854c80e.tar.xz
pki-7b6b60b7d8d26799ea1bda48e6e51fa05854c80e.zip
Fixed issue by streamlining code to be more consistent.
* PKI TRAC Ticket #843 - Incorrect CLI argument parsing
Diffstat (limited to 'base/java-tools/src/com/netscape/cmstools/cert')
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cert/CertFindCLI.java189
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cert/CertHoldCLI.java28
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cert/CertReleaseHoldCLI.java28
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cert/CertRequestFindCLI.java85
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileFindCLI.java27
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileShowCLI.java34
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cert/CertRequestReviewCLI.java34
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cert/CertRequestShowCLI.java27
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cert/CertRequestSubmitCLI.java22
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cert/CertRevokeCLI.java30
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cert/CertShowCLI.java32
11 files changed, 306 insertions, 230 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertFindCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertFindCLI.java
index 333a3daca..8c7a4df14 100644
--- a/base/java-tools/src/com/netscape/cmstools/cert/CertFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertFindCLI.java
@@ -21,6 +21,7 @@ package com.netscape.cmstools.cert;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
@@ -46,102 +47,15 @@ public class CertFindCLI extends CLI {
public CertFindCLI(CertCLI certCLI) {
super("find", "Find certificates", certCLI);
this.certCLI = certCLI;
+
+ createOptions();
}
public void printHelp() {
formatter.printHelp(getFullName() + " [OPTIONS...]", options);
}
- public void execute(String[] args) throws Exception {
-
- addOptions();
-
- CommandLine cmd = null;
- CertSearchRequest searchData = null;
- try {
- cmd = parser.parse(options, args);
- } catch (ParseException e) {
- System.err.println("Error: " + e.getMessage());
- printHelp();
- System.exit(1);
- }
-
- if (cmd.hasOption("help")) {
- // Display usage
- printHelp();
- System.exit(0);
- }
-
- String fileName = null;
-
- if (cmd.hasOption("input")) {
- fileName = cmd.getOptionValue("input");
- if (fileName == null || fileName.length() < 1) {
- System.err.println("Error: No file name specified.");
- printHelp();
- System.exit(1);
- }
- }
-
- if (fileName != null) {
- FileReader reader = null;
- try {
- reader = new FileReader(fileName);
- searchData = CertSearchRequest.valueOf(reader);
-
- } catch (FileNotFoundException e) {
- System.err.println("Error: " + e.getMessage());
- System.exit(1);
-
- } catch (JAXBException e) {
- System.err.println("Error: " + e.getMessage());
- System.exit(1);
-
- } finally {
- if (reader != null)
- try {
- reader.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- } else {
- searchData = new CertSearchRequest();
- searchData.setSerialNumberRangeInUse(true);
- }
-
- String s = cmd.getOptionValue("start");
- Integer start = s == null ? null : Integer.valueOf(s);
-
- s = cmd.getOptionValue("size");
- Integer size = s == null ? null : Integer.valueOf(s);
-
- addSearchAttribute(cmd, searchData);
-
- CertDataInfos certs = certCLI.certClient.findCerts(searchData, start, size);
-
- MainCLI.printMessage(certs.getTotal() + " entries found");
- if (certs.getTotal() == 0) return;
-
- boolean first = true;
-
- Collection<CertDataInfo> entries = certs.getEntries();
- for (CertDataInfo cert : entries) {
- if (first) {
- first = false;
- } else {
- System.out.println();
- }
-
- CertCLI.printCertInfo(cert);
- }
-
- MainCLI.printMessage("Number of entries returned " + certs.getEntries().size());
- }
-
- public void addOptions() {
-
+ public void createOptions() {
Option option = null;
//pagination options
@@ -277,6 +191,101 @@ public class CertFindCLI extends CLI {
options.addOption(option);
}
+ public void execute(String[] args) throws Exception {
+ // Always check for "--help" prior to parsing
+ if (Arrays.asList(args).contains("--help")) {
+ // Display usage
+ printHelp();
+ System.exit(0);
+ }
+
+ CommandLine cmd = null;
+
+ try {
+ cmd = parser.parse(options, args);
+ } catch (ParseException e) {
+ System.err.println("Error: " + e.getMessage());
+ printHelp();
+ System.exit(-1);
+ }
+
+ String[] cmdArgs = cmd.getArgs();
+
+ if (cmdArgs.length != 0) {
+ System.err.println("Error: Too many arguments specified.");
+ printHelp();
+ System.exit(-1);
+ }
+
+ CertSearchRequest searchData = null;
+ String fileName = null;
+
+ if (cmd.hasOption("input")) {
+ fileName = cmd.getOptionValue("input");
+ if (fileName == null || fileName.length() < 1) {
+ System.err.println("Error: No file name specified.");
+ printHelp();
+ System.exit(-1);
+ }
+ }
+
+ if (fileName != null) {
+ FileReader reader = null;
+ try {
+ reader = new FileReader(fileName);
+ searchData = CertSearchRequest.valueOf(reader);
+
+ } catch (FileNotFoundException e) {
+ System.err.println("Error: " + e.getMessage());
+ System.exit(-1);
+
+ } catch (JAXBException e) {
+ System.err.println("Error: " + e.getMessage());
+ System.exit(-1);
+
+ } finally {
+ if (reader != null)
+ try {
+ reader.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ } else {
+ searchData = new CertSearchRequest();
+ searchData.setSerialNumberRangeInUse(true);
+ }
+
+ String s = cmd.getOptionValue("start");
+ Integer start = s == null ? null : Integer.valueOf(s);
+
+ s = cmd.getOptionValue("size");
+ Integer size = s == null ? null : Integer.valueOf(s);
+
+ addSearchAttribute(cmd, searchData);
+
+ CertDataInfos certs = certCLI.certClient.findCerts(searchData, start, size);
+
+ MainCLI.printMessage(certs.getTotal() + " entries found");
+ if (certs.getTotal() == 0) return;
+
+ boolean first = true;
+
+ Collection<CertDataInfo> entries = certs.getEntries();
+ for (CertDataInfo cert : entries) {
+ if (first) {
+ first = false;
+ } else {
+ System.out.println();
+ }
+
+ CertCLI.printCertInfo(cert);
+ }
+
+ MainCLI.printMessage("Number of entries returned " + certs.getEntries().size());
+ }
+
public Long convertValidityDurationUnit(String unit) {
if (unit.equalsIgnoreCase("day")) {
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertHoldCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertHoldCLI.java
index eb4f619a4..a4b184871 100644
--- a/base/java-tools/src/com/netscape/cmstools/cert/CertHoldCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertHoldCLI.java
@@ -20,6 +20,7 @@ package com.netscape.cmstools.cert;
import java.io.BufferedReader;
import java.io.InputStreamReader;
+import java.util.Arrays;
import netscape.security.x509.RevocationReason;
@@ -44,19 +45,29 @@ public class CertHoldCLI extends CLI {
public CertHoldCLI(CertCLI certCLI) {
super("hold", "Place certificate on-hold", certCLI);
this.certCLI = certCLI;
+
+ createOptions();
}
public void printHelp() {
formatter.printHelp(getFullName() + " <Serial Number> [OPTIONS...]", options);
}
- public void execute(String[] args) throws Exception {
-
+ public void createOptions() {
Option option = new Option(null, "comments", true, "Comments");
option.setArgName("comments");
options.addOption(option);
options.addOption(null, "force", false, "Force");
+ }
+
+ public void execute(String[] args) throws Exception {
+ // Always check for "--help" prior to parsing
+ if (Arrays.asList(args).contains("--help")) {
+ // Display usage
+ printHelp();
+ System.exit(0);
+ }
CommandLine cmd = null;
@@ -66,20 +77,15 @@ public class CertHoldCLI extends CLI {
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
printHelp();
- System.exit(1);
- }
-
- if (cmd.hasOption("help")) {
- // Display usage
- printHelp();
- System.exit(0);
+ System.exit(-1);
}
String[] cmdArgs = cmd.getArgs();
if (cmdArgs.length != 1) {
+ System.err.println("Error: Missing Serial Number.");
printHelp();
- System.exit(1);
+ System.exit(-1);
}
CertId certID = new CertId(cmdArgs[0]);
@@ -98,7 +104,7 @@ public class CertHoldCLI extends CLI {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line = reader.readLine();
if (!line.equalsIgnoreCase("Y")) {
- System.exit(1);
+ System.exit(-1);
}
}
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertReleaseHoldCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertReleaseHoldCLI.java
index 5917a0105..42a8ae9ca 100644
--- a/base/java-tools/src/com/netscape/cmstools/cert/CertReleaseHoldCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertReleaseHoldCLI.java
@@ -20,6 +20,7 @@ package com.netscape.cmstools.cert;
import java.io.BufferedReader;
import java.io.InputStreamReader;
+import java.util.Arrays;
import org.apache.commons.cli.CommandLine;
@@ -41,15 +42,25 @@ public class CertReleaseHoldCLI extends CLI {
public CertReleaseHoldCLI(CertCLI certCLI) {
super("release-hold", "Place certificate off-hold", certCLI);
this.certCLI = certCLI;
+
+ createOptions();
}
public void printHelp() {
formatter.printHelp(getFullName() + " <Serial Number> [OPTIONS...]", options);
}
- public void execute(String[] args) throws Exception {
-
+ public void createOptions() {
options.addOption(null, "force", false, "Force");
+ }
+
+ public void execute(String[] args) throws Exception {
+ // Always check for "--help" prior to parsing
+ if (Arrays.asList(args).contains("--help")) {
+ // Display usage
+ printHelp();
+ System.exit(0);
+ }
CommandLine cmd = null;
@@ -59,20 +70,15 @@ public class CertReleaseHoldCLI extends CLI {
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
printHelp();
- System.exit(1);
- }
-
- if (cmd.hasOption("help")) {
- // Display usage
- printHelp();
- System.exit(0);
+ System.exit(-1);
}
String[] cmdArgs = cmd.getArgs();
if (cmdArgs.length != 1) {
+ System.err.println("Error: Missing Serial Number.");
printHelp();
- System.exit(1);
+ System.exit(-1);
}
CertId certID = new CertId(cmdArgs[0]);
@@ -91,7 +97,7 @@ public class CertReleaseHoldCLI extends CLI {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line = reader.readLine();
if (!line.equalsIgnoreCase("Y")) {
- System.exit(1);
+ System.exit(-1);
}
}
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestFindCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestFindCLI.java
index 8024a042a..2d8779d07 100644
--- a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestFindCLI.java
@@ -18,6 +18,7 @@
package com.netscape.cmstools.cert;
+import java.util.Arrays;
import java.util.Collection;
import org.apache.commons.cli.CommandLine;
@@ -40,17 +41,56 @@ public class CertRequestFindCLI extends CLI {
public CertRequestFindCLI(CertCLI certCLI) {
super("request-find", "Find certificate requests", certCLI);
this.certCLI = certCLI;
+
+ createOptions();
}
public void printHelp() {
formatter.printHelp(getFullName() + " [OPTIONS...]", options);
}
- public void execute(String[] args) throws Exception {
+ public void createOptions() {
+ Option option = null;
+
+ // request state
+ option = new Option(null, "status", true, "Request status (pending, cancelled, rejected, complete, all)");
+ option.setArgName("status");
+ options.addOption(option);
- addOptions();
+ // request type
+ option = new Option(null, "type", true, "Request type (enrollment, renewal, revocation, all)");
+ option.setArgName("type");
+ options.addOption(option);
+
+ //pagination options
+ option = new Option(null, "start", true, "Page start");
+ option.setArgName("start");
+ options.addOption(option);
+
+ option = new Option(null, "size", true, "Page size");
+ option.setArgName("size");
+ options.addOption(option);
+
+ //search limits
+ option = new Option(null, "maxResults", true, "Maximum number of results");
+ option.setArgName("maxResults");
+ options.addOption(option);
+
+ option = new Option(null, "timeout", true, "Search timeout");
+ option.setArgName("maxTime");
+ options.addOption(option);
+ }
+
+ public void execute(String[] args) throws Exception {
+ // Always check for "--help" prior to parsing
+ if (Arrays.asList(args).contains("--help")) {
+ // Display usage
+ printHelp();
+ System.exit(0);
+ }
CommandLine cmd = null;
+
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
@@ -59,10 +99,12 @@ public class CertRequestFindCLI extends CLI {
System.exit(-1);
}
- if (cmd.hasOption("help")) {
- // Display usage
+ String[] cmdArgs = cmd.getArgs();
+
+ if (cmdArgs.length != 0) {
+ System.err.println("Error: Too many arguments specified.");
printHelp();
- System.exit(0);
+ System.exit(-1);
}
String s = cmd.getOptionValue("start");
@@ -103,37 +145,4 @@ public class CertRequestFindCLI extends CLI {
MainCLI.printMessage("Number of entries returned " + entries.size());
}
-
- public void addOptions() {
-
- Option option = null;
-
- // request state
- option = new Option(null, "status", true, "Request status (pending, cancelled, rejected, complete, all)");
- option.setArgName("status");
- options.addOption(option);
-
- // request type
- option = new Option(null, "type", true, "Request type (enrollment, renewal, revocation, all)");
- option.setArgName("type");
- options.addOption(option);
-
- //pagination options
- option = new Option(null, "start", true, "Page start");
- option.setArgName("start");
- options.addOption(option);
-
- option = new Option(null, "size", true, "Page size");
- option.setArgName("size");
- options.addOption(option);
-
- //search limits
- option = new Option(null, "maxResults", true, "Maximum number of results");
- option.setArgName("maxResults");
- options.addOption(option);
-
- option = new Option(null, "timeout", true, "Search timeout");
- option.setArgName("maxTime");
- options.addOption(option);
- }
}
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileFindCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileFindCLI.java
index 85616a95b..d36fb590e 100644
--- a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileFindCLI.java
@@ -1,5 +1,6 @@
package com.netscape.cmstools.cert;
+import java.util.Arrays;
import java.util.Collection;
import org.apache.commons.cli.CommandLine;
@@ -19,14 +20,15 @@ public class CertRequestProfileFindCLI extends CLI {
public CertRequestProfileFindCLI(CertCLI certCLI) {
super("request-profile-find", "List Enrollment templates", certCLI);
this.certCLI = certCLI;
+
+ createOptions();
}
public void printHelp() {
- formatter.printHelp(getFullName() + " <Profile ID>", options);
+ formatter.printHelp(getFullName() + " <Profile ID> [OPTIONS...]", options);
}
- public void execute(String[] args) throws Exception {
-
+ public void createOptions() {
Option option = new Option(null, "start", true, "Page start");
option.setArgName("start");
options.addOption(option);
@@ -34,6 +36,15 @@ public class CertRequestProfileFindCLI extends CLI {
option = new Option(null, "size", true, "Page size");
option.setArgName("size");
options.addOption(option);
+ }
+
+ public void execute(String[] args) throws Exception {
+ // Always check for "--help" prior to parsing
+ if (Arrays.asList(args).contains("--help")) {
+ // Display usage
+ printHelp();
+ System.exit(0);
+ }
CommandLine cmd = null;
@@ -43,13 +54,15 @@ public class CertRequestProfileFindCLI extends CLI {
} catch (ParseException e) {
System.err.println("Error: " + e.getMessage());
printHelp();
- System.exit(1);
+ System.exit(-1);
}
- if (cmd.hasOption("help")) {
- // Display usage
+ String[] cmdArgs = cmd.getArgs();
+
+ if (cmdArgs.length != 1) {
+ System.err.println("Error: Missing Profile ID.");
printHelp();
- System.exit(0);
+ System.exit(-1);
}
String s = cmd.getOptionValue("start");
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileShowCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileShowCLI.java
index 396eca623..8b626703f 100644
--- a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileShowCLI.java
@@ -1,5 +1,7 @@
package com.netscape.cmstools.cert;
+import java.util.Arrays;
+
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.ParseException;
@@ -16,18 +18,29 @@ public class CertRequestProfileShowCLI extends CLI {
public CertRequestProfileShowCLI(CertCLI certCLI) {
super("request-profile-show", "Get Enrollment template", certCLI);
this.certCLI = certCLI;
+
+ createOptions();
}
public void printHelp() {
- formatter.printHelp(getFullName() + " <Profile ID>", options);
+ formatter.printHelp(getFullName() + " <Profile ID> [OPTIONS...]", options);
}
- public void execute(String[] args) throws Exception {
- CommandLine cmd = null;
-
+ public void createOptions() {
Option option = new Option(null, "output", true, "Output filename");
option.setArgName("filename");
options.addOption(option);
+ }
+
+ public void execute(String[] args) throws Exception {
+ // Always check for "--help" prior to parsing
+ if (Arrays.asList(args).contains("--help")) {
+ // Display usage
+ printHelp();
+ System.exit(0);
+ }
+
+ CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
@@ -37,20 +50,15 @@ public class CertRequestProfileShowCLI extends CLI {
System.exit(-1);
}
- if (cmd.hasOption("help")) {
- // Display usage
- printHelp();
- System.exit(0);
- }
+ String[] cmdArgs = cmd.getArgs();
- String[] cLineArgs = cmd.getArgs();
- if (cLineArgs.length < 1) {
- System.err.println("Error: Missing profile ID.");
+ if (cmdArgs.length < 1) {
+ System.err.println("Error: Missing Profile ID.");
printHelp();
System.exit(-1);
}
- String profileId = cLineArgs[0];
+ String profileId = cmdArgs[0];
String filename = null;
if (cmd.hasOption("output")) {
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestReviewCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestReviewCLI.java
index 672b7b50e..4a8221bcd 100644
--- a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestReviewCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestReviewCLI.java
@@ -32,6 +32,8 @@ public class CertRequestReviewCLI extends CLI {
public CertRequestReviewCLI(CertCLI certCLI) {
super("request-review", "Review certificate request", certCLI);
this.certCLI = certCLI;
+
+ createOptions();
}
@Override
@@ -39,10 +41,7 @@ public class CertRequestReviewCLI extends CLI {
formatter.printHelp(getFullName() + " <Request ID> [OPTIONS...]", options);
}
- @Override
- public void execute(String[] args) throws Exception {
- CommandLine cmd = null;
-
+ public void createOptions() {
Option option = new Option(null, "action", true, "Action: " + StringUtils.join(actions, ", "));
option.setArgName("action");
options.addOption(option);
@@ -50,6 +49,18 @@ public class CertRequestReviewCLI extends CLI {
option = new Option(null, "file", true, "File to store the certificate request");
option.setArgName("filename");
options.addOption(option);
+ }
+
+ @Override
+ public void execute(String[] args) throws Exception {
+ // Always check for "--help" prior to parsing
+ if (Arrays.asList(args).contains("--help")) {
+ // Display usage
+ printHelp();
+ System.exit(0);
+ }
+
+ CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
@@ -59,24 +70,19 @@ public class CertRequestReviewCLI extends CLI {
System.exit(-1);
}
- if (cmd.hasOption("help")) {
- // Display usage
- printHelp();
- System.exit(0);
- }
+ String[] cmdArgs = cmd.getArgs();
- String[] cLineArgs = cmd.getArgs();
- if (cLineArgs.length < 1) {
- System.err.println("Error: Missing certificate request ID.");
+ if (cmdArgs.length < 1) {
+ System.err.println("Error: Missing Certificate Request ID.");
printHelp();
System.exit(-1);
}
RequestId requestId = null;
try {
- requestId = new RequestId(cLineArgs[0]);
+ requestId = new RequestId(cmdArgs[0]);
} catch (NumberFormatException e) {
- System.err.println("Error: Invalid certificate request ID " + cLineArgs[0] + ".");
+ System.err.println("Error: Invalid certificate request ID " + cmdArgs[0] + ".");
System.exit(-1);
}
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestShowCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestShowCLI.java
index ca3ac44bc..aac18a679 100644
--- a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestShowCLI.java
@@ -1,5 +1,7 @@
package com.netscape.cmstools.cert;
+import java.util.Arrays;
+
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.ParseException;
@@ -13,19 +15,27 @@ public class CertRequestShowCLI extends CLI {
CertCLI certCLI;
public CertRequestShowCLI(CertCLI certCLI) {
+
super("request-show", "Show certificate request", certCLI);
this.certCLI = certCLI;
}
@Override
public void printHelp() {
- formatter.printHelp(getFullName() + " <Request ID>", options);
+ formatter.printHelp(getFullName() + " <Request ID> [OPTIONS...]", options);
}
@Override
public void execute(String[] args) throws Exception {
+ // Always check for "--help" prior to parsing
+ if (Arrays.asList(args).contains("--help")) {
+ // Display usage
+ printHelp();
+ System.exit(0);
+ }
CommandLine cmd = null;
+
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
@@ -34,24 +44,19 @@ public class CertRequestShowCLI extends CLI {
System.exit(-1);
}
- if (cmd.hasOption("help")) {
- // Display usage
- printHelp();
- System.exit(0);
- }
+ String[] cmdArgs = cmd.getArgs();
- String[] cLineArgs = cmd.getArgs();
- if (cLineArgs.length < 1) {
- System.err.println("Error: Missing certificate request ID.");
+ if (cmdArgs.length < 1) {
+ System.err.println("Error: Missing Certificate Request ID.");
printHelp();
System.exit(-1);
}
RequestId requestId = null;
try {
- requestId = new RequestId(cLineArgs[0]);
+ requestId = new RequestId(cmdArgs[0]);
} catch (NumberFormatException e) {
- System.err.println("Error: Invalid certificate request ID " + cLineArgs[0] + ".");
+ System.err.println("Error: Invalid certificate request ID " + cmdArgs[0] + ".");
System.exit(-1);
}
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestSubmitCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestSubmitCLI.java
index 481a643c4..fe2b806b0 100644
--- a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestSubmitCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestSubmitCLI.java
@@ -2,6 +2,7 @@ package com.netscape.cmstools.cert;
import java.io.File;
import java.io.FileNotFoundException;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Scanner;
@@ -26,11 +27,18 @@ public class CertRequestSubmitCLI extends CLI {
}
public void printHelp() {
- formatter.printHelp(getFullName() + " <filename>", options);
+ formatter.printHelp(getFullName() + " <filename> [OPTIONS...]", options);
}
@Override
public void execute(String[] args) {
+ // Always check for "--help" prior to parsing
+ if (Arrays.asList(args).contains("--help")) {
+ // Display usage
+ printHelp();
+ System.exit(0);
+ }
+
CommandLine cmd = null;
try {
@@ -41,22 +49,16 @@ public class CertRequestSubmitCLI extends CLI {
System.exit(-1);
}
- if (cmd.hasOption("help")) {
- // Display usage
- printHelp();
- System.exit(0);
- }
-
- String[] cLineArgs = cmd.getArgs();
+ String[] cmdArgs = cmd.getArgs();
- if (cLineArgs.length < 1) {
+ if (cmdArgs.length < 1) {
System.err.println("Error: No filename specified.");
printHelp();
System.exit(-1);
}
try {
- CertEnrollmentRequest erd = getEnrollmentRequest(cLineArgs[0]);
+ CertEnrollmentRequest erd = getEnrollmentRequest(cmdArgs[0]);
CertRequestInfos cri = certCLI.certClient.enrollRequest(erd);
MainCLI.printMessage("Submitted certificate request");
printRequestInformation(cri);
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertRevokeCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertRevokeCLI.java
index 87d5869c4..afb0e03fd 100644
--- a/base/java-tools/src/com/netscape/cmstools/cert/CertRevokeCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertRevokeCLI.java
@@ -20,6 +20,7 @@ package com.netscape.cmstools.cert;
import java.io.BufferedReader;
import java.io.InputStreamReader;
+import java.util.Arrays;
import netscape.security.x509.RevocationReason;
@@ -44,14 +45,15 @@ public class CertRevokeCLI extends CLI {
public CertRevokeCLI(CertCLI certCLI) {
super("revoke", "Revoke certificate", certCLI);
this.certCLI = certCLI;
+
+ createOptions();
}
public void printHelp() {
formatter.printHelp(getFullName() + " <Serial Number> [OPTIONS...]", options);
}
- public void execute(String[] args) throws Exception {
-
+ public void createOptions() {
StringBuilder sb = new StringBuilder();
for (RevocationReason reason : RevocationReason.INSTANCES) {
@@ -74,6 +76,15 @@ public class CertRevokeCLI extends CLI {
options.addOption(null, "ca", false, "CA signing certificate");
options.addOption(null, "force", false, "Force");
+ }
+
+ public void execute(String[] args) throws Exception {
+ // Always check for "--help" prior to parsing
+ if (Arrays.asList(args).contains("--help")) {
+ // Display usage
+ printHelp();
+ System.exit(0);
+ }
CommandLine cmd = null;
@@ -83,20 +94,15 @@ public class CertRevokeCLI extends CLI {
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
printHelp();
- System.exit(1);
- }
-
- if (cmd.hasOption("help")) {
- // Display usage
- printHelp();
- System.exit(0);
+ System.exit(-1);
}
String[] cmdArgs = cmd.getArgs();
if (cmdArgs.length != 1) {
+ System.err.println("Error: Missing Serial Number.");
printHelp();
- System.exit(1);
+ System.exit(-1);
}
CertId certID = new CertId(cmdArgs[0]);
@@ -107,7 +113,7 @@ public class CertRevokeCLI extends CLI {
if (reason == null) {
System.err.println("Error: Invalid revocation reason: "+string);
printHelp();
- System.exit(1);
+ System.exit(-1);
return;
}
@@ -132,7 +138,7 @@ public class CertRevokeCLI extends CLI {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line = reader.readLine();
if (!line.equalsIgnoreCase("Y")) {
- System.exit(1);
+ System.exit(-1);
}
}
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertShowCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertShowCLI.java
index d4867422a..febc4a494 100644
--- a/base/java-tools/src/com/netscape/cmstools/cert/CertShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertShowCLI.java
@@ -20,6 +20,7 @@ package com.netscape.cmstools.cert;
import java.io.FileWriter;
import java.io.PrintWriter;
+import java.util.Arrays;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
@@ -39,20 +40,30 @@ public class CertShowCLI extends CLI {
public CertShowCLI(CertCLI certCLI) {
super("show", "Show certificate", certCLI);
this.certCLI = certCLI;
+
+ createOptions();
}
public void printHelp() {
formatter.printHelp(getFullName() + " <Serial Number> [OPTIONS...]", options);
}
- public void execute(String[] args) throws Exception {
-
+ public void createOptions() {
Option option = new Option(null, "output", true, "Output file");
option.setArgName("file");
options.addOption(option);
options.addOption(null, "pretty", false, "Pretty print");
options.addOption(null, "encoded", false, "Base-64 encoded");
+ }
+
+ public void execute(String[] args) throws Exception {
+ // Always check for "--help" prior to parsing
+ if (Arrays.asList(args).contains("--help")) {
+ // Display usage
+ printHelp();
+ System.exit(0);
+ }
CommandLine cmd = null;
@@ -62,25 +73,20 @@ public class CertShowCLI extends CLI {
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
printHelp();
- System.exit(1);
+ System.exit(-1);
}
- if (cmd.hasOption("help")) {
- // Display usage
- printHelp();
- System.exit(0);
- }
-
- boolean showPrettyPrint = cmd.hasOption("pretty");
- boolean showEncoded = cmd.hasOption("encoded");
-
String[] cmdArgs = cmd.getArgs();
if (cmdArgs.length != 1) {
+ System.err.println("Error: Missing Serial Number.");
printHelp();
- System.exit(1);
+ System.exit(-1);
}
+ boolean showPrettyPrint = cmd.hasOption("pretty");
+ boolean showEncoded = cmd.hasOption("encoded");
+
CertId certID = new CertId(cmdArgs[0]);
String file = cmd.getOptionValue("output");