diff options
author | Endi Sukma Dewata <edewata@redhat.com> | 2013-02-06 20:04:06 -0500 |
---|---|---|
committer | Endi Sukma Dewata <edewata@redhat.com> | 2013-02-06 20:08:08 -0500 |
commit | b4530fdf0b7355a97c2131614810648276233a78 (patch) | |
tree | 171fda6bd03f969c32e363e80172f9f8135b482e /base/java-tools/src | |
parent | 7de94ec405d633bc6bf9343ac18d86aba5da9ebe (diff) | |
download | pki-ticket-503.tar.gz pki-ticket-503.tar.xz pki-ticket-503.zip |
Fixed validity duration options for cert-find.ticket-503
The cert-find command has been fixed to show better error messages
on missing validity duration options. The validity duration unit
has been changed to take "day", "week", "month", or "year" and
convert it into milliseconds.
Ticket #291, #500
Diffstat (limited to 'base/java-tools/src')
-rw-r--r-- | base/java-tools/src/com/netscape/cmstools/cert/CertFindCLI.java | 52 |
1 files changed, 46 insertions, 6 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 9107a574b..e4f741bcf 100644 --- a/base/java-tools/src/com/netscape/cmstools/cert/CertFindCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cert/CertFindCLI.java @@ -263,17 +263,36 @@ public class CertFindCLI extends CLI { options.addOption(option); //validityLengthinUse - option = new Option(null, "validityOperation", true, "Validity operation: \"<=\" or \">=\""); + option = new Option(null, "validityOperation", true, "Validity duration operation: \"<=\" or \">=\""); option.setArgName("operation"); options.addOption(option); - option = new Option(null, "validityCount", true, "Validity count"); + option = new Option(null, "validityCount", true, "Validity duration count"); option.setArgName("count"); options.addOption(option); - option = new Option(null, "validityUnit", true, "Validity unit"); - option.setArgName("milliseconds"); + option = new Option(null, "validityUnit", true, "Validity duration unit: day, week, month (default), year"); + option.setArgName("day|week|month|year"); options.addOption(option); } + public Long convertValidityDurationUnit(String unit) { + + if (unit.equalsIgnoreCase("day")) { + return 86400000l; + + } else if (unit.equalsIgnoreCase("week")) { + return 604800000l; + + } else if (unit.equalsIgnoreCase("month")) { + return 2592000000l; + + } else if (unit.equalsIgnoreCase("year")) { + return 31536000000l; + + } else { + throw new Error("Invalid validity duration unit: "+unit); + } + } + public void addSearchAttribute(CommandLine cmd, CertSearchRequest csd) throws java.text.ParseException { @@ -392,18 +411,39 @@ public class CertFindCLI extends CLI { Date date = CertCLI.dateFormat.parse(cmd.getOptionValue("validNotAfterTo")); csd.setValidNotAfterTo(""+date.getTime()); } + if (cmd.hasOption("validityOperation")) { csd.setValidityLengthInUse(true); csd.setValidityOperation(cmd.getOptionValue("validityOperation")); } + if (cmd.hasOption("validityCount")) { csd.setValidityLengthInUse(true); - csd.setValidityCount(cmd.getOptionValue("validityCount")); + String count = cmd.getOptionValue("validityCount"); + csd.setValidityCount(Integer.parseInt(count)); } + if (cmd.hasOption("validityUnit")) { csd.setValidityLengthInUse(true); - csd.setValidityUnit(cmd.getOptionValue("validityUnit")); + String unit = cmd.getOptionValue("validityUnit"); + Long value = convertValidityDurationUnit(unit); + csd.setValidityUnit(value); } + if (csd.getValidityLengthInUse()) { + + if (csd.getValidityOperation() == null) { + throw new Error("Mising validity duration operation"); + } + + if (csd.getValidityCount() == null) { + throw new Error("Mising validity duration count"); + } + + if (csd.getValidityUnit() == null) { + Long value = convertValidityDurationUnit("month"); + csd.setValidityUnit(value); + } + } } } |