James Moger
2014-03-27 8d96b960e472433d2b4a5b71df7000bf1fbde648
src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java
@@ -48,6 +48,7 @@
      register(user, AddKey.class);
      register(user, RemoveKey.class);
      register(user, ListKeys.class);
      register(user, WhichKey.class);
   }
   @CommandMetaData(name = "add", description = "Add an SSH public key to your account")
@@ -177,4 +178,33 @@
         stdout.println(FlipTable.of(headers, data, Borders.BODY_HCOLS));
      }
   }
   @CommandMetaData(name = "which", description = "Display the SSH public key used for this session")
   public static class WhichKey extends SshCommand {
      @Option(name = "-L", usage = "list complete public key parameters")
      private boolean showRaw;
      @Override
      public void run() throws UnloggedFailure {
         SshKey key = getContext().getClient().getKey();
         if (key == null) {
            throw new UnloggedFailure(1,  "You have not authenticated with an SSH public key.");
         }
         if (showRaw) {
            stdout.println(key.getRawData());
         } else {
            asTable(key);
         }
      }
      protected void asTable(SshKey key) {
         String[] headers = { "Fingerprint", "Comment", "Type" };
         Object[][] data = new Object[1][];
         data[0] = new Object[] { key.getFingerprint(), key.getComment(), key.getAlgorithm() };
         stdout.println(FlipTable.of(headers, data, Borders.BODY_HCOLS));
      }
   }
}