List of usage examples for com.google.api.client.googleapis.auth.oauth2 GoogleCredential getApplicationDefault
@Beta public static GoogleCredential getApplicationDefault(HttpTransport transport, JsonFactory jsonFactory) throws IOException
From source file:io.rodeo.chute.bigquery.BigQueryExporter.java
License:Apache License
public BigQueryExporter(BigQueryExporterConfiguration config) { this.config = config; this.checkedSchemas = new HashSet<String>(); this.existingSchemaMap = new HashMap<String, com.google.api.services.bigquery.model.TableSchema>(); HttpTransport transport = new NetHttpTransport(); JsonFactory jsonFactory = new JacksonFactory(); GoogleCredential credential;//w w w . ja v a2s. c om try { credential = GoogleCredential.getApplicationDefault(transport, jsonFactory); } catch (IOException e) { throw new RuntimeException(e); } if (credential.createScopedRequired()) { credential = credential.createScoped(BigqueryScopes.all()); } this.bq = new Bigquery.Builder(transport, jsonFactory, credential) .setApplicationName(this.config.applicationName).build(); }
From source file:org.apache.druid.common.gcp.GcpModule.java
License:Apache License
@Provides @LazySingleton/*from w w w . ja v a 2 s . c o m*/ public HttpRequestInitializer getHttpRequestInitializer(HttpTransport transport, JsonFactory factory) throws IOException { GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, factory); if (credential.createScopedRequired()) { credential = credential .createScoped(Collections.singleton("https://www.googleapis.com/auth/cloud-platform")); } return credential; }
From source file:org.apache.zeppelin.bigquery.BigQueryInterpreter.java
License:Apache License
private static Bigquery createAuthorizedClient() throws IOException { HttpTransport transport = new NetHttpTransport(); JsonFactory jsonFactory = new JacksonFactory(); GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory); if (credential.createScopedRequired()) { Collection<String> bigqueryScopes = BigqueryScopes.all(); credential = credential.createScoped(bigqueryScopes); }/*from www . java 2s. c om*/ return new Bigquery.Builder(transport, jsonFactory, credential) .setApplicationName("Zeppelin/1.0 (GPN:Apache Zeppelin;)").build(); }
From source file:org.gradle.internal.resource.transport.gcp.gcs.GcsClient.java
License:Apache License
private static Supplier<Credential> getCredentialSupplier(final HttpTransport transport, final JsonFactory jsonFactory) { return Suppliers.memoize(new Supplier<Credential>() { @Override/*from www . j a va 2s . c om*/ public Credential get() { try { GoogleCredential googleCredential = GoogleCredential.getApplicationDefault(transport, jsonFactory); // Ensure we have a scope return googleCredential .createScoped(singletonList("https://www.googleapis.com/auth/devstorage.read_write")); } catch (IOException e) { throw new UncheckedIOException("Failed to get Google credentials for GCS connection", e); } } }); }
From source file:org.jenkinsci.plugins.googlecloudlogging.manager.BigQueryManager.java
License:Apache License
/** * Creates an authorized BigQuery builder using the Application Default Credentials. * * @return an authorized BigQuery builder * * @throws IOException//from w ww . j av a 2 s. c o m */ private static Bigquery createAuthorizedClient() throws IOException { HttpTransport transport = new NetHttpTransport(); JsonFactory jsonFactory = new JacksonFactory(); GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory); if (credential.createScopedRequired()) { credential = credential.createScoped(BigqueryScopes.all()); } return new Bigquery.Builder(transport, jsonFactory, credential) .setApplicationName(GoogleCloudLoggingConstants.APPLICATION_NAME).build(); }
From source file:utils.GCE.java
License:Apache License
GCE() { try {/*from w w w .java 2 s . com*/ JacksonFactory jaksonFactory = JacksonFactory.getDefaultInstance(); NetHttpTransport httpTransport = newTrustedTransport(); GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport, jaksonFactory) .createScoped(ComputeScopes.all()); this.compute = new Compute.Builder(httpTransport, jaksonFactory, credential).build(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:utils.PubSubUtil.java
License:Apache License
PubSubUtil() { try {/*ww w .j ava 2s .co m*/ JacksonFactory jaksonFactory = JacksonFactory.getDefaultInstance(); NetHttpTransport httpTransport = newTrustedTransport(); GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport, jaksonFactory) .createScoped(PubsubScopes.all()); this.pubsub = new Pubsub.Builder(httpTransport, jaksonFactory, credential).build(); } catch (Exception e) { throw new RuntimeException(e); } }