Skip to content

Commit

Permalink
HADOOP-11455. KMS and Credential CLI should request confirmation for …
Browse files Browse the repository at this point in the history
…deletion by default. (Charles Lamb via yliu)
  • Loading branch information
y-liu committed Jan 4, 2015
1 parent ddc5be4 commit 21c6f01
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
3 changes: 3 additions & 0 deletions hadoop-common-project/hadoop-common/CHANGES.txt
Expand Up @@ -452,6 +452,9 @@ Release 2.7.0 - UNRELEASED
HADOOP-11399. Java Configuration file and .xml files should be
automatically cross-compared (rchiang via rkanter)

HADOOP-11455. KMS and Credential CLI should request confirmation for
deletion by default. (Charles Lamb via yliu)

OPTIMIZATIONS

HADOOP-11323. WritableComparator#compare keeps reference to byte array.
Expand Down
Expand Up @@ -47,7 +47,7 @@ public class KeyShell extends Configured implements Tool {
" [" + ListCommand.USAGE + "]\n";
private static final String LIST_METADATA = "keyShell.list.metadata";

private boolean interactive = false;
private boolean interactive = true;
private Command command = null;

/** allows stdout to be captured if necessary */
Expand Down Expand Up @@ -169,8 +169,8 @@ private int init(String[] args) throws IOException {
getConf().set(KeyProviderFactory.KEY_PROVIDER_PATH, args[++i]);
} else if ("-metadata".equals(args[i])) {
getConf().setBoolean(LIST_METADATA, true);
} else if ("-i".equals(args[i]) || ("-interactive".equals(args[i]))) {
interactive = true;
} else if ("-f".equals(args[i]) || ("-force".equals(args[i]))) {
interactive = false;
} else if ("-help".equals(args[i])) {
printKeyShellUsage();
return 1;
Expand Down Expand Up @@ -367,11 +367,13 @@ public String getUsage() {
}

private class DeleteCommand extends Command {
public static final String USAGE = "delete <keyname> [-provider <provider>] [-help]";
public static final String USAGE =
"delete <keyname> [-provider <provider>] [-f] [-help]";
public static final String DESC =
"The delete subcommand deletes all versions of the key\n" +
"specified by the <keyname> argument from within the\n" +
"provider specified -provider.";
"provider specified -provider. The command asks for\n" +
"user confirmation unless -f is specified.";

String keyName = null;
boolean cont = true;
Expand All @@ -397,10 +399,10 @@ public boolean validate() {
try {
cont = ToolRunner
.confirmPrompt("You are about to DELETE all versions of "
+ " key: " + keyName + " from KeyProvider "
+ provider + ". Continue?:");
+ " key " + keyName + " from KeyProvider "
+ provider + ". Continue? ");
if (!cont) {
out.println("Nothing has been be deleted.");
out.println(keyName + " has not been deleted.");
}
return cont;
} catch (IOException e) {
Expand Down
Expand Up @@ -44,7 +44,7 @@ public class CredentialShell extends Configured implements Tool {
" [" + DeleteCommand.USAGE + "]\n" +
" [" + ListCommand.USAGE + "]\n";

private boolean interactive = false;
private boolean interactive = true;
private Command command = null;

/** allows stdout to be captured if necessary */
Expand Down Expand Up @@ -116,8 +116,8 @@ protected int init(String[] args) throws IOException {
userSuppliedProvider = true;
getConf().set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH,
args[++i]);
} else if (args[i].equals("-i") || (args[i].equals("-interactive"))) {
interactive = true;
} else if (args[i].equals("-f") || (args[i].equals("-force"))) {
interactive = false;
} else if (args[i].equals("-v") || (args[i].equals("-value"))) {
value = args[++i];
} else if (args[i].equals("-help")) {
Expand Down Expand Up @@ -236,11 +236,13 @@ public String getUsage() {
}

private class DeleteCommand extends Command {
public static final String USAGE = "delete <alias> [-provider] [-help]";
public static final String USAGE =
"delete <alias> [-provider] [-f] [-help]";
public static final String DESC =
"The delete subcommand deletes the credenital\n" +
"The delete subcommand deletes the credential\n" +
"specified as the <alias> argument from within the provider\n" +
"indicated through the -provider argument";
"indicated through the -provider argument. The command asks for\n" +
"confirmation unless the -f option is specified.";

String alias = null;
boolean cont = true;
Expand All @@ -267,9 +269,9 @@ public boolean validate() {
if (interactive) {
try {
cont = ToolRunner
.confirmPrompt("You are about to DELETE the credential: " +
.confirmPrompt("You are about to DELETE the credential " +
alias + " from CredentialProvider " + provider.toString() +
". Continue?:");
". Continue? ");
if (!cont) {
out.println("Nothing has been deleted.");
}
Expand All @@ -293,7 +295,7 @@ public void execute() throws IOException {
provider.flush();
printProviderWritten();
} catch (IOException e) {
out.println(alias + "has NOT been deleted.");
out.println(alias + " has NOT been deleted.");
throw e;
}
}
Expand Down
Expand Up @@ -75,7 +75,8 @@ public void cleanUp() throws Exception {
private void deleteKey(KeyShell ks, String keyName) throws Exception {
int rc;
outContent.reset();
final String[] delArgs = {"delete", keyName, "-provider", jceksProvider};
final String[] delArgs =
{"delete", keyName, "-f", "-provider", jceksProvider};
rc = ks.run(delArgs);
assertEquals(0, rc);
assertTrue(outContent.toString().contains(keyName + " has been " +
Expand Down
Expand Up @@ -47,6 +47,7 @@ public void setup() throws Exception {
System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
final Path jksPath = new Path(tmpDir.toString(), "keystore.jceks");
new File(jksPath.toString()).delete();
jceksProvider = "jceks://file" + jksPath.toUri();
}

Expand All @@ -71,7 +72,7 @@ public void testCredentialSuccessfulLifecycle() throws Exception {
assertTrue(outContent.toString().contains("credential1"));

outContent.reset();
String[] args4 = {"delete", "credential1", "-provider",
String[] args4 = {"delete", "credential1", "-f", "-provider",
jceksProvider};
rc = cs.run(args4);
assertEquals(0, rc);
Expand Down Expand Up @@ -113,7 +114,7 @@ public void testTransientProviderWarning() throws Exception {
assertTrue(outContent.toString().contains("WARNING: you are modifying a " +
"transient provider."));

String[] args2 = {"delete", "credential1", "-provider", "user:///"};
String[] args2 = {"delete", "credential1", "-f", "-provider", "user:///"};
rc = cs.run(args2);
assertEquals(outContent.toString(), 0, rc);
assertTrue(outContent.toString().contains("credential1 has been successfully " +
Expand Down Expand Up @@ -167,7 +168,7 @@ public void testPromptForCredential() throws Exception {
assertTrue(outContent.toString().contains("credential1 has been successfully " +
"created."));

String[] args2 = {"delete", "credential1", "-provider",
String[] args2 = {"delete", "credential1", "-f", "-provider",
jceksProvider};
rc = shell.run(args2);
assertEquals(0, rc);
Expand Down

0 comments on commit 21c6f01

Please sign in to comment.