Rename UserError
The top-level class Throwable represents all errors and exceptions in Java. This hierarchy is divided into Error and Exception, the former being serious problems that applications should not try to catch and the latter representing exceptional conditions that an application might want to catch and handle. This commit renames org.elasticsearch.cli.UserError to org.elasticsearch.UserException to make its name consistent with where it falls in this hierarchy. Relates elastic/elasticsearch#2701 Original commit: elastic/x-pack-elasticsearch@589e159ec0
This commit is contained in:
parent
8cc49b5b30
commit
f1670a3845
|
@ -10,7 +10,7 @@ import joptsimple.OptionSpec;
|
||||||
import org.elasticsearch.cli.Command;
|
import org.elasticsearch.cli.Command;
|
||||||
import org.elasticsearch.cli.ExitCodes;
|
import org.elasticsearch.cli.ExitCodes;
|
||||||
import org.elasticsearch.cli.Terminal;
|
import org.elasticsearch.cli.Terminal;
|
||||||
import org.elasticsearch.cli.UserError;
|
import org.elasticsearch.cli.UserException;
|
||||||
import org.elasticsearch.common.SuppressForbidden;
|
import org.elasticsearch.common.SuppressForbidden;
|
||||||
import org.elasticsearch.common.io.PathUtils;
|
import org.elasticsearch.common.io.PathUtils;
|
||||||
|
|
||||||
|
@ -54,9 +54,9 @@ public class KeyPairGeneratorTool extends Command {
|
||||||
Path publicKeyPath = parsePath(publicKeyPathOption.value(options));
|
Path publicKeyPath = parsePath(publicKeyPathOption.value(options));
|
||||||
Path privateKeyPath = parsePath(privateKeyPathOption.value(options));
|
Path privateKeyPath = parsePath(privateKeyPathOption.value(options));
|
||||||
if (Files.exists(privateKeyPath)) {
|
if (Files.exists(privateKeyPath)) {
|
||||||
throw new UserError(ExitCodes.USAGE, privateKeyPath + " already exists");
|
throw new UserException(ExitCodes.USAGE, privateKeyPath + " already exists");
|
||||||
} else if (Files.exists(publicKeyPath)) {
|
} else if (Files.exists(publicKeyPath)) {
|
||||||
throw new UserError(ExitCodes.USAGE, publicKeyPath + " already exists");
|
throw new UserException(ExitCodes.USAGE, publicKeyPath + " already exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
SecureRandom random = new SecureRandom();
|
SecureRandom random = new SecureRandom();
|
||||||
|
|
|
@ -12,7 +12,7 @@ import joptsimple.OptionSet;
|
||||||
import joptsimple.OptionSpec;
|
import joptsimple.OptionSpec;
|
||||||
import org.elasticsearch.cli.Command;
|
import org.elasticsearch.cli.Command;
|
||||||
import org.elasticsearch.cli.ExitCodes;
|
import org.elasticsearch.cli.ExitCodes;
|
||||||
import org.elasticsearch.cli.UserError;
|
import org.elasticsearch.cli.UserException;
|
||||||
import org.elasticsearch.cli.Terminal;
|
import org.elasticsearch.cli.Terminal;
|
||||||
import org.elasticsearch.common.SuppressForbidden;
|
import org.elasticsearch.common.SuppressForbidden;
|
||||||
import org.elasticsearch.common.io.PathUtils;
|
import org.elasticsearch.common.io.PathUtils;
|
||||||
|
@ -62,9 +62,9 @@ public class LicenseGeneratorTool extends Command {
|
||||||
Path publicKeyPath = parsePath(publicKeyPathOption.value(options));
|
Path publicKeyPath = parsePath(publicKeyPathOption.value(options));
|
||||||
Path privateKeyPath = parsePath(privateKeyPathOption.value(options));
|
Path privateKeyPath = parsePath(privateKeyPathOption.value(options));
|
||||||
if (Files.exists(privateKeyPath) == false) {
|
if (Files.exists(privateKeyPath) == false) {
|
||||||
throw new UserError(ExitCodes.USAGE, privateKeyPath + " does not exist");
|
throw new UserException(ExitCodes.USAGE, privateKeyPath + " does not exist");
|
||||||
} else if (Files.exists(publicKeyPath) == false) {
|
} else if (Files.exists(publicKeyPath) == false) {
|
||||||
throw new UserError(ExitCodes.USAGE, publicKeyPath + " does not exist");
|
throw new UserException(ExitCodes.USAGE, publicKeyPath + " does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
final License licenseSpec;
|
final License licenseSpec;
|
||||||
|
@ -73,11 +73,11 @@ public class LicenseGeneratorTool extends Command {
|
||||||
} else if (options.has(licenseFileOption)) {
|
} else if (options.has(licenseFileOption)) {
|
||||||
Path licenseSpecPath = parsePath(licenseFileOption.value(options));
|
Path licenseSpecPath = parsePath(licenseFileOption.value(options));
|
||||||
if (Files.exists(licenseSpecPath) == false) {
|
if (Files.exists(licenseSpecPath) == false) {
|
||||||
throw new UserError(ExitCodes.USAGE, licenseSpecPath + " does not exist");
|
throw new UserException(ExitCodes.USAGE, licenseSpecPath + " does not exist");
|
||||||
}
|
}
|
||||||
licenseSpec = License.fromSource(Files.readAllBytes(licenseSpecPath));
|
licenseSpec = License.fromSource(Files.readAllBytes(licenseSpecPath));
|
||||||
} else {
|
} else {
|
||||||
throw new UserError(ExitCodes.USAGE, "Must specify either --license or --licenseFile");
|
throw new UserException(ExitCodes.USAGE, "Must specify either --license or --licenseFile");
|
||||||
}
|
}
|
||||||
|
|
||||||
// sign
|
// sign
|
||||||
|
|
|
@ -12,7 +12,7 @@ import joptsimple.OptionSet;
|
||||||
import joptsimple.OptionSpec;
|
import joptsimple.OptionSpec;
|
||||||
import org.elasticsearch.cli.Command;
|
import org.elasticsearch.cli.Command;
|
||||||
import org.elasticsearch.cli.ExitCodes;
|
import org.elasticsearch.cli.ExitCodes;
|
||||||
import org.elasticsearch.cli.UserError;
|
import org.elasticsearch.cli.UserException;
|
||||||
import org.elasticsearch.cli.Terminal;
|
import org.elasticsearch.cli.Terminal;
|
||||||
import org.elasticsearch.common.SuppressForbidden;
|
import org.elasticsearch.common.SuppressForbidden;
|
||||||
import org.elasticsearch.common.io.PathUtils;
|
import org.elasticsearch.common.io.PathUtils;
|
||||||
|
@ -49,7 +49,7 @@ public class LicenseVerificationTool extends Command {
|
||||||
protected void execute(Terminal terminal, OptionSet options) throws Exception {
|
protected void execute(Terminal terminal, OptionSet options) throws Exception {
|
||||||
Path publicKeyPath = parsePath(publicKeyPathOption.value(options));
|
Path publicKeyPath = parsePath(publicKeyPathOption.value(options));
|
||||||
if (Files.exists(publicKeyPath) == false) {
|
if (Files.exists(publicKeyPath) == false) {
|
||||||
throw new UserError(ExitCodes.USAGE, publicKeyPath + " does not exist");
|
throw new UserException(ExitCodes.USAGE, publicKeyPath + " does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
final License licenseSpec;
|
final License licenseSpec;
|
||||||
|
@ -58,16 +58,16 @@ public class LicenseVerificationTool extends Command {
|
||||||
} else if (options.has(licenseFileOption)) {
|
} else if (options.has(licenseFileOption)) {
|
||||||
Path licenseSpecPath = parsePath(licenseFileOption.value(options));
|
Path licenseSpecPath = parsePath(licenseFileOption.value(options));
|
||||||
if (Files.exists(licenseSpecPath) == false) {
|
if (Files.exists(licenseSpecPath) == false) {
|
||||||
throw new UserError(ExitCodes.USAGE, licenseSpecPath + " does not exist");
|
throw new UserException(ExitCodes.USAGE, licenseSpecPath + " does not exist");
|
||||||
}
|
}
|
||||||
licenseSpec = License.fromSource(Files.readAllBytes(licenseSpecPath));
|
licenseSpec = License.fromSource(Files.readAllBytes(licenseSpecPath));
|
||||||
} else {
|
} else {
|
||||||
throw new UserError(ExitCodes.USAGE, "Must specify either --license or --licenseFile");
|
throw new UserException(ExitCodes.USAGE, "Must specify either --license or --licenseFile");
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
if (LicenseVerifier.verifyLicense(licenseSpec, Files.readAllBytes(publicKeyPath)) == false) {
|
if (LicenseVerifier.verifyLicense(licenseSpec, Files.readAllBytes(publicKeyPath)) == false) {
|
||||||
throw new UserError(ExitCodes.DATA_ERROR, "Invalid License!");
|
throw new UserException(ExitCodes.DATA_ERROR, "Invalid License!");
|
||||||
}
|
}
|
||||||
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
|
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
|
|
|
@ -11,9 +11,7 @@ import java.nio.file.Path;
|
||||||
import org.elasticsearch.cli.Command;
|
import org.elasticsearch.cli.Command;
|
||||||
import org.elasticsearch.cli.CommandTestCase;
|
import org.elasticsearch.cli.CommandTestCase;
|
||||||
import org.elasticsearch.cli.ExitCodes;
|
import org.elasticsearch.cli.ExitCodes;
|
||||||
import org.elasticsearch.cli.UserError;
|
import org.elasticsearch.cli.UserException;
|
||||||
import org.elasticsearch.cli.Terminal;
|
|
||||||
import org.elasticsearch.test.ESTestCase;
|
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.containsString;
|
import static org.hamcrest.CoreMatchers.containsString;
|
||||||
|
|
||||||
|
@ -27,12 +25,12 @@ public class KeyPairGenerationToolTests extends CommandTestCase {
|
||||||
public void testMissingKeyPaths() throws Exception {
|
public void testMissingKeyPaths() throws Exception {
|
||||||
Path exists = createTempFile("", "existing");
|
Path exists = createTempFile("", "existing");
|
||||||
Path dne = createTempDir().resolve("dne");
|
Path dne = createTempDir().resolve("dne");
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
execute("--publicKeyPath", exists.toString(), "--privateKeyPath", dne.toString());
|
execute("--publicKeyPath", exists.toString(), "--privateKeyPath", dne.toString());
|
||||||
});
|
});
|
||||||
assertThat(e.getMessage(), containsString("existing"));
|
assertThat(e.getMessage(), containsString("existing"));
|
||||||
assertEquals(ExitCodes.USAGE, e.exitCode);
|
assertEquals(ExitCodes.USAGE, e.exitCode);
|
||||||
e = expectThrows(UserError.class, () -> {
|
e = expectThrows(UserException.class, () -> {
|
||||||
execute("--publicKeyPath", dne.toString(), "--privateKeyPath", exists.toString());
|
execute("--publicKeyPath", dne.toString(), "--privateKeyPath", exists.toString());
|
||||||
});
|
});
|
||||||
assertThat(e.getMessage(), containsString("existing"));
|
assertThat(e.getMessage(), containsString("existing"));
|
||||||
|
|
|
@ -12,12 +12,9 @@ import java.nio.file.Path;
|
||||||
import org.elasticsearch.cli.Command;
|
import org.elasticsearch.cli.Command;
|
||||||
import org.elasticsearch.cli.CommandTestCase;
|
import org.elasticsearch.cli.CommandTestCase;
|
||||||
import org.elasticsearch.cli.ExitCodes;
|
import org.elasticsearch.cli.ExitCodes;
|
||||||
import org.elasticsearch.cli.UserError;
|
import org.elasticsearch.cli.UserException;
|
||||||
import org.elasticsearch.cli.MockTerminal;
|
|
||||||
import org.elasticsearch.cli.Terminal;
|
|
||||||
import org.elasticsearch.license.core.License;
|
import org.elasticsearch.license.core.License;
|
||||||
import org.elasticsearch.license.licensor.TestUtils;
|
import org.elasticsearch.license.licensor.TestUtils;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
public class LicenseGenerationToolTests extends CommandTestCase {
|
public class LicenseGenerationToolTests extends CommandTestCase {
|
||||||
|
@ -38,14 +35,14 @@ public class LicenseGenerationToolTests extends CommandTestCase {
|
||||||
public void testMissingKeyPaths() throws Exception {
|
public void testMissingKeyPaths() throws Exception {
|
||||||
Path pub = createTempDir().resolve("pub");
|
Path pub = createTempDir().resolve("pub");
|
||||||
Path pri = createTempDir().resolve("pri");
|
Path pri = createTempDir().resolve("pri");
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
execute("--publicKeyPath", pub.toString(), "--privateKeyPath", pri.toString());
|
execute("--publicKeyPath", pub.toString(), "--privateKeyPath", pri.toString());
|
||||||
});
|
});
|
||||||
assertTrue(e.getMessage(), e.getMessage().contains("pri does not exist"));
|
assertTrue(e.getMessage(), e.getMessage().contains("pri does not exist"));
|
||||||
assertEquals(ExitCodes.USAGE, e.exitCode);
|
assertEquals(ExitCodes.USAGE, e.exitCode);
|
||||||
|
|
||||||
Files.createFile(pri);
|
Files.createFile(pri);
|
||||||
e = expectThrows(UserError.class, () -> {
|
e = expectThrows(UserException.class, () -> {
|
||||||
execute("--publicKeyPath", pub.toString(), "--privateKeyPath", pri.toString());
|
execute("--publicKeyPath", pub.toString(), "--privateKeyPath", pri.toString());
|
||||||
});
|
});
|
||||||
assertTrue(e.getMessage(), e.getMessage().contains("pub does not exist"));
|
assertTrue(e.getMessage(), e.getMessage().contains("pub does not exist"));
|
||||||
|
@ -53,7 +50,7 @@ public class LicenseGenerationToolTests extends CommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMissingLicenseSpec() throws Exception {
|
public void testMissingLicenseSpec() throws Exception {
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
execute("--publicKeyPath", pubKeyPath.toString(), "--privateKeyPath", priKeyPath.toString());
|
execute("--publicKeyPath", pubKeyPath.toString(), "--privateKeyPath", priKeyPath.toString());
|
||||||
});
|
});
|
||||||
assertTrue(e.getMessage(), e.getMessage().contains("Must specify either --license or --licenseFile"));
|
assertTrue(e.getMessage(), e.getMessage().contains("Must specify either --license or --licenseFile"));
|
||||||
|
|
|
@ -12,7 +12,7 @@ import java.nio.file.Path;
|
||||||
import org.elasticsearch.cli.Command;
|
import org.elasticsearch.cli.Command;
|
||||||
import org.elasticsearch.cli.CommandTestCase;
|
import org.elasticsearch.cli.CommandTestCase;
|
||||||
import org.elasticsearch.cli.ExitCodes;
|
import org.elasticsearch.cli.ExitCodes;
|
||||||
import org.elasticsearch.cli.UserError;
|
import org.elasticsearch.cli.UserException;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.license.core.License;
|
import org.elasticsearch.license.core.License;
|
||||||
import org.elasticsearch.license.licensor.TestUtils;
|
import org.elasticsearch.license.licensor.TestUtils;
|
||||||
|
@ -36,7 +36,7 @@ public class LicenseVerificationToolTests extends CommandTestCase {
|
||||||
|
|
||||||
public void testMissingKeyPath() throws Exception {
|
public void testMissingKeyPath() throws Exception {
|
||||||
Path pub = createTempDir().resolve("pub");
|
Path pub = createTempDir().resolve("pub");
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
execute("--publicKeyPath", pub.toString());
|
execute("--publicKeyPath", pub.toString());
|
||||||
});
|
});
|
||||||
assertTrue(e.getMessage(), e.getMessage().contains("pub does not exist"));
|
assertTrue(e.getMessage(), e.getMessage().contains("pub does not exist"));
|
||||||
|
@ -44,7 +44,7 @@ public class LicenseVerificationToolTests extends CommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMissingLicenseSpec() throws Exception {
|
public void testMissingLicenseSpec() throws Exception {
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
execute("--publicKeyPath", pubKeyPath.toString());
|
execute("--publicKeyPath", pubKeyPath.toString());
|
||||||
});
|
});
|
||||||
assertTrue(e.getMessage(), e.getMessage().contains("Must specify either --license or --licenseFile"));
|
assertTrue(e.getMessage(), e.getMessage().contains("Must specify either --license or --licenseFile"));
|
||||||
|
@ -56,7 +56,7 @@ public class LicenseVerificationToolTests extends CommandTestCase {
|
||||||
License tamperedLicense = License.builder()
|
License tamperedLicense = License.builder()
|
||||||
.fromLicenseSpec(signedLicense, signedLicense.signature())
|
.fromLicenseSpec(signedLicense, signedLicense.signature())
|
||||||
.expiryDate(signedLicense.expiryDate() + randomIntBetween(1, 1000)).build();
|
.expiryDate(signedLicense.expiryDate() + randomIntBetween(1, 1000)).build();
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
execute("--publicKeyPath", pubKeyPath.toString(),
|
execute("--publicKeyPath", pubKeyPath.toString(),
|
||||||
"--license", TestUtils.dumpLicense(tamperedLicense));
|
"--license", TestUtils.dumpLicense(tamperedLicense));
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,7 +11,7 @@ import org.elasticsearch.cli.ExitCodes;
|
||||||
import org.elasticsearch.cli.MultiCommand;
|
import org.elasticsearch.cli.MultiCommand;
|
||||||
import org.elasticsearch.cli.SettingCommand;
|
import org.elasticsearch.cli.SettingCommand;
|
||||||
import org.elasticsearch.cli.Terminal;
|
import org.elasticsearch.cli.Terminal;
|
||||||
import org.elasticsearch.cli.UserError;
|
import org.elasticsearch.cli.UserException;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.util.set.Sets;
|
import org.elasticsearch.common.util.set.Sets;
|
||||||
|
@ -88,7 +88,7 @@ public class UsersTool extends MultiCommand {
|
||||||
String username = parseUsername(arguments.values(options));
|
String username = parseUsername(arguments.values(options));
|
||||||
Validation.Error validationError = Users.validateUsername(username);
|
Validation.Error validationError = Users.validateUsername(username);
|
||||||
if (validationError != null) {
|
if (validationError != null) {
|
||||||
throw new UserError(ExitCodes.DATA_ERROR, "Invalid username [" + username + "]... " + validationError);
|
throw new UserException(ExitCodes.DATA_ERROR, "Invalid username [" + username + "]... " + validationError);
|
||||||
}
|
}
|
||||||
|
|
||||||
char[] password = parsePassword(terminal, passwordOption.value(options));
|
char[] password = parsePassword(terminal, passwordOption.value(options));
|
||||||
|
@ -102,7 +102,7 @@ public class UsersTool extends MultiCommand {
|
||||||
|
|
||||||
Map<String, char[]> users = new HashMap<>(FileUserPasswdStore.parseFile(passwordFile, null));
|
Map<String, char[]> users = new HashMap<>(FileUserPasswdStore.parseFile(passwordFile, null));
|
||||||
if (users.containsKey(username)) {
|
if (users.containsKey(username)) {
|
||||||
throw new UserError(ExitCodes.CODE_ERROR, "User [" + username + "] already exists");
|
throw new UserException(ExitCodes.CODE_ERROR, "User [" + username + "] already exists");
|
||||||
}
|
}
|
||||||
Hasher hasher = Hasher.BCRYPT;
|
Hasher hasher = Hasher.BCRYPT;
|
||||||
users.put(username, hasher.hash(new SecuredString(password)));
|
users.put(username, hasher.hash(new SecuredString(password)));
|
||||||
|
@ -149,7 +149,7 @@ public class UsersTool extends MultiCommand {
|
||||||
|
|
||||||
Map<String, char[]> users = new HashMap<>(FileUserPasswdStore.parseFile(passwordFile, null));
|
Map<String, char[]> users = new HashMap<>(FileUserPasswdStore.parseFile(passwordFile, null));
|
||||||
if (users.containsKey(username) == false) {
|
if (users.containsKey(username) == false) {
|
||||||
throw new UserError(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
|
throw new UserException(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
|
||||||
}
|
}
|
||||||
if (Files.exists(passwordFile)) {
|
if (Files.exists(passwordFile)) {
|
||||||
char[] passwd = users.remove(username);
|
char[] passwd = users.remove(username);
|
||||||
|
@ -205,7 +205,7 @@ public class UsersTool extends MultiCommand {
|
||||||
FileAttributesChecker attributesChecker = new FileAttributesChecker(file);
|
FileAttributesChecker attributesChecker = new FileAttributesChecker(file);
|
||||||
Map<String, char[]> users = new HashMap<>(FileUserPasswdStore.parseFile(file, null));
|
Map<String, char[]> users = new HashMap<>(FileUserPasswdStore.parseFile(file, null));
|
||||||
if (users.containsKey(username) == false) {
|
if (users.containsKey(username) == false) {
|
||||||
throw new UserError(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
|
throw new UserException(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
|
||||||
}
|
}
|
||||||
users.put(username, Hasher.BCRYPT.hash(new SecuredString(password)));
|
users.put(username, Hasher.BCRYPT.hash(new SecuredString(password)));
|
||||||
FileUserPasswdStore.writeFile(users, file);
|
FileUserPasswdStore.writeFile(users, file);
|
||||||
|
@ -261,7 +261,7 @@ public class UsersTool extends MultiCommand {
|
||||||
|
|
||||||
Map<String, char[]> usersMap = FileUserPasswdStore.parseFile(usersFile, null);
|
Map<String, char[]> usersMap = FileUserPasswdStore.parseFile(usersFile, null);
|
||||||
if (!usersMap.containsKey(username)) {
|
if (!usersMap.containsKey(username)) {
|
||||||
throw new UserError(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
|
throw new UserException(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String[]> userRoles = FileUserRolesStore.parseFile(rolesFile, null);
|
Map<String, String[]> userRoles = FileUserRolesStore.parseFile(rolesFile, null);
|
||||||
|
@ -325,7 +325,7 @@ public class UsersTool extends MultiCommand {
|
||||||
|
|
||||||
if (username != null) {
|
if (username != null) {
|
||||||
if (!users.contains(username)) {
|
if (!users.contains(username)) {
|
||||||
throw new UserError(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
|
throw new UserException(ExitCodes.NO_USER, "User [" + username + "] doesn't exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userRoles.containsKey(username)) {
|
if (userRoles.containsKey(username)) {
|
||||||
|
@ -394,38 +394,38 @@ public class UsersTool extends MultiCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
// pkg private for testing
|
// pkg private for testing
|
||||||
static String parseUsername(List<String> args) throws UserError {
|
static String parseUsername(List<String> args) throws UserException {
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
throw new UserError(ExitCodes.USAGE, "Missing username argument");
|
throw new UserException(ExitCodes.USAGE, "Missing username argument");
|
||||||
} else if (args.size() > 1) {
|
} else if (args.size() > 1) {
|
||||||
throw new UserError(ExitCodes.USAGE, "Expected a single username argument, found extra: " + args.toString());
|
throw new UserException(ExitCodes.USAGE, "Expected a single username argument, found extra: " + args.toString());
|
||||||
}
|
}
|
||||||
String username = args.get(0);
|
String username = args.get(0);
|
||||||
Validation.Error validationError = Users.validateUsername(username);
|
Validation.Error validationError = Users.validateUsername(username);
|
||||||
if (validationError != null) {
|
if (validationError != null) {
|
||||||
throw new UserError(ExitCodes.DATA_ERROR, "Invalid username [" + username + "]... " + validationError);
|
throw new UserException(ExitCodes.DATA_ERROR, "Invalid username [" + username + "]... " + validationError);
|
||||||
}
|
}
|
||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pkg private for testing
|
// pkg private for testing
|
||||||
static char[] parsePassword(Terminal terminal, String passwordStr) throws UserError {
|
static char[] parsePassword(Terminal terminal, String passwordStr) throws UserException {
|
||||||
char[] password;
|
char[] password;
|
||||||
if (passwordStr != null) {
|
if (passwordStr != null) {
|
||||||
password = passwordStr.toCharArray();
|
password = passwordStr.toCharArray();
|
||||||
Validation.Error validationError = Users.validatePassword(password);
|
Validation.Error validationError = Users.validatePassword(password);
|
||||||
if (validationError != null) {
|
if (validationError != null) {
|
||||||
throw new UserError(ExitCodes.DATA_ERROR, "Invalid password..." + validationError);
|
throw new UserException(ExitCodes.DATA_ERROR, "Invalid password..." + validationError);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
password = terminal.readSecret("Enter new password: ");
|
password = terminal.readSecret("Enter new password: ");
|
||||||
Validation.Error validationError = Users.validatePassword(password);
|
Validation.Error validationError = Users.validatePassword(password);
|
||||||
if (validationError != null) {
|
if (validationError != null) {
|
||||||
throw new UserError(ExitCodes.DATA_ERROR, "Invalid password..." + validationError);
|
throw new UserException(ExitCodes.DATA_ERROR, "Invalid password..." + validationError);
|
||||||
}
|
}
|
||||||
char[] retyped = terminal.readSecret("Retype new password: ");
|
char[] retyped = terminal.readSecret("Retype new password: ");
|
||||||
if (Arrays.equals(password, retyped) == false) {
|
if (Arrays.equals(password, retyped) == false) {
|
||||||
throw new UserError(ExitCodes.DATA_ERROR, "Password mismatch");
|
throw new UserException(ExitCodes.DATA_ERROR, "Password mismatch");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return password;
|
return password;
|
||||||
|
@ -446,7 +446,7 @@ public class UsersTool extends MultiCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
// pkg private for testing
|
// pkg private for testing
|
||||||
static String[] parseRoles(Terminal terminal, Environment env, String rolesStr) throws UserError {
|
static String[] parseRoles(Terminal terminal, Environment env, String rolesStr) throws UserException {
|
||||||
if (rolesStr.isEmpty()) {
|
if (rolesStr.isEmpty()) {
|
||||||
return Strings.EMPTY_ARRAY;
|
return Strings.EMPTY_ARRAY;
|
||||||
}
|
}
|
||||||
|
@ -454,7 +454,7 @@ public class UsersTool extends MultiCommand {
|
||||||
for (String role : roles) {
|
for (String role : roles) {
|
||||||
Validation.Error validationError = Validation.Roles.validateRoleName(role);
|
Validation.Error validationError = Validation.Roles.validateRoleName(role);
|
||||||
if (validationError != null) {
|
if (validationError != null) {
|
||||||
throw new UserError(ExitCodes.DATA_ERROR, "Invalid role [" + role + "]... " + validationError);
|
throw new UserException(ExitCodes.DATA_ERROR, "Invalid role [" + role + "]... " + validationError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,10 @@ package org.elasticsearch.xpack.security.crypto.tool;
|
||||||
|
|
||||||
import joptsimple.OptionSet;
|
import joptsimple.OptionSet;
|
||||||
import joptsimple.OptionSpec;
|
import joptsimple.OptionSpec;
|
||||||
import joptsimple.util.KeyValuePair;
|
|
||||||
import org.elasticsearch.cli.Command;
|
|
||||||
import org.elasticsearch.cli.ExitCodes;
|
import org.elasticsearch.cli.ExitCodes;
|
||||||
import org.elasticsearch.cli.SettingCommand;
|
import org.elasticsearch.cli.SettingCommand;
|
||||||
import org.elasticsearch.cli.Terminal;
|
import org.elasticsearch.cli.Terminal;
|
||||||
import org.elasticsearch.cli.UserError;
|
import org.elasticsearch.cli.UserException;
|
||||||
import org.elasticsearch.common.SuppressForbidden;
|
import org.elasticsearch.common.SuppressForbidden;
|
||||||
import org.elasticsearch.common.io.PathUtils;
|
import org.elasticsearch.common.io.PathUtils;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
@ -26,7 +24,6 @@ import java.nio.file.Path;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.nio.file.attribute.PosixFileAttributeView;
|
import java.nio.file.attribute.PosixFileAttributeView;
|
||||||
import java.nio.file.attribute.PosixFilePermission;
|
import java.nio.file.attribute.PosixFilePermission;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -65,7 +62,7 @@ public class SystemKeyTool extends SettingCommand {
|
||||||
if (options.hasArgument(arguments)) {
|
if (options.hasArgument(arguments)) {
|
||||||
List<String> args = arguments.values(options);
|
List<String> args = arguments.values(options);
|
||||||
if (args.size() > 1) {
|
if (args.size() > 1) {
|
||||||
throw new UserError(ExitCodes.USAGE, "No more than one key path can be supplied");
|
throw new UserException(ExitCodes.USAGE, "No more than one key path can be supplied");
|
||||||
}
|
}
|
||||||
keyPath = parsePath(args.get(0));
|
keyPath = parsePath(args.get(0));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -11,7 +11,7 @@ import org.apache.lucene.util.IOUtils;
|
||||||
import org.elasticsearch.cli.Command;
|
import org.elasticsearch.cli.Command;
|
||||||
import org.elasticsearch.cli.CommandTestCase;
|
import org.elasticsearch.cli.CommandTestCase;
|
||||||
import org.elasticsearch.cli.ExitCodes;
|
import org.elasticsearch.cli.ExitCodes;
|
||||||
import org.elasticsearch.cli.UserError;
|
import org.elasticsearch.cli.UserException;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.io.PathUtilsForTesting;
|
import org.elasticsearch.common.io.PathUtilsForTesting;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
@ -174,7 +174,7 @@ public class UsersToolTests extends CommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseInvalidUsername() throws Exception {
|
public void testParseInvalidUsername() throws Exception {
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
UsersTool.parseUsername(Collections.singletonList("$34dkl"));
|
UsersTool.parseUsername(Collections.singletonList("$34dkl"));
|
||||||
});
|
});
|
||||||
assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
|
assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
|
||||||
|
@ -182,7 +182,7 @@ public class UsersToolTests extends CommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseUsernameMissing() throws Exception {
|
public void testParseUsernameMissing() throws Exception {
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
UsersTool.parseUsername(Collections.emptyList());
|
UsersTool.parseUsername(Collections.emptyList());
|
||||||
});
|
});
|
||||||
assertEquals(ExitCodes.USAGE, e.exitCode);
|
assertEquals(ExitCodes.USAGE, e.exitCode);
|
||||||
|
@ -190,7 +190,7 @@ public class UsersToolTests extends CommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseUsernameExtraArgs() throws Exception {
|
public void testParseUsernameExtraArgs() throws Exception {
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
UsersTool.parseUsername(Arrays.asList("username", "extra"));
|
UsersTool.parseUsername(Arrays.asList("username", "extra"));
|
||||||
});
|
});
|
||||||
assertEquals(ExitCodes.USAGE, e.exitCode);
|
assertEquals(ExitCodes.USAGE, e.exitCode);
|
||||||
|
@ -198,7 +198,7 @@ public class UsersToolTests extends CommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseInvalidPasswordOption() throws Exception {
|
public void testParseInvalidPasswordOption() throws Exception {
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
UsersTool.parsePassword(terminal, "123");
|
UsersTool.parsePassword(terminal, "123");
|
||||||
});
|
});
|
||||||
assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
|
assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
|
||||||
|
@ -207,7 +207,7 @@ public class UsersToolTests extends CommandTestCase {
|
||||||
|
|
||||||
public void testParseInvalidPasswordInput() throws Exception {
|
public void testParseInvalidPasswordInput() throws Exception {
|
||||||
terminal.addSecretInput("123");
|
terminal.addSecretInput("123");
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
UsersTool.parsePassword(terminal, null);
|
UsersTool.parsePassword(terminal, null);
|
||||||
});
|
});
|
||||||
assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
|
assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
|
||||||
|
@ -217,7 +217,7 @@ public class UsersToolTests extends CommandTestCase {
|
||||||
public void testParseMismatchPasswordInput() throws Exception {
|
public void testParseMismatchPasswordInput() throws Exception {
|
||||||
terminal.addSecretInput("password1");
|
terminal.addSecretInput("password1");
|
||||||
terminal.addSecretInput("password2");
|
terminal.addSecretInput("password2");
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
UsersTool.parsePassword(terminal, null);
|
UsersTool.parsePassword(terminal, null);
|
||||||
});
|
});
|
||||||
assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
|
assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
|
||||||
|
@ -239,7 +239,7 @@ public class UsersToolTests extends CommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseInvalidRole() throws Exception {
|
public void testParseInvalidRole() throws Exception {
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
UsersTool.parseRoles(terminal, new Environment(settings), "$345");
|
UsersTool.parseRoles(terminal, new Environment(settings), "$345");
|
||||||
});
|
});
|
||||||
assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
|
assertEquals(ExitCodes.DATA_ERROR, e.exitCode);
|
||||||
|
@ -266,7 +266,7 @@ public class UsersToolTests extends CommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUseraddUserExists() throws Exception {
|
public void testUseraddUserExists() throws Exception {
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
execute("useradd", pathHomeParameter, fileTypeParameter, "existing_user", "-p", "changeme");
|
execute("useradd", pathHomeParameter, fileTypeParameter, "existing_user", "-p", "changeme");
|
||||||
});
|
});
|
||||||
assertEquals(ExitCodes.CODE_ERROR, e.exitCode);
|
assertEquals(ExitCodes.CODE_ERROR, e.exitCode);
|
||||||
|
@ -282,7 +282,7 @@ public class UsersToolTests extends CommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUserdelUnknownUser() throws Exception {
|
public void testUserdelUnknownUser() throws Exception {
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
execute("userdel", pathHomeParameter, fileTypeParameter, "unknown");
|
execute("userdel", pathHomeParameter, fileTypeParameter, "unknown");
|
||||||
});
|
});
|
||||||
assertEquals(ExitCodes.NO_USER, e.exitCode);
|
assertEquals(ExitCodes.NO_USER, e.exitCode);
|
||||||
|
@ -295,7 +295,7 @@ public class UsersToolTests extends CommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPasswdUnknownUser() throws Exception {
|
public void testPasswdUnknownUser() throws Exception {
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
execute("passwd", pathHomeParameter, fileTypeParameter, "unknown", "-p", "changeme");
|
execute("passwd", pathHomeParameter, fileTypeParameter, "unknown", "-p", "changeme");
|
||||||
});
|
});
|
||||||
assertEquals(ExitCodes.NO_USER, e.exitCode);
|
assertEquals(ExitCodes.NO_USER, e.exitCode);
|
||||||
|
@ -317,7 +317,7 @@ public class UsersToolTests extends CommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRolesUnknownUser() throws Exception {
|
public void testRolesUnknownUser() throws Exception {
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
execute("roles", pathHomeParameter, fileTypeParameter, "unknown");
|
execute("roles", pathHomeParameter, fileTypeParameter, "unknown");
|
||||||
});
|
});
|
||||||
assertEquals(ExitCodes.NO_USER, e.exitCode);
|
assertEquals(ExitCodes.NO_USER, e.exitCode);
|
||||||
|
@ -354,7 +354,7 @@ public class UsersToolTests extends CommandTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListUnknownUser() throws Exception {
|
public void testListUnknownUser() throws Exception {
|
||||||
UserError e = expectThrows(UserError.class, () -> {
|
UserException e = expectThrows(UserException.class, () -> {
|
||||||
execute("list", pathHomeParameter, fileTypeParameter, "unknown");
|
execute("list", pathHomeParameter, fileTypeParameter, "unknown");
|
||||||
});
|
});
|
||||||
assertEquals(ExitCodes.NO_USER, e.exitCode);
|
assertEquals(ExitCodes.NO_USER, e.exitCode);
|
||||||
|
|
|
@ -13,7 +13,7 @@ import org.elasticsearch.bootstrap.JarHell;
|
||||||
import org.elasticsearch.cli.ExitCodes;
|
import org.elasticsearch.cli.ExitCodes;
|
||||||
import org.elasticsearch.cli.SettingCommand;
|
import org.elasticsearch.cli.SettingCommand;
|
||||||
import org.elasticsearch.cli.Terminal;
|
import org.elasticsearch.cli.Terminal;
|
||||||
import org.elasticsearch.cli.UserError;
|
import org.elasticsearch.cli.UserException;
|
||||||
import org.elasticsearch.common.io.FileSystemUtils;
|
import org.elasticsearch.common.io.FileSystemUtils;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.env.Environment;
|
import org.elasticsearch.env.Environment;
|
||||||
|
@ -83,7 +83,7 @@ final class InstallXPackExtensionCommand extends SettingCommand {
|
||||||
// TODO: in jopt-simple 5.0 we can enforce a min/max number of positional args
|
// TODO: in jopt-simple 5.0 we can enforce a min/max number of positional args
|
||||||
List<String> args = arguments.values(options);
|
List<String> args = arguments.values(options);
|
||||||
if (args.size() != 1) {
|
if (args.size() != 1) {
|
||||||
throw new UserError(ExitCodes.USAGE, "Must supply a single extension id argument");
|
throw new UserException(ExitCodes.USAGE, "Must supply a single extension id argument");
|
||||||
}
|
}
|
||||||
String extensionURL = args.get(0);
|
String extensionURL = args.get(0);
|
||||||
boolean isBatch = options.has(batchOption) || System.console() == null;
|
boolean isBatch = options.has(batchOption) || System.console() == null;
|
||||||
|
@ -116,7 +116,7 @@ final class InstallXPackExtensionCommand extends SettingCommand {
|
||||||
return zip;
|
return zip;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path unzip(Path zip, Path extensionDir) throws IOException, UserError {
|
private Path unzip(Path zip, Path extensionDir) throws IOException, UserException {
|
||||||
// unzip extension to a staging temp dir
|
// unzip extension to a staging temp dir
|
||||||
Path target = Files.createTempDirectory(extensionDir, ".installing-");
|
Path target = Files.createTempDirectory(extensionDir, ".installing-");
|
||||||
Files.createDirectories(target);
|
Files.createDirectories(target);
|
||||||
|
@ -195,7 +195,7 @@ final class InstallXPackExtensionCommand extends SettingCommand {
|
||||||
XPackExtensionInfo info = verify(terminal, tmpRoot, env, isBatch);
|
XPackExtensionInfo info = verify(terminal, tmpRoot, env, isBatch);
|
||||||
final Path destination = resolveXPackExtensionsFile(env).resolve(info.getName());
|
final Path destination = resolveXPackExtensionsFile(env).resolve(info.getName());
|
||||||
if (Files.exists(destination)) {
|
if (Files.exists(destination)) {
|
||||||
throw new UserError(ExitCodes.USAGE,
|
throw new UserException(ExitCodes.USAGE,
|
||||||
"extension directory " + destination.toAbsolutePath() +
|
"extension directory " + destination.toAbsolutePath() +
|
||||||
" already exists. To update the extension, uninstall it first using 'remove " +
|
" already exists. To update the extension, uninstall it first using 'remove " +
|
||||||
info.getName() + "' command");
|
info.getName() + "' command");
|
||||||
|
|
|
@ -11,7 +11,7 @@ import org.apache.lucene.util.IOUtils;
|
||||||
import org.elasticsearch.cli.ExitCodes;
|
import org.elasticsearch.cli.ExitCodes;
|
||||||
import org.elasticsearch.cli.SettingCommand;
|
import org.elasticsearch.cli.SettingCommand;
|
||||||
import org.elasticsearch.cli.Terminal;
|
import org.elasticsearch.cli.Terminal;
|
||||||
import org.elasticsearch.cli.UserError;
|
import org.elasticsearch.cli.UserException;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.env.Environment;
|
import org.elasticsearch.env.Environment;
|
||||||
|
@ -44,7 +44,7 @@ class RemoveXPackExtensionCommand extends SettingCommand {
|
||||||
// TODO: in jopt-simple 5.0 we can enforce a min/max number of positional args
|
// TODO: in jopt-simple 5.0 we can enforce a min/max number of positional args
|
||||||
List<String> args = arguments.values(options);
|
List<String> args = arguments.values(options);
|
||||||
if (args.size() != 1) {
|
if (args.size() != 1) {
|
||||||
throw new UserError(ExitCodes.USAGE, "Must supply a single extension id argument");
|
throw new UserException(ExitCodes.USAGE, "Must supply a single extension id argument");
|
||||||
}
|
}
|
||||||
execute(terminal, args.get(0), settings);
|
execute(terminal, args.get(0), settings);
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class RemoveXPackExtensionCommand extends SettingCommand {
|
||||||
Environment env = InternalSettingsPreparer.prepareEnvironment(Settings.EMPTY, terminal, settings);
|
Environment env = InternalSettingsPreparer.prepareEnvironment(Settings.EMPTY, terminal, settings);
|
||||||
Path extensionDir = resolveXPackExtensionsFile(env).resolve(extensionName);
|
Path extensionDir = resolveXPackExtensionsFile(env).resolve(extensionName);
|
||||||
if (Files.exists(extensionDir) == false) {
|
if (Files.exists(extensionDir) == false) {
|
||||||
throw new UserError(ExitCodes.USAGE,
|
throw new UserException(ExitCodes.USAGE,
|
||||||
"Extension " + extensionName + " not found. Run 'bin/x-pack/extension list' to get list of installed extensions.");
|
"Extension " + extensionName + " not found. Run 'bin/x-pack/extension list' to get list of installed extensions.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ package org.elasticsearch.xpack.extensions;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.cli.MockTerminal;
|
import org.elasticsearch.cli.MockTerminal;
|
||||||
import org.elasticsearch.cli.UserError;
|
import org.elasticsearch.cli.UserException;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.env.Environment;
|
import org.elasticsearch.env.Environment;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
|
@ -162,7 +162,7 @@ public class InstallXPackExtensionCommandTests extends ESTestCase {
|
||||||
public void testExistingExtension() throws Exception {
|
public void testExistingExtension() throws Exception {
|
||||||
String extZip = createExtension("fake", createTempDir());
|
String extZip = createExtension("fake", createTempDir());
|
||||||
installExtension(extZip, home);
|
installExtension(extZip, home);
|
||||||
UserError e = expectThrows(UserError.class, () -> installExtension(extZip, home));
|
UserException e = expectThrows(UserException.class, () -> installExtension(extZip, home));
|
||||||
assertTrue(e.getMessage(), e.getMessage().contains("already exists"));
|
assertTrue(e.getMessage(), e.getMessage().contains("already exists"));
|
||||||
assertInstallCleaned(env);
|
assertInstallCleaned(env);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ package org.elasticsearch.xpack.extensions;
|
||||||
|
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
import org.elasticsearch.cli.MockTerminal;
|
import org.elasticsearch.cli.MockTerminal;
|
||||||
import org.elasticsearch.cli.UserError;
|
import org.elasticsearch.cli.UserException;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.env.Environment;
|
import org.elasticsearch.env.Environment;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
|
@ -58,7 +58,7 @@ public class RemoveXPackExtensionCommandTests extends ESTestCase {
|
||||||
|
|
||||||
public void testMissing() throws Exception {
|
public void testMissing() throws Exception {
|
||||||
Path extDir = createExtensionDir(env);
|
Path extDir = createExtensionDir(env);
|
||||||
UserError e = expectThrows(UserError.class, () -> removeExtension("dne", home));
|
UserException e = expectThrows(UserException.class, () -> removeExtension("dne", home));
|
||||||
assertTrue(e.getMessage(), e.getMessage().contains("Extension dne not found"));
|
assertTrue(e.getMessage(), e.getMessage().contains("Extension dne not found"));
|
||||||
assertRemoveCleaned(extDir);
|
assertRemoveCleaned(extDir);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import joptsimple.OptionSet;
|
||||||
import joptsimple.OptionSpec;
|
import joptsimple.OptionSpec;
|
||||||
import org.elasticsearch.cli.Command;
|
import org.elasticsearch.cli.Command;
|
||||||
import org.elasticsearch.cli.ExitCodes;
|
import org.elasticsearch.cli.ExitCodes;
|
||||||
import org.elasticsearch.cli.UserError;
|
import org.elasticsearch.cli.UserException;
|
||||||
import org.elasticsearch.cli.Terminal;
|
import org.elasticsearch.cli.Terminal;
|
||||||
import org.elasticsearch.xpack.watcher.trigger.schedule.Cron;
|
import org.elasticsearch.xpack.watcher.trigger.schedule.Cron;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
@ -46,7 +46,7 @@ public class CronEvalTool extends Command {
|
||||||
int count = Integer.parseInt(countOption.value(options));
|
int count = Integer.parseInt(countOption.value(options));
|
||||||
List<String> args = arguments.values(options);
|
List<String> args = arguments.values(options);
|
||||||
if (args.size() != 1) {
|
if (args.size() != 1) {
|
||||||
throw new UserError(ExitCodes.USAGE, "expecting a single argument that is the cron expression to evaluate");
|
throw new UserException(ExitCodes.USAGE, "expecting a single argument that is the cron expression to evaluate");
|
||||||
}
|
}
|
||||||
execute(terminal, args.get(0), count);
|
execute(terminal, args.get(0), count);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public class CronEvalTool extends Command {
|
||||||
long prevTime = time;
|
long prevTime = time;
|
||||||
time = cron.getNextValidTimeAfter(time);
|
time = cron.getNextValidTimeAfter(time);
|
||||||
if (time < 0) {
|
if (time < 0) {
|
||||||
throw new UserError(ExitCodes.OK, (i + 1) + ".\t Could not compute future times since ["
|
throw new UserException(ExitCodes.OK, (i + 1) + ".\t Could not compute future times since ["
|
||||||
+ formatter.print(prevTime) + "] " + "(perhaps the cron expression only points to times in the past?)");
|
+ formatter.print(prevTime) + "] " + "(perhaps the cron expression only points to times in the past?)");
|
||||||
}
|
}
|
||||||
terminal.println((i+1) + ".\t" + formatter.print(time));
|
terminal.println((i+1) + ".\t" + formatter.print(time));
|
||||||
|
|
Loading…
Reference in New Issue