com.google.api.client.googleapis.compute.ComputeCredential Java Examples

The following examples show how to use com.google.api.client.googleapis.compute.ComputeCredential. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CredentialFactory.java    From hadoop-connectors with Apache License 2.0 6 votes vote down vote up
/**
 * 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>.
 */
public static Credential getCredentialFromMetadataServiceAccount()
    throws IOException, GeneralSecurityException {
  logger.atFine().log("Getting service account credentials from meta data service.");
  Credential cred =
      new ComputeCredentialWithRetry(
          new ComputeCredential.Builder(getStaticHttpTransport(), JSON_FACTORY)
              .setRequestInitializer(new CredentialHttpRetryInitializer()));
  try {
    cred.refreshToken();
  } catch (IOException e) {
    throw new IOException(
        "Error getting access token from metadata server at: " + cred.getTokenServerEncodedUrl(),
        e);
  }
  return cred;
}
 
Example #2
Source File: GcsClientImpl.java    From exhibitor with Apache License 2.0 4 votes vote down vote up
private Credential authorize() throws Exception {
    JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    return new ComputeCredential.Builder(httpTransport, JSON_FACTORY).build();
}