Skip to content

Commit

Permalink
Different handling for security specific errors in the CLI. Fix for #…
Browse files Browse the repository at this point in the history
  • Loading branch information
astefan committed Aug 31, 2018
1 parent e5eddc2 commit f3b848a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/reference/sql/endpoints/cli.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ the first parameter:
$ ./bin/elasticsearch-sql-cli https://some.server:9200
--------------------------------------------------

If security is enabled on your cluster, you can pass the username
and password in the form `username:password@host_name:port`
to the SQL CLI:

[source,bash]
--------------------------------------------------
$ ./bin/elasticsearch-sql-cli https://sql_user:strongpassword@some.server:9200
--------------------------------------------------

Once the CLI is running you can use any <<sql-spec,query>> that
Elasticsearch supports:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jline.terminal.TerminalBuilder;
import java.io.IOException;
import java.net.ConnectException;
import java.sql.SQLInvalidAuthorizationSpecException;
import java.util.Arrays;
import java.util.List;
import java.util.logging.LogManager;
Expand Down Expand Up @@ -139,6 +140,10 @@ private void checkConnection(CliSession cliSession, CliTerminal cliTerminal, Con
// Most likely Elasticsearch is not running
throw new UserException(ExitCodes.IO_ERROR,
"Cannot connect to the server " + con.connectionString() + " - " + ex.getCause().getMessage());
} else if (ex.getCause() != null && ex.getCause() instanceof SQLInvalidAuthorizationSpecException) {
throw new UserException(ExitCodes.NOPERM,
"Cannot establish a secure connection to the server " +
con.connectionString() + " - " + ex.getCause().getMessage());
} else {
// Most likely we connected to something other than Elasticsearch
throw new UserException(ExitCodes.DATA_ERROR,
Expand Down

0 comments on commit f3b848a

Please sign in to comment.