use of jline.console.ConsoleReader in project cdap by caskdata.
the class CLIConfig method getNewAccessToken.
private UserAccessToken getNewAccessToken(ConnectionConfig connectionInfo, PrintStream output, boolean debug) throws IOException {
AuthenticationClient authenticationClient = getAuthenticationClient(connectionInfo);
Properties properties = new Properties();
properties.put(BasicAuthenticationClient.VERIFY_SSL_CERT_PROP_NAME, String.valueOf(clientConfig.isVerifySSLCert()));
String username = "";
// obtain new access token via manual user input
output.printf("Authentication is enabled in the CDAP instance: %s.\n", connectionInfo.getHostname());
ConsoleReader reader = new ConsoleReader();
for (Credential credential : authenticationClient.getRequiredCredentials()) {
String prompt = "Please, specify " + credential.getDescription() + "> ";
String credentialValue;
if (credential.isSecret()) {
credentialValue = reader.readLine(prompt, '*');
} else {
credentialValue = reader.readLine(prompt);
}
properties.put(credential.getName(), credentialValue);
if (credential.getName().contains("username")) {
username = credentialValue;
}
}
authenticationClient.configure(properties);
AccessToken accessToken = authenticationClient.getAccessToken();
UserAccessToken userToken = new UserAccessToken(accessToken, username);
if (accessToken != null) {
if (saveAccessToken(userToken, connectionInfo.getHostname()) && debug) {
output.printf("Saved access token to %s\n", getAccessTokenFile(connectionInfo.getHostname()).getAbsolutePath());
}
}
return userToken;
}
use of jline.console.ConsoleReader in project hive by apache.
the class BeeLine method initializeConsoleReader.
public ConsoleReader initializeConsoleReader(InputStream inputStream) throws IOException {
if (inputStream != null) {
// ### NOTE: fix for sf.net bug 879425.
// Working around an issue in jline-2.1.2, see https://github.com/jline/jline/issues/10
// by appending a newline to the end of inputstream
InputStream inputStreamAppendedNewline = new SequenceInputStream(inputStream, new ByteArrayInputStream((new String("\n")).getBytes()));
consoleReader = new ConsoleReader(inputStreamAppendedNewline, getErrorStream());
// jline will detect if <tab> is regular character
consoleReader.setCopyPasteDetection(true);
} else {
consoleReader = new ConsoleReader(getInputStream(), getErrorStream());
}
// disable the expandEvents for the purpose of backward compatibility
consoleReader.setExpandEvents(false);
try {
// now set the output for the history
consoleReader.setHistory(this.history);
} catch (Exception e) {
handleException(e);
}
if (inputStream instanceof FileInputStream || inputStream instanceof FSDataInputStream) {
// from script.. no need to load history and no need of completer, either
return consoleReader;
}
consoleReader.addCompleter(new BeeLineCompleter(this));
return consoleReader;
}
Aggregations