Search in sources :

Example 1 with KerberosConfig

use of io.airlift.http.client.spnego.KerberosConfig in project presto by prestodb.

the class ClientOptions method toKerberosConfig.

public KerberosConfig toKerberosConfig() {
    KerberosConfig config = new KerberosConfig();
    if (krb5ConfigPath != null) {
        config.setConfig(new File(krb5ConfigPath));
    }
    if (krb5KeytabPath != null) {
        config.setKeytab(new File(krb5KeytabPath));
    }
    if (krb5CredentialCachePath != null) {
        config.setCredentialCache(new File(krb5CredentialCachePath));
    }
    config.setUseCanonicalHostname(!krb5DisableRemoteServiceHostnameCanonicalization);
    return config;
}
Also used : KerberosConfig(io.airlift.http.client.spnego.KerberosConfig) File(java.io.File)

Example 2 with KerberosConfig

use of io.airlift.http.client.spnego.KerberosConfig in project presto by prestodb.

the class Console method run.

@Override
public void run() {
    ClientSession session = clientOptions.toClientSession();
    KerberosConfig kerberosConfig = clientOptions.toKerberosConfig();
    boolean hasQuery = !Strings.isNullOrEmpty(clientOptions.execute);
    boolean isFromFile = !Strings.isNullOrEmpty(clientOptions.file);
    if (!hasQuery && !isFromFile) {
        AnsiConsole.systemInstall();
    }
    initializeLogging(clientOptions.logLevelsFile);
    String query = clientOptions.execute;
    if (hasQuery) {
        query += ";";
    }
    if (isFromFile) {
        if (hasQuery) {
            throw new RuntimeException("both --execute and --file specified");
        }
        try {
            query = Files.toString(new File(clientOptions.file), UTF_8);
            hasQuery = true;
        } catch (IOException e) {
            throw new RuntimeException(format("Error reading from file %s: %s", clientOptions.file, e.getMessage()));
        }
    }
    AtomicBoolean exiting = new AtomicBoolean();
    interruptThreadOnExit(Thread.currentThread(), exiting);
    try (QueryRunner queryRunner = QueryRunner.create(session, Optional.ofNullable(clientOptions.socksProxy), Optional.ofNullable(clientOptions.keystorePath), Optional.ofNullable(clientOptions.keystorePassword), Optional.ofNullable(clientOptions.truststorePath), Optional.ofNullable(clientOptions.truststorePassword), Optional.ofNullable(clientOptions.user), clientOptions.password ? Optional.of(getPassword()) : Optional.empty(), Optional.ofNullable(clientOptions.krb5Principal), Optional.ofNullable(clientOptions.krb5RemoteServiceName), clientOptions.authenticationEnabled, kerberosConfig)) {
        if (hasQuery) {
            executeCommand(queryRunner, query, clientOptions.outputFormat);
        } else {
            runConsole(queryRunner, session, exiting);
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientSession(com.facebook.presto.client.ClientSession) KerberosConfig(io.airlift.http.client.spnego.KerberosConfig) IOException(java.io.IOException) File(java.io.File)

Aggregations

KerberosConfig (io.airlift.http.client.spnego.KerberosConfig)2 File (java.io.File)2 ClientSession (com.facebook.presto.client.ClientSession)1 IOException (java.io.IOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1