Search in sources :

Example 96 with ConsoleReader

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;
}
Also used : Credential(co.cask.cdap.security.authentication.client.Credential) ConsoleReader(jline.console.ConsoleReader) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) AuthenticationClient(co.cask.cdap.security.authentication.client.AuthenticationClient) BasicAuthenticationClient(co.cask.cdap.security.authentication.client.basic.BasicAuthenticationClient) Properties(java.util.Properties)

Example 97 with ConsoleReader

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;
}
Also used : SequenceInputStream(java.io.SequenceInputStream) ConsoleReader(jline.console.ConsoleReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) TTransportException(org.apache.thrift.transport.TTransportException) BeelineHS2ConnectionFileParseException(org.apache.hive.beeline.hs2connection.BeelineHS2ConnectionFileParseException) EOFException(java.io.EOFException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ParseException(org.apache.commons.cli.ParseException) SQLException(java.sql.SQLException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Aggregations

ConsoleReader (jline.console.ConsoleReader)97 UnsupportedTerminal (jline.UnsupportedTerminal)44 GeogigCLI (org.locationtech.geogig.cli.GeogigCLI)42 GeoGIG (org.locationtech.geogig.api.GeoGIG)22 IOException (java.io.IOException)19 Before (org.junit.Before)19 Test (org.junit.Test)17 File (java.io.File)12 MockitoException (org.mockito.exceptions.base.MockitoException)12 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)11 ObjectId (org.locationtech.geogig.api.ObjectId)9 TestPlatform (org.locationtech.geogig.api.TestPlatform)8 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)8 Ref (org.locationtech.geogig.api.Ref)7 CLITestContextBuilder (org.locationtech.geogig.cli.test.functional.general.CLITestContextBuilder)7 Ansi (org.fusesource.jansi.Ansi)6 NodeRef (org.locationtech.geogig.api.NodeRef)6 RevCommit (org.locationtech.geogig.api.RevCommit)6 FileInputStream (java.io.FileInputStream)4 RevObject (org.locationtech.geogig.api.RevObject)4