use of com.google.auth.Credentials 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());
}
use of com.google.auth.Credentials in project google-cloud-java by GoogleCloudPlatform.
the class GrpcTransportOptions method setUpChannelProvider.
/**
* Returns a channel provider from the given default provider.
*/
public static ChannelProvider setUpChannelProvider(InstantiatingChannelProvider.Builder providerBuilder, ServiceOptions<?, ?> serviceOptions) {
providerBuilder.setEndpoint(serviceOptions.getHost()).setClientLibHeader(ServiceOptions.getGoogApiClientLibName(), firstNonNull(serviceOptions.getLibraryVersion(), ""));
Credentials scopedCredentials = serviceOptions.getScopedCredentials();
if (scopedCredentials != null && scopedCredentials != NoCredentials.getInstance()) {
providerBuilder.setCredentialsProvider(FixedCredentialsProvider.create(scopedCredentials));
}
return providerBuilder.build();
}
use of com.google.auth.Credentials 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));
}
};
}
use of com.google.auth.Credentials in project google-cloud-java by GoogleCloudPlatform.
the class Subscriber method startPollingConnections.
private void startPollingConnections() throws IOException {
synchronized (pollingSubscriberConnections) {
Credentials credentials = credentialsProvider.getCredentials();
CallCredentials callCredentials = credentials == null ? null : MoreCallCredentials.from(credentials);
for (int i = 0; i < numChannels; i++) {
SubscriberFutureStub stub = SubscriberGrpc.newFutureStub(channels.get(i));
if (callCredentials != null) {
stub = stub.withCallCredentials(callCredentials);
}
pollingSubscriberConnections.add(new PollingSubscriberConnection(cachedSubscriptionNameString, receiver, ackExpirationPadding, maxAckExtensionPeriod, ackLatencyDistribution, stub, flowController, flowControlSettings.getMaxOutstandingElementCount(), executor, alarmsExecutor, clock));
}
startConnections(pollingSubscriberConnections, new Listener() {
@Override
public void failed(State from, Throwable failure) {
// If a connection failed is because of a fatal error, we should fail the
// whole subscriber.
stopAllPollingConnections();
try {
notifyFailed(failure);
} catch (IllegalStateException e) {
if (isRunning()) {
throw e;
}
// It could happen that we are shutting down while some channels fail.
}
}
});
}
}
use of com.google.auth.Credentials 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();
}
Aggregations