HADOOP-10586. KeyShell doesn't allow setting Options via CLI. (clamb via tucu)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1595105 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8f48760663
commit
51b37969df
@ -328,6 +328,8 @@ Trunk (Unreleased)
|
||||
|
||||
HADOOP-10583. bin/hadoop key throws NPE with no args and assorted other fixups. (clamb via tucu)
|
||||
|
||||
HADOOP-10586. KeyShell doesn't allow setting Options via CLI. (clamb via tucu)
|
||||
|
||||
OPTIMIZATIONS
|
||||
|
||||
HADOOP-7761. Improve the performance of raw comparisons. (todd)
|
||||
|
@ -89,6 +89,8 @@ public int run(String[] args) throws Exception {
|
||||
* @throws IOException
|
||||
*/
|
||||
private int init(String[] args) throws IOException {
|
||||
final Options options = KeyProvider.options(getConf());
|
||||
|
||||
for (int i = 0; i < args.length; i++) { // parse command line
|
||||
boolean moreTokens = (i < args.length - 1);
|
||||
if (args[i].equals("create")) {
|
||||
@ -97,7 +99,7 @@ private int init(String[] args) throws IOException {
|
||||
keyName = args[++i];
|
||||
}
|
||||
|
||||
command = new CreateCommand(keyName);
|
||||
command = new CreateCommand(keyName, options);
|
||||
if ("--help".equals(keyName)) {
|
||||
printKeyShellUsage();
|
||||
return -1;
|
||||
@ -127,9 +129,11 @@ private int init(String[] args) throws IOException {
|
||||
} else if ("list".equals(args[i])) {
|
||||
command = new ListCommand();
|
||||
} else if ("--size".equals(args[i]) && moreTokens) {
|
||||
getConf().set(KeyProvider.DEFAULT_BITLENGTH_NAME, args[++i]);
|
||||
options.setBitLength(Integer.parseInt(args[++i]));
|
||||
} else if ("--cipher".equals(args[i]) && moreTokens) {
|
||||
getConf().set(KeyProvider.DEFAULT_CIPHER_NAME, args[++i]);
|
||||
options.setCipher(args[++i]);
|
||||
} else if ("--description".equals(args[i]) && moreTokens) {
|
||||
options.setDescription(args[++i]);
|
||||
} else if ("--provider".equals(args[i]) && moreTokens) {
|
||||
userSuppliedProvider = true;
|
||||
getConf().set(KeyProviderFactory.KEY_PROVIDER_PATH, args[++i]);
|
||||
@ -399,6 +403,7 @@ public String getUsage() {
|
||||
private class CreateCommand extends Command {
|
||||
public static final String USAGE =
|
||||
"create <keyname> [--cipher <cipher>] [--size <size>]\n" +
|
||||
" [--description <description>]\n" +
|
||||
" [--provider <provider>] [--help]";
|
||||
public static final String DESC =
|
||||
"The create subcommand creates a new key for the name specified\n" +
|
||||
@ -408,10 +413,12 @@ private class CreateCommand extends Command {
|
||||
"The default keysize is 256. You may specify the requested key\n" +
|
||||
"length using the --size argument.\n";
|
||||
|
||||
String keyName = null;
|
||||
final String keyName;
|
||||
final Options options;
|
||||
|
||||
public CreateCommand(String keyName) {
|
||||
public CreateCommand(String keyName, Options options) {
|
||||
this.keyName = keyName;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
public boolean validate() {
|
||||
@ -434,7 +441,6 @@ public boolean validate() {
|
||||
public void execute() throws IOException, NoSuchAlgorithmException {
|
||||
warnIfTransientProvider();
|
||||
try {
|
||||
Options options = KeyProvider.options(getConf());
|
||||
provider.createKey(keyName, options);
|
||||
out.println(keyName + " has been successfully created.");
|
||||
provider.flush();
|
||||
|
@ -111,6 +111,30 @@ public void testKeySuccessfulKeyLifecycle() throws Exception {
|
||||
assertFalse(outContent.toString(), outContent.toString().contains("key1"));
|
||||
}
|
||||
|
||||
/* HADOOP-10586 KeyShell didn't allow -description. */
|
||||
@Test
|
||||
public void testKeySuccessfulCreationWithDescription() throws Exception {
|
||||
outContent.reset();
|
||||
String[] args1 = {"create", "key1", "--provider",
|
||||
"jceks://file" + tmpDir + "/keystore.jceks",
|
||||
"--description", "someDescription"};
|
||||
int rc = 0;
|
||||
KeyShell ks = new KeyShell();
|
||||
ks.setConf(new Configuration());
|
||||
rc = ks.run(args1);
|
||||
assertEquals(0, rc);
|
||||
assertTrue(outContent.toString().contains("key1 has been successfully " +
|
||||
"created."));
|
||||
|
||||
outContent.reset();
|
||||
String[] args2a = {"list", "--metadata", "--provider",
|
||||
"jceks://file" + tmpDir + "/keystore.jceks"};
|
||||
rc = ks.run(args2a);
|
||||
assertEquals(0, rc);
|
||||
assertTrue(outContent.toString().contains("description"));
|
||||
assertTrue(outContent.toString().contains("someDescription"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidKeySize() throws Exception {
|
||||
String[] args1 = {"create", "key1", "--size", "56", "--provider",
|
||||
|
Loading…
Reference in New Issue
Block a user