Example usage for com.google.api.client.googleapis.compute ComputeCredential TOKEN_SERVER_ENCODED_URL

List of usage examples for com.google.api.client.googleapis.compute ComputeCredential TOKEN_SERVER_ENCODED_URL

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.compute ComputeCredential TOKEN_SERVER_ENCODED_URL.

Prototype

String TOKEN_SERVER_ENCODED_URL

To view the source code for com.google.api.client.googleapis.compute ComputeCredential TOKEN_SERVER_ENCODED_URL.

Click Source Link

Document

Metadata Service Account token server encoded URL.

Usage

From source file:com.google.cloud.bigtable.hbase.CredentialFactory.java

License:Open Source License

/**
 * Initializes OAuth2 credential using preconfigured ServiceAccount settings on the local
 * GCE VM. See: <a href="https://developers.google.com/compute/docs/authentication"
 * >Authenticating from Google Compute Engine</a>.
 *//*  w  w  w.j  a v  a 2  s .  c  om*/
public static Credentials getCredentialFromMetadataServiceAccount()
        throws IOException, GeneralSecurityException {
    Credentials cred = new ComputeEngineCredentials(getHttpTransport());
    try {
        cred.refresh();
    } catch (IOException e) {
        throw new IOException("Error getting access token from metadata server at: "
                + ComputeCredential.TOKEN_SERVER_ENCODED_URL, e);
    }
    return cred;
}

From source file:com.google.cloud.hadoop.util.CredentialFactory.java

License:Open Source License

/**
 * Initializes OAuth2 credential using preconfigured ServiceAccount settings on the local
 * GCE VM. See: <a href="https://developers.google.com/compute/docs/authentication"
 * >Authenticating from Google Compute Engine</a>.
 *///  w  w  w .j ava 2  s.co m
public Credential getCredentialFromMetadataServiceAccount() throws IOException, GeneralSecurityException {
    LOG.debug("getCredentialFromMetadataServiceAccount()");
    Credential cred = new ComputeCredentialWithRetry(
            new ComputeCredential.Builder(getHttpTransport(), JSON_FACTORY)
                    .setRequestInitializer(new CredentialHttpRetryInitializer()));
    try {
        cred.refreshToken();
    } catch (IOException e) {
        throw new IOException("Error getting access token from metadata server at: "
                + ComputeCredential.TOKEN_SERVER_ENCODED_URL, e);
    }
    return cred;
}