use of org.opensearch.cli.UserException in project OpenSearch by opensearch-project.
the class AddFileKeyStoreCommandTests method testFileDNE.
public void testFileDNE() throws Exception {
String password = "keystorepassword";
createKeystore(password);
terminal.addSecretInput(password);
UserException e = expectThrows(UserException.class, () -> execute("foo", "path/dne"));
assertEquals(ExitCodes.IO_ERROR, e.exitCode);
assertThat(e.getMessage(), containsString("File [path/dne] does not exist"));
}
use of org.opensearch.cli.UserException in project OpenSearch by opensearch-project.
the class AddFileKeyStoreCommandTests method testExtraArguments.
public void testExtraArguments() throws Exception {
String password = "keystorepassword";
createKeystore(password);
Path file = createRandomFile();
terminal.addSecretInput(password);
UserException e = expectThrows(UserException.class, () -> execute("foo", file.toString(), "bar"));
assertEquals(e.getMessage(), ExitCodes.USAGE, e.exitCode);
assertThat(e.getMessage(), containsString("settings and filenames must come in pairs"));
}
use of org.opensearch.cli.UserException in project OpenSearch by opensearch-project.
the class AddFileKeyStoreCommandTests method testMissingSettingName.
public void testMissingSettingName() throws Exception {
String password = "keystorepassword";
createKeystore(password);
terminal.addSecretInput(password);
UserException e = expectThrows(UserException.class, this::execute);
assertEquals(ExitCodes.USAGE, e.exitCode);
assertThat(e.getMessage(), containsString("Missing setting name"));
}
use of org.opensearch.cli.UserException in project OpenSearch by opensearch-project.
the class AddFileKeyStoreCommand method executeCommand.
@Override
protected void executeCommand(Terminal terminal, OptionSet options, Environment env) throws Exception {
final List<String> argumentValues = arguments.values(options);
if (argumentValues.size() == 0) {
throw new UserException(ExitCodes.USAGE, "Missing setting name");
}
if (argumentValues.size() % 2 != 0) {
throw new UserException(ExitCodes.USAGE, "settings and filenames must come in pairs");
}
final KeyStoreWrapper keyStore = getKeyStore();
for (int i = 0; i < argumentValues.size(); i += 2) {
final String setting = argumentValues.get(i);
if (keyStore.getSettingNames().contains(setting) && options.has(forceOption) == false) {
if (terminal.promptYesNo("Setting " + setting + " already exists. Overwrite?", false) == false) {
terminal.println("Exiting without modifying keystore.");
return;
}
}
final Path file = getPath(argumentValues.get(i + 1));
if (Files.exists(file) == false) {
throw new UserException(ExitCodes.IO_ERROR, "File [" + file.toString() + "] does not exist");
}
keyStore.setFile(setting, Files.readAllBytes(file));
}
keyStore.save(env.configDir(), getKeyStorePassword().getChars());
}
use of org.opensearch.cli.UserException in project OpenSearch by opensearch-project.
the class RemoveCustomsCommandIT method testCustomDoesNotMatch.
public void testCustomDoesNotMatch() throws Exception {
internalCluster().setBootstrapClusterManagerNodeIndex(0);
String node = internalCluster().startNode();
createIndex("test");
client().admin().indices().prepareDelete("test").get();
assertEquals(1, client().admin().cluster().prepareState().get().getState().metadata().indexGraveyard().getTombstones().size());
Settings dataPathSettings = internalCluster().dataPathSettings(node);
ensureStableCluster(1);
internalCluster().stopRandomDataNode();
Environment environment = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build());
UserException ex = expectThrows(UserException.class, () -> removeCustoms(environment, false, new String[] { "index-greveyard-with-typos" }));
assertThat(ex.getMessage(), containsString("No custom metadata matching [index-greveyard-with-typos] were " + "found on this node"));
}
Aggregations