HADOOP-10927. Fix CredentialShell help behavior and error codes. Contributed by Josh Elser.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1615827 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d7b5709bcb
commit
c8abf5f20a
@ -519,6 +519,9 @@ Release 2.6.0 - UNRELEASED
|
||||
HADOOP-10928. Incorrect usage on `hadoop credential list`.
|
||||
(Josh Elser via wang)
|
||||
|
||||
HADOOP-10927. Fix CredentialShell help behavior and error codes.
|
||||
(Josh Elser via wang)
|
||||
|
||||
Release 2.5.0 - UNRELEASED
|
||||
|
||||
INCOMPATIBLE CHANGES
|
||||
|
@ -35,6 +35,7 @@ function print_usage(){
|
||||
echo " distcp <srcurl> <desturl> copy file or directories recursively"
|
||||
echo " archive -archiveName NAME -p <parent path> <src>* <dest> create a hadoop archive"
|
||||
echo " classpath prints the class path needed to get the"
|
||||
echo " credential interact with credential providers"
|
||||
echo " Hadoop jar and the required libraries"
|
||||
echo " daemonlog get/set the log level for each daemon"
|
||||
echo " or"
|
||||
|
@ -67,11 +67,11 @@ public int run(String[] args) throws Exception {
|
||||
if (command.validate()) {
|
||||
command.execute();
|
||||
} else {
|
||||
exitCode = -1;
|
||||
exitCode = 1;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(err);
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
return exitCode;
|
||||
}
|
||||
@ -79,29 +79,36 @@ public int run(String[] args) throws Exception {
|
||||
/**
|
||||
* Parse the command line arguments and initialize the data
|
||||
* <pre>
|
||||
* % hadoop alias create alias [-provider providerPath]
|
||||
* % hadoop alias list [-provider providerPath]
|
||||
* % hadoop alias delete alias [-provider providerPath] [-i]
|
||||
* % hadoop credential create alias [-provider providerPath]
|
||||
* % hadoop credential list [-provider providerPath]
|
||||
* % hadoop credential delete alias [-provider providerPath] [-i]
|
||||
* </pre>
|
||||
* @param args
|
||||
* @return
|
||||
* @return 0 if the argument(s) were recognized, 1 otherwise
|
||||
* @throws IOException
|
||||
*/
|
||||
private int init(String[] args) throws IOException {
|
||||
protected int init(String[] args) throws IOException {
|
||||
// no args should print the help message
|
||||
if (0 == args.length) {
|
||||
printCredShellUsage();
|
||||
ToolRunner.printGenericCommandUsage(System.err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < args.length; i++) { // parse command line
|
||||
if (args[i].equals("create")) {
|
||||
String alias = args[++i];
|
||||
command = new CreateCommand(alias);
|
||||
if (alias.equals("-help")) {
|
||||
printCredShellUsage();
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
} else if (args[i].equals("delete")) {
|
||||
String alias = args[++i];
|
||||
command = new DeleteCommand(alias);
|
||||
if (alias.equals("-help")) {
|
||||
printCredShellUsage();
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
} else if (args[i].equals("list")) {
|
||||
command = new ListCommand();
|
||||
@ -115,11 +122,11 @@ private int init(String[] args) throws IOException {
|
||||
value = args[++i];
|
||||
} else if (args[i].equals("-help")) {
|
||||
printCredShellUsage();
|
||||
return -1;
|
||||
return 0;
|
||||
} else {
|
||||
printCredShellUsage();
|
||||
ToolRunner.printGenericCommandUsage(System.err);
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -17,16 +17,18 @@
|
||||
*/
|
||||
package org.apache.hadoop.security.alias;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.security.alias.CredentialShell.PasswordReader;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -87,7 +89,7 @@ public void testInvalidProvider() throws Exception {
|
||||
CredentialShell cs = new CredentialShell();
|
||||
cs.setConf(new Configuration());
|
||||
rc = cs.run(args1);
|
||||
assertEquals(-1, rc);
|
||||
assertEquals(1, rc);
|
||||
assertTrue(outContent.toString().contains("There are no valid " +
|
||||
"CredentialProviders configured."));
|
||||
}
|
||||
@ -122,7 +124,7 @@ public void testTransientProviderOnlyConfig() throws Exception {
|
||||
config.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, "user:///");
|
||||
cs.setConf(config);
|
||||
rc = cs.run(args1);
|
||||
assertEquals(-1, rc);
|
||||
assertEquals(1, rc);
|
||||
assertTrue(outContent.toString().contains("There are no valid " +
|
||||
"CredentialProviders configured."));
|
||||
}
|
||||
@ -139,7 +141,7 @@ public void testPromptForCredentialWithEmptyPasswd() throws Exception {
|
||||
shell.setConf(new Configuration());
|
||||
shell.setPasswordReader(new MockPasswordReader(passwords));
|
||||
rc = shell.run(args1);
|
||||
assertEquals(outContent.toString(), -1, rc);
|
||||
assertEquals(outContent.toString(), 1, rc);
|
||||
assertTrue(outContent.toString().contains("Passwords don't match"));
|
||||
}
|
||||
|
||||
@ -186,4 +188,21 @@ public void format(String message) {
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyArgList() throws Exception {
|
||||
CredentialShell shell = new CredentialShell();
|
||||
shell.setConf(new Configuration());
|
||||
assertEquals(1, shell.init(new String[0]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandHelpExitsNormally() throws Exception {
|
||||
for (String cmd : Arrays.asList("create", "list", "delete")) {
|
||||
CredentialShell shell = new CredentialShell();
|
||||
shell.setConf(new Configuration());
|
||||
assertEquals("Expected help argument on " + cmd + " to return 0",
|
||||
0, shell.init(new String[] {cmd, "-help"}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user