Search in sources :

Example 1 with HttpCredentialsAdapter

use of com.google.auth.http.HttpCredentialsAdapter in project beam by apache.

the class BigQueryServicesImpl method newBigQueryClient.

/**
 * Returns a BigQuery client builder using the specified {@link BigQueryOptions}.
 */
private static Bigquery.Builder newBigQueryClient(BigQueryOptions options) {
    // Do not log 404. It clutters the output and is possibly even required by the
    // caller.
    RetryHttpRequestInitializer httpRequestInitializer = new RetryHttpRequestInitializer(ImmutableList.of(404));
    httpRequestInitializer.setCustomErrors(createBigQueryClientCustomErrors());
    httpRequestInitializer.setWriteTimeout(options.getHTTPWriteTimeout());
    ImmutableList.Builder<HttpRequestInitializer> initBuilder = ImmutableList.builder();
    Credentials credential = options.getGcpCredential();
    initBuilder.add(credential == null ? new NullCredentialInitializer() : new HttpCredentialsAdapter(credential));
    initBuilder.add(new LatencyRecordingHttpRequestInitializer(API_METRIC_LABEL));
    initBuilder.add(httpRequestInitializer);
    HttpRequestInitializer chainInitializer = new ChainingHttpRequestInitializer(Iterables.toArray(initBuilder.build(), HttpRequestInitializer.class));
    return new Bigquery.Builder(Transport.getTransport(), Transport.getJsonFactory(), chainInitializer).setApplicationName(options.getAppName()).setGoogleClientRequestInitializer(options.getGoogleApiTrace());
}
Also used : RetryHttpRequestInitializer(org.apache.beam.sdk.extensions.gcp.util.RetryHttpRequestInitializer) HttpCredentialsAdapter(com.google.auth.http.HttpCredentialsAdapter) ImmutableList(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList) LatencyRecordingHttpRequestInitializer(org.apache.beam.sdk.extensions.gcp.util.LatencyRecordingHttpRequestInitializer) ChainingHttpRequestInitializer(com.google.cloud.hadoop.util.ChainingHttpRequestInitializer) RetryHttpRequestInitializer(org.apache.beam.sdk.extensions.gcp.util.RetryHttpRequestInitializer) LatencyRecordingHttpRequestInitializer(org.apache.beam.sdk.extensions.gcp.util.LatencyRecordingHttpRequestInitializer) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer) NullCredentialInitializer(org.apache.beam.sdk.extensions.gcp.auth.NullCredentialInitializer) Credentials(com.google.auth.Credentials) ChainingHttpRequestInitializer(com.google.cloud.hadoop.util.ChainingHttpRequestInitializer)

Example 2 with HttpCredentialsAdapter

use of com.google.auth.http.HttpCredentialsAdapter in project beam by apache.

the class BigqueryClient method getNewBigqueryClient.

public static Bigquery getNewBigqueryClient(String applicationName) {
    HttpTransport transport = Transport.getTransport();
    JsonFactory jsonFactory = Transport.getJsonFactory();
    Credentials credential = getDefaultCredential();
    return new Bigquery.Builder(transport, jsonFactory, new HttpCredentialsAdapter(credential)).setApplicationName(applicationName).build();
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) HttpCredentialsAdapter(com.google.auth.http.HttpCredentialsAdapter) JsonFactory(com.google.api.client.json.JsonFactory) Credentials(com.google.auth.Credentials) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials)

Example 3 with HttpCredentialsAdapter

use of com.google.auth.http.HttpCredentialsAdapter in project beam by apache.

the class V1TestUtil method getDatastore.

/**
 * Build a new datastore client.
 */
static Datastore getDatastore(PipelineOptions pipelineOptions, String projectId) {
    Credentials credential = pipelineOptions.as(GcpOptions.class).getGcpCredential();
    HttpRequestInitializer initializer;
    if (credential != null) {
        initializer = new ChainingHttpRequestInitializer(new HttpCredentialsAdapter(credential), new RetryHttpRequestInitializer());
    } else {
        initializer = new RetryHttpRequestInitializer();
    }
    DatastoreOptions.Builder builder = new DatastoreOptions.Builder().projectId(projectId).initializer(initializer);
    return DatastoreFactory.get().create(builder.build());
}
Also used : RetryHttpRequestInitializer(org.apache.beam.sdk.extensions.gcp.util.RetryHttpRequestInitializer) GcpOptions(org.apache.beam.sdk.extensions.gcp.options.GcpOptions) HttpCredentialsAdapter(com.google.auth.http.HttpCredentialsAdapter) DatastoreOptions(com.google.datastore.v1.client.DatastoreOptions) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer) RetryHttpRequestInitializer(org.apache.beam.sdk.extensions.gcp.util.RetryHttpRequestInitializer) ChainingHttpRequestInitializer(com.google.cloud.hadoop.util.ChainingHttpRequestInitializer) Credentials(com.google.auth.Credentials) ChainingHttpRequestInitializer(com.google.cloud.hadoop.util.ChainingHttpRequestInitializer)

Example 4 with HttpCredentialsAdapter

use of com.google.auth.http.HttpCredentialsAdapter in project google-cloud-java by GoogleCloudPlatform.

the class HttpTransportOptions method getHttpRequestInitializer.

/**
   * Returns a request initializer responsible for initializing requests according to service
   * options.
   */
public HttpRequestInitializer getHttpRequestInitializer(final ServiceOptions<?, ?> serviceOptions) {
    Credentials scopedCredentials = serviceOptions.getScopedCredentials();
    final HttpRequestInitializer delegate = scopedCredentials != null && scopedCredentials != NoCredentials.getInstance() ? new HttpCredentialsAdapter(scopedCredentials) : null;
    return new HttpRequestInitializer() {

        @Override
        public void initialize(HttpRequest httpRequest) throws IOException {
            if (delegate != null) {
                delegate.initialize(httpRequest);
            }
            if (connectTimeout >= 0) {
                httpRequest.setConnectTimeout(connectTimeout);
            }
            if (readTimeout >= 0) {
                httpRequest.setReadTimeout(readTimeout);
            }
            HttpHeaders headers = httpRequest.getHeaders();
            headers.set("x-goog-api-client", getXGoogApiClientHeader(serviceOptions));
        }
    };
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) HttpHeaders(com.google.api.client.http.HttpHeaders) HttpCredentialsAdapter(com.google.auth.http.HttpCredentialsAdapter) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer) NoCredentials(com.google.cloud.NoCredentials) Credentials(com.google.auth.Credentials)

Example 5 with HttpCredentialsAdapter

use of com.google.auth.http.HttpCredentialsAdapter in project beam by apache.

the class BigqueryMatcher method newBigqueryClient.

@VisibleForTesting
Bigquery newBigqueryClient(String applicationName) {
    HttpTransport transport = Transport.getTransport();
    JsonFactory jsonFactory = Transport.getJsonFactory();
    Credentials credential = getDefaultCredential();
    return new Bigquery.Builder(transport, jsonFactory, new HttpCredentialsAdapter(credential)).setApplicationName(applicationName).build();
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) HttpCredentialsAdapter(com.google.auth.http.HttpCredentialsAdapter) JsonFactory(com.google.api.client.json.JsonFactory) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) Credentials(com.google.auth.Credentials) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Credentials (com.google.auth.Credentials)5 HttpCredentialsAdapter (com.google.auth.http.HttpCredentialsAdapter)5 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)3 HttpTransport (com.google.api.client.http.HttpTransport)2 JsonFactory (com.google.api.client.json.JsonFactory)2 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)2 ChainingHttpRequestInitializer (com.google.cloud.hadoop.util.ChainingHttpRequestInitializer)2 RetryHttpRequestInitializer (org.apache.beam.sdk.extensions.gcp.util.RetryHttpRequestInitializer)2 HttpHeaders (com.google.api.client.http.HttpHeaders)1 HttpRequest (com.google.api.client.http.HttpRequest)1 NoCredentials (com.google.cloud.NoCredentials)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 DatastoreOptions (com.google.datastore.v1.client.DatastoreOptions)1 NullCredentialInitializer (org.apache.beam.sdk.extensions.gcp.auth.NullCredentialInitializer)1 GcpOptions (org.apache.beam.sdk.extensions.gcp.options.GcpOptions)1 LatencyRecordingHttpRequestInitializer (org.apache.beam.sdk.extensions.gcp.util.LatencyRecordingHttpRequestInitializer)1 ImmutableList (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList)1