[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Pki-devel] [PATCH] 595 Added key-show option.



The key-show CLI has been modified to provide an option to find
the active key info using the client key ID.

--
Endi S. Dewata
From c0f1c6c384169985f958bc4b3fd513388c021663 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata redhat com>
Date: Wed, 13 May 2015 00:27:27 -0400
Subject: [PATCH] Added key-show option.

The key-show CLI has been modified to provide an option to find
the active key info using the client key ID.
---
 .../src/com/netscape/cmstools/key/KeyCLI.java      | 15 +++++++-----
 .../src/com/netscape/cmstools/key/KeyShowCLI.java  | 28 ++++++++++++++++------
 2 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/base/java-tools/src/com/netscape/cmstools/key/KeyCLI.java b/base/java-tools/src/com/netscape/cmstools/key/KeyCLI.java
index e9790b985bbbfa3fe9223926b019f63ae32efe7d..fb324be25bb1680ebe987cefbcaa41f2ae54182e 100644
--- a/base/java-tools/src/com/netscape/cmstools/key/KeyCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/key/KeyCLI.java
@@ -39,18 +39,21 @@ public class KeyCLI extends CLI {
     public KeyCLI(CLI parent) {
         super("key", "Key management commands", parent);
 
-        addModule(new KeyFindCLI(this));
+        addModule(new KeyTemplateFindCLI(this));
+        addModule(new KeyTemplateShowCLI(this));
+
         addModule(new KeyRequestFindCLI(this));
-        addModule(new KeyShowCLI(this));
         addModule(new KeyRequestShowCLI(this));
+        addModule(new KeyRequestReviewCLI(this));
+
+        addModule(new KeyFindCLI(this));
+        addModule(new KeyShowCLI(this));
         addModule(new KeyModifyCLI(this));
-        addModule(new KeyTemplateFindCLI(this));
-        addModule(new KeyTemplateShowCLI(this));
+
+        addModule(new KeyGenerateCLI(this));
         addModule(new KeyArchiveCLI(this));
         addModule(new KeyRetrieveCLI(this));
-        addModule(new KeyGenerateCLI(this));
         addModule(new KeyRecoverCLI(this));
-        addModule(new KeyRequestReviewCLI(this));
     }
 
     public String getFullName() {
diff --git a/base/java-tools/src/com/netscape/cmstools/key/KeyShowCLI.java b/base/java-tools/src/com/netscape/cmstools/key/KeyShowCLI.java
index 4e1c50d1e18558147ef3a95ff7c1340fd9c7a1ee..ebc5741b6c8fa1ee0e72929f973ad5251b0fff64 100644
--- a/base/java-tools/src/com/netscape/cmstools/key/KeyShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/key/KeyShowCLI.java
@@ -21,6 +21,7 @@ package com.netscape.cmstools.key;
 import java.util.Arrays;
 
 import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
 import org.apache.commons.cli.ParseException;
 
 import com.netscape.certsrv.dbs.keydb.KeyId;
@@ -34,12 +35,20 @@ public class KeyShowCLI extends CLI {
     public KeyShowCLI(KeyCLI keyCLI) {
         super("show", "Get key", keyCLI);
         this.keyCLI = keyCLI;
+
+        createOptions();
     }
 
     public void printHelp() {
         formatter.printHelp(getFullName() + " <Key ID> [OPTIONS...]", options);
     }
 
+    public void createOptions() {
+        Option option = new Option(null, "clientKeyID", true, "Unique client key identifier.");
+        option.setArgName("Client Key Identifier");
+        options.addOption(option);
+    }
+
     public void execute(String[] args) {
         // Always check for "--help" prior to parsing
         if (Arrays.asList(args).contains("--help")) {
@@ -60,18 +69,23 @@ public class KeyShowCLI extends CLI {
         }
 
         String[] cmdArgs = cmd.getArgs();
+        String clientKeyId = cmd.getOptionValue("clientKeyID");
+        KeyInfo keyInfo;
 
-        if (cmdArgs.length != 1) {
-            System.err.println("Error: No Key ID specified.");
+        if (cmdArgs.length == 1) {
+            KeyId keyId = new KeyId(cmdArgs[0]);
+            keyInfo = keyCLI.keyClient.getKeyInfo(keyId);
+
+        } else if (clientKeyId != null) {
+            keyInfo = keyCLI.keyClient.getActiveKeyInfo(clientKeyId);
+
+        } else {
+            System.err.println("Error: Missing Key ID or Client Key ID.");
             printHelp();
             System.exit(-1);
+            return;
         }
 
-        KeyId keyId = new KeyId(args[0].trim());
-
-        KeyInfo keyInfo = keyCLI.keyClient.getKeyInfo(keyId);
-
         KeyCLI.printKeyInfo(keyInfo);
     }
-
 }
-- 
1.9.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]